summaryrefslogtreecommitdiff
path: root/src/works/mod.rs
blob: cfd302d19adc0410a797c7c341ec211946285d99 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
use anyhow::Result;
use serde::{Deserialize, Serialize};

pub mod stories;

pub trait Works: for<'a> Deserialize<'a> + Serialize {
    fn new_from_file(file: std::fs::File) -> Result<Self> {
        Ok(serde_json::from_reader(std::io::BufReader::new(file))?)
    }

    fn create_tera_context(&self) -> Result<tera::Context> {
        let mut context = tera::Context::new();
        context.insert("works", &self);
        Ok(context)
    }
}