reify/processor/
handlebars.rs

1use handlebars::{Handlebars};
2use crate::processor::context::ReifyContext;
3use crate::processor::ReifyProcessor;
4
5pub struct HandlebarsProcessor<'a, Ctx> {
6    ctx: &'a Ctx,
7    registry: Handlebars<'a>
8}
9
10impl <'a, Ctx> HandlebarsProcessor<'a, Ctx> {
11    pub fn new(ctx: &'a Ctx) -> anyhow::Result<Self> {
12        Ok(Self {
13            ctx,
14            registry: Handlebars::new()
15        })
16    }
17}
18
19impl <'a, Ctx: ReifyContext> ReifyProcessor for HandlebarsProcessor<'a, Ctx> {
20    fn render(&self, source: &str) -> anyhow::Result<String> {
21        let result = self.registry.render_template(source, self.ctx.read_ctx())?;
22        Ok(result)
23    }
24}