From 6b5dc8c448299485d2b07fdb6eef4dd584f11bb6 Mon Sep 17 00:00:00 2001 From: yuma14 Date: Sun, 15 Oct 2023 00:06:23 +0900 Subject: [PATCH] add TemplateEngine --- src/template_engine.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/template_engine.rs diff --git a/src/template_engine.rs b/src/template_engine.rs new file mode 100644 index 0000000..0f36643 --- /dev/null +++ b/src/template_engine.rs @@ -0,0 +1,17 @@ +use handlebars::Handlebars; + +use crate::handlebars_helpers; + +/// TemplateEngine is a wrapper for Handlebars and processes templates and [`Value`](crate::Value)s. +pub struct TemplateEngine(Handlebars<'static>); + +impl TemplateEngine { + pub fn new() -> Self { + let mut handlebars = Handlebars::new(); + + handlebars.register_helper("md2html", Box::new(handlebars_helpers::md2html)); + handlebars.register_helper("resolve", Box::new(handlebars_helpers::resolve)); + + Self(handlebars) + } +}