static Handlebars create(final List<TemplateLoader> templateLoaders, final I18nResolver i18NResolver, final I18nIdentifierFactory i18nIdentifierFactory) { if (templateLoaders.isEmpty()) { throw new SunriseConfigurationException("Could not initialize Handlebars due to missing template loaders configuration", CONFIG_TEMPLATE_LOADERS); } logger.info("Provide Handlebars: template loaders [{}]]", templateLoaders.stream().map(TemplateLoader::getPrefix).collect(joining(", "))); final TemplateLoader[] loaders = templateLoaders.toArray(new TemplateLoader[templateLoaders.size()]); final Handlebars handlebars = new Handlebars() .with(loaders) .with(new HighConcurrencyTemplateCache()) .infiniteLoops(true); handlebars.registerHelper("i18n", new HandlebarsI18nHelper(i18NResolver, i18nIdentifierFactory)); handlebars.registerHelper("cms", new HandlebarsCmsHelper()); handlebars.registerHelper("json", new HandlebarsJsonHelper<>()); return handlebars; }
protected Handlebars createHandlebars(UpdatableInjectionContext injectionContext, boolean hotload) { Logger.info("Handlebars template hotloading is %s", hotload ? "enabled" : "disabled"); TemplateCache templateCache = hotload ? NullTemplateCache.INSTANCE : new HighConcurrencyTemplateCache(); return new Handlebars(new CompositeTemplateLoader(injectionContext)).with(templateCache); }
public HandlebarsTransformer() { config = ConfigUtil.loadYaml("handlebars_config.yml", HandlebarsConfig.class); setPriority(config.priority); addSupportedTypes(WILDCARD_TYPE, TEXT_HTML_TYPE, APPLICATION_FORM_URLENCODED_TYPE, APPLICATION_XHTML_XML_TYPE); if (DependencyProvider.global().get(HANDLE_BARS) == null) { DependencyProvider.global().put(HANDLE_BARS, new HashMap<String, Object>()); } loader = new HiggsTemplateLoader(config); handlebars = new Handlebars(loader); loadHelpers(); if (config.enable_humanize_helper) { HumanizeHelper.register(handlebars); } if (config.enable_jackson_helper) { handlebars.registerHelper("json", Jackson2Helper.INSTANCE); } if (config.enable_markdown_helper) { handlebars.registerHelper("md", MarkdownHelper.INSTANCE); } if (config.cache_templates) { handlebars.with(new HighConcurrencyTemplateCache()); } }