1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
use std::collections::HashMap;
use tera::{Tera, try_get_value};
use serde_json::value::{to_value, Value};

pub fn do_nothing_filter(value: &Value, _: &HashMap<String, Value>) -> tera::Result<Value> {
    let s = try_get_value!("do_nothing_filter", "value", String, value);
    Ok(to_value(&s).unwrap())
}

pub fn init_tera(path: &str) -> Tera {
    let tpl_path = format!("{}/**/*",&path);
    let mut tera = match Tera::new(&tpl_path) {
        Ok(t) => { 
            println!("Templates loaded from: {}",&tpl_path);
            log::info!("Templates loaded from: {}",&tpl_path);
            t
        },
        Err(e) => {
            println!("Tempates from {} parsing error(s): {}",&tpl_path, e);
            ::std::process::exit(1);
        }
    };
    tera.autoescape_on(vec![]);
    tera.register_filter("do_nothing", do_nothing_filter);
    tera
}