mod square_brackets;
#[cfg(test)]
mod tests;
mod call_stack;
mod for_loop;
mod macros;
mod processor;
mod stack_frame;
use serde_json::value::Value;
use self::processor::Processor;
use errors::Result;
use template::Template;
use tera::Tera;
#[derive(Debug)]
pub struct Renderer<'a> {
template: &'a Template,
tera: &'a Tera,
context: Value,
should_escape: bool,
}
impl<'a> Renderer<'a> {
#[inline]
pub fn new(template: &'a Template, tera: &'a Tera, context: Value) -> Renderer<'a> {
let should_escape = tera.autoescape_suffixes.iter().any(|ext| {
if let Some(ref p) = template.path {
return p.ends_with(ext);
}
template.name.ends_with(ext)
});
Renderer { template, tera, context, should_escape }
}
pub fn render(&self) -> Result<String> {
let output;
{
let mut processor =
Processor::new(self.template, self.tera, &self.context, self.should_escape);
output = processor.render()?;
}
Ok(output)
}
}