Search in sources :

Example 1 with EscapingStrategy

use of com.github.jknack.handlebars.EscapingStrategy in project wcomponents by BorderTech.

the class HandlebarsRendererImpl method getHandlebarsEngine.

/**
 * @param options the engine options
 * @return the handlebars engine
 */
protected Handlebars getHandlebarsEngine(final Map<String, Object> options) {
    // Setup handlebars
    TemplateLoader loader = new ClassPathTemplateLoader();
    // Clear the suffix so the file name does not default the file type to ".hbs"
    loader.setSuffix("");
    Handlebars handlebars = new Handlebars(loader);
    // Pretty Print
    Object value = options.get(PRETTY_PRINT);
    if (value != null) {
        handlebars.setPrettyPrint("true".equalsIgnoreCase(value.toString()));
    }
    // Escaping Strategy
    value = options.get(ESCAPING_STRATEGY);
    if (value instanceof EscapingStrategy) {
        handlebars.with((EscapingStrategy) value);
    }
    value = options.get(THEME_I18N);
    if (value == null || "true".equalsIgnoreCase(value.toString())) {
        String resourceBundleBasename = ConfigurationProperties.getI18nThemeResourceBundleBaseName();
        // Theme i18n helper uses "t" not "i18n".
        handlebars.registerHelper("t", I18nHelper.i18n);
        I18nHelper.i18n.setDefaultLocale(I18nUtilities.getEffectiveLocale());
        I18nHelper.i18n.setDefaultBundle(resourceBundleBasename);
    }
    // Use markdown
    // Disabled temporarily for issues # 565
    /*value = options.get(MARKDOWN);
		if (value != null && "true".equalsIgnoreCase(value.toString())) {
			handlebars.registerHelper("md", new MarkdownHelper());
		}*/
    // Caching
    value = options.get(USE_CACHE);
    boolean cache = (isCaching() && value == null) || (value != null && "true".equalsIgnoreCase(value.toString()));
    if (cache) {
        handlebars.with(CACHE);
    }
    return handlebars;
}
Also used : EscapingStrategy(com.github.jknack.handlebars.EscapingStrategy) Handlebars(com.github.jknack.handlebars.Handlebars) ClassPathTemplateLoader(com.github.jknack.handlebars.io.ClassPathTemplateLoader) TemplateLoader(com.github.jknack.handlebars.io.TemplateLoader) ClassPathTemplateLoader(com.github.jknack.handlebars.io.ClassPathTemplateLoader)

Aggregations

EscapingStrategy (com.github.jknack.handlebars.EscapingStrategy)1 Handlebars (com.github.jknack.handlebars.Handlebars)1 ClassPathTemplateLoader (com.github.jknack.handlebars.io.ClassPathTemplateLoader)1 TemplateLoader (com.github.jknack.handlebars.io.TemplateLoader)1