use ramhorns::{Content, Ramhorns}; /// Structure used in the config variable of the app #[derive(Clone, Debug)] pub struct Template { /// Root directory where templates are stored pub directory: String, /// App name pub app_name: String, /// URL of app pub url: String, /// Name of user pub name: Option, } /// Structure used by /routes/*.rs #[derive(Debug, Default)] pub struct Infos { /// Title pub page_title: Option, /// Description pub page_desc: Option, /// Keywords pub page_kw: Option, } #[derive(Content, Debug, Default)] pub struct NavBar { pub index: bool, pub blog: bool, pub portfolio: bool, pub contact: bool, pub contrib: bool, pub cours: bool, } /// Final structure given to template #[derive(Content, Debug)] struct Data { /// App name app_name: String, /// App URL url: String, /// Title of the page page_title: Option, /// Description of the page page_desc: Option, /// Keywords of the the page page_kw: Option, /// Author's name page_author: Option, /// Data needed to render the page data: T, } impl Template { pub fn render(&self, template: &str, data: C, info: Infos) -> String { let mut templates: Ramhorns = Ramhorns::lazy(&self.directory).unwrap(); let tplt = templates.from_file(template).unwrap(); tplt.render(&Data { app_name: self.app_name.to_owned(), url: self.url.to_owned(), page_title: info.page_title, page_desc: info.page_desc, page_kw: info.page_kw, page_author: self.name.clone(), data, }) } }