diff options
| author | WriterV2 <primary-v2@protonmail.com> | 2024-08-04 10:07:08 +0200 |
|---|---|---|
| committer | WriterV2 <primary-v2@protonmail.com> | 2024-08-04 10:07:08 +0200 |
| commit | f982a5621bfed646ce71fcf7aeeca71ef4ae55c1 (patch) | |
| tree | 4811e7dbd105b0a17da8725d5f7a9a5536eb5fbc /src/works/mod.rs | |
| parent | 19c2c05c6f5220f4feedad99a38e0fb4dc57b957 (diff) | |
Purge
Diffstat (limited to 'src/works/mod.rs')
| -rw-r--r-- | src/works/mod.rs | 63 |
1 files changed, 0 insertions, 63 deletions
diff --git a/src/works/mod.rs b/src/works/mod.rs deleted file mode 100644 index 8cda299..0000000 --- a/src/works/mod.rs +++ /dev/null @@ -1,63 +0,0 @@ -use std::fs::{write, File}; -use std::io::BufReader; -use std::path::PathBuf; - -use anyhow::{Context, Ok, Result}; -use serde::{Deserialize, Serialize}; - -pub mod stories; - -// functionality for a group of work, e.g. stories or games -pub trait Works: for<'a> Deserialize<'a> + Serialize { - // create works from the corresponding JSON file, - // e.g. stories from stories.json - fn new_from_file(workname: &str) -> Result<Self> { - let work = serde_json::from_reader(BufReader::new( - &File::open(PathBuf::from(format!("{}.json", workname))) - .with_context(|| format!("Failed to open {}.json", workname))?, - )) - .with_context(|| format!("Failed to create works from {}.json", workname))?; - Ok(work) - } - - // crate tera context from the group of work - // tera context can be accessed in HTML tera templating - fn create_tera_context(&self) -> tera::Context { - let mut context = tera::Context::new(); - context.insert("works", &self); - context - } - - // render page for every work - fn render_single_pages(self, tera_instance: &tera::Tera, template_name: &str) -> Result<Self>; - - // render corresponding overview HTML template - // with its tera context - fn render_overview_page( - self, - tera_instance: &tera::Tera, - filename_without_extension: &str, - ) -> Result<Self> { - write( - format!("docs/{}.html", filename_without_extension).as_str(), - tera_instance - .render( - format!("{}.html", filename_without_extension).as_str(), - &self.create_tera_context(), - ) - .with_context(|| { - format!( - "Failed rendering overview page for {}", - filename_without_extension - ) - })?, - ) - .with_context(|| { - format!( - "Failed to write overview page for {}", - filename_without_extension - ) - })?; - Ok(self) - } -} |
