{
+ private static final HighConcurrencyTemplateCache HIGH_CONCURRENCY_TEMPLATE_CACHE =
+ new HighConcurrencyTemplateCache();
+
+ /**
+ * Use this to obtain an instance of Handlebars instead of creating one separately.
+ *
+ * Specify a TemplateLoader if the default ClassPathTemplateLoader is not required.
+ *
+ *
Using this ensures the instance returned has a consistent setup with all helpers registered.
+ *
+ * @param loader The TemplateLoader to use. If null, handlebars defaults to
+ * ClassPathTemplateLoader.
+ * @return A HandleBars instance with appropriate settings and registered helpers
+ */
+ static Handlebars getHandlebarsInstance(@Nullable TemplateLoader loader) {
+ Handlebars handlebars =
+ new Handlebars()
+ .with(HIGH_CONCURRENCY_TEMPLATE_CACHE)
+ .preEvaluatePartialBlocks(false)
+ .parentScopeResolution(false)
+ .setCharset(StandardCharsets.UTF_8);
+ if (loader != null) {
+ handlebars.with(loader);
+ }
+ return HandlebarsHelpers.registerHelpers(handlebars);
+ }
+
public static boolean isAssetFileHandlebars(String filename) {
if (filename == null) {
return false;
@@ -63,7 +81,7 @@ public static boolean isAssetFileHandlebars(String filename) {
private final Template template;
/** Logging class instance. */
- private static final Logger log = LogManager.getLogger(Token.class);
+ private static final Logger log = LogManager.getLogger(HandlebarsUtil.class);
/** Handlebars partial template source that uses Add-On files */
private static record LibraryTemplateSource(@Nonnull Library library, @Nonnull String filename)
@@ -124,29 +142,6 @@ public LibraryTemplateSource sourceAt(@Nonnull final String location) {
}
}
- private static enum MapToolHelpers implements Helper