static STATE: RwLock<Option<State>> = const_rwlock(None);
struct State {
- tera: tera::Tera,
+ tera: tera_standalone::Tera,
}
#[throws(StartupError)]
let config = config();
let nwtemplate_dir = &config.nwtemplate_dir;
let glob = format!("{}/*.tera", nwtemplate_dir);
- let tera = tera::Tera::new(&glob)
+ let tera = tera_standalone::Tera::new(&glob)
.map_err(|e| anyhow!("{}", e))
.context("load tamplates")
.with_context(|| nwtemplate_dir.to_string())?;
}
#[throws(anyhow::Error)]
-pub fn render<D: Serialize>(template_name: &str, data: &D) -> String {
- fn get_tera() -> MappedRwLockReadGuard<'static, tera::Tera> {
+pub fn render<D>(template_name: &str, data: &D) -> String
+where D: Serialize + Debug
+{
+ fn get_tera() -> MappedRwLockReadGuard<'static, tera_standalone::Tera> {
let g = STATE.read();
RwLockReadGuard::map(g, |g| &g.as_ref().unwrap().tera)
}
- get_tera().render(template_name, data).map_err(|e| {
+ let context = tera_standalone::Context::from_serialize(data)
+ .with_context(
+ || format!("failed make context from serializable {:?}", data)
+ )
+ .map_err(IE::from)?;
+ get_tera().render(template_name, &context).map_err(|e| {
error!("template render error: {:?}", &e);
anyhow!(e.to_string())
})?