use std::sync::LazyLock;
use minijinja::{Environment, Template};
use crate::db::event::signed_docs::{
FILTERED_SELECT_SIGNED_DOCS_TEMPLATE, SELECT_SIGNED_DOCS_TEMPLATE,
};
pub(crate) struct JinjaTemplateSource {
pub(crate) name: &'static str,
pub(crate) source: &'static str,
}
#[allow(clippy::unwrap_used)]
static JINJA_ENV: LazyLock<Environment> = LazyLock::new(|| {
let mut env = minijinja::Environment::new();
env.add_template(
SELECT_SIGNED_DOCS_TEMPLATE.name,
SELECT_SIGNED_DOCS_TEMPLATE.source,
)
.unwrap();
env.add_template(
FILTERED_SELECT_SIGNED_DOCS_TEMPLATE.name,
FILTERED_SELECT_SIGNED_DOCS_TEMPLATE.source,
)
.unwrap();
env
});
pub(crate) fn get_template(temp: &JinjaTemplateSource) -> anyhow::Result<Template<'static, '_>> {
let template = JINJA_ENV.get_template(temp.name)?;
Ok(template)
}