summaryrefslogtreecommitdiff
path: root/src/works/mod.rs
diff options
context:
space:
mode:
authorWriterV2 <primary-v2@protonmail.com>2022-09-03 18:45:45 +0200
committerWriterV2 <primary-v2@protonmail.com>2022-09-03 18:45:45 +0200
commit18853a2baf20017e926e4bb465e3c02bb5a7af97 (patch)
treeee9051cd54073878a407c93005405c116db57771 /src/works/mod.rs
parent746c348f739a8d5f26d4cd76ed72646a338271c4 (diff)
Universalize method to create context from works and pass entire works object
Diffstat (limited to 'src/works/mod.rs')
-rw-r--r--src/works/mod.rs10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/works/mod.rs b/src/works/mod.rs
index 3dfd4a2..f062565 100644
--- a/src/works/mod.rs
+++ b/src/works/mod.rs
@@ -1,8 +1,8 @@
-use serde::Deserialize;
+use serde::{Deserialize, Serialize};
pub mod stories;
-pub trait Works: for<'a> Deserialize<'a> {
+pub trait Works: for<'a> Deserialize<'a> + Serialize {
fn new_from_file(file: std::fs::File) -> Self {
match serde_json::from_reader(std::io::BufReader::new(file)) {
Ok(work) => work,
@@ -10,5 +10,9 @@ pub trait Works: for<'a> Deserialize<'a> {
}
}
- fn create_tera_context(&self) -> tera::Context;
+ fn create_tera_context(&self) -> tera::Context {
+ let mut context = tera::Context::new();
+ context.insert("works", &self);
+ context
+ }
}