1use std::io::{Error, ErrorKind};
2
3use handlebars::{Handlebars, no_escape};
4
5use crate::include_template_file;
6
7pub fn init_registry<'a>() -> Result<Handlebars<'a>, Error> {
8 let mut reg = Handlebars::new();
9
10 let theme = "blog";
11
12 #[allow(clippy::vec_init_then_push)]
14 for (n, s) in match theme {
15 "documentation" => include_template_file!(
16 "documentation",
17 "_article",
18 "_sidebar",
19 "layout"
20 ),
21 _ => include_template_file!(
22 "blog", "_article", "_footer", "_header", "_sidebar", "headline",
23 "layout"
24 ),
25 } {
26 reg.register_template_string(n, s).as_ref().map_err(|e| {
27 eprintln!("err: {}", e);
28 Error::new(ErrorKind::InvalidInput, "no such template file")
29 })?;
30 }
31 Ok(reg)
32}
33
34pub fn add_escape_fn(reg: &mut Handlebars) {
35 reg.register_escape_fn(no_escape)
36}
37
38pub fn del_escape_fn(reg: &mut Handlebars) {
39 reg.unregister_escape_fn()
40}