Skip to content

Commit

Permalink
more templating
Browse files Browse the repository at this point in the history
Signed-off-by: simonsan <[email protected]>
  • Loading branch information
simonsan committed Mar 23, 2024
1 parent e7e8b4a commit 037ab64
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 6 deletions.
14 changes: 10 additions & 4 deletions crates/core/src/template.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use lazy_static::lazy_static;
use tera::Tera;
use pace_time::duration::PaceDuration;
use tera::{Function, Tera};

use crate::prelude::{ReflectionSummary, SummaryActivityGroup};

Expand All @@ -13,7 +14,6 @@ lazy_static! {
}
};
tera.autoescape_on(vec![".html", ".sql"]);
// tera.register_filter("do_nothing", do_nothing_filter);
tera
};
}
Expand All @@ -35,8 +35,14 @@ impl From<ReflectionSummary> for PaceReflectionTemplate {
context.insert("time_range_start", &value.time_range().start());
context.insert("time_range_end", &value.time_range().end());

context.insert("total_time_spent", &value.total_time_spent());
context.insert("total_break_duration", &value.total_break_duration());
context.insert(
"total_time_spent",
&value.total_time_spent().human_readable(),
);
context.insert(
"total_break_duration",
&value.total_break_duration().human_readable(),
);

// key must be a string, because of the way tera works with nested objects
// we need to convert the key to a string
Expand Down
4 changes: 2 additions & 2 deletions templates/reflections/basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ <h2>Time Range</h2>
<p>End: <span id="end">{{ time_range_end }}</span></p>

<h2>Total Time Spent</h2>
<p><span id="total_time">{{ total_time_spent }}</span> seconds</p>
<p><span id="total_time">{{ total_time_spent }}</span></p>

<h2>Total Break Duration</h2>
<p><span id="total_time_break">{{ total_break_duration }}</span> seconds</p>
<p><span id="total_time_break">{{ total_break_duration }}</span></p>

<h2>Summary Groups by Category</h2>

Expand Down
32 changes: 32 additions & 0 deletions templates/reflections/basic.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Activity Reflection

## Time Range

Start: **{{time_range_start}}**

End: **{{time_range_end}}**

## Overview

Total Time Spent: **{{total_time_spent}}**

Total Break Time: **{{total_break_duration}}**

## Summary Groups By Category

{% for key, value in summary_groups_by_category %}

### {{key}}

Duration: **{{value.total_duration}}s**

Break Duration (Count): {{value.total_break_duration}}s ({{value.total_break_count}})

{% for key2, value2 in value.activity_groups_by_description %}

#### {{key2}}

{{value2.description}}

{% endfor %}
{% endfor %}

0 comments on commit 037ab64

Please sign in to comment.