use std::path::Path;
pub use tera::Context;
use crate::{Error, Result};
pub fn render_str(template: &str, context: &Context) -> Result<String> {
tera::Tera::one_off(template, context, false).map_err(|e| Error::Template(e.to_string()))
}
pub fn render_file(path: &Path, context: &Context) -> Result<String> {
let template = std::fs::read_to_string(path)?;
render_str(&template, context)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn renders_and_passes_html_through_unescaped() {
let mut ctx = Context::new();
ctx.insert("title", "BMF");
ctx.insert("importmap", "<script type=\"importmap\">{}</script>");
let html = render_str("<title>{{ title }}</title>{{ importmap | safe }}", &ctx).unwrap();
assert!(html.contains("<title>BMF</title>"));
assert!(html.contains("<script type=\"importmap\">"));
}
}