1414import java .nio .file .Files ;
1515import java .nio .file .Path ;
1616import java .nio .file .Paths ;
17+ import java .util .Deque ;
18+ import java .util .LinkedList ;
1719import java .util .List ;
1820import java .util .Optional ;
1921
2022import com .github .jknack .handlebars .Handlebars ;
23+ import com .github .jknack .handlebars .ValueResolver ;
2124import com .github .jknack .handlebars .cache .HighConcurrencyTemplateCache ;
2225import com .github .jknack .handlebars .cache .NullTemplateCache ;
2326import com .github .jknack .handlebars .cache .TemplateCache ;
@@ -199,6 +202,9 @@ protected URL getResource(String location) {
199202
200203 private Path templatesPath ;
201204
205+ private final Deque <ValueResolver > resolvers =
206+ new LinkedList <>(ValueResolver .defaultValueResolvers ());
207+
202208 /**
203209 * Creates a new handlebars module.
204210 *
@@ -233,6 +239,17 @@ public HandlebarsModule() {
233239 this (TemplateEngine .PATH );
234240 }
235241
242+ /**
243+ * Add custom value resolver.
244+ *
245+ * @param resolver Value resolver.
246+ * @return This module.
247+ */
248+ public HandlebarsModule with (@ NonNull ValueResolver resolver ) {
249+ resolvers .addFirst (resolver );
250+ return this ;
251+ }
252+
236253 @ Override
237254 public void install (@ NonNull Jooby application ) throws Exception {
238255 if (handlebars == null ) {
@@ -242,7 +259,8 @@ public void install(@NonNull Jooby application) throws Exception {
242259 .setTemplatesPath (templatesPath )
243260 .build (application .getEnvironment ());
244261 }
245- application .encoder (new HandlebarsTemplateEngine (handlebars , EXT ));
262+ application .encoder (
263+ new HandlebarsTemplateEngine (handlebars , resolvers .toArray (new ValueResolver [0 ]), EXT ));
246264
247265 ServiceRegistry services = application .getServices ();
248266 services .put (Handlebars .class , handlebars );
0 commit comments