Search in sources :

Example 16 with Handlebars

use of com.github.jknack.handlebars.Handlebars in project ddf by codice.

the class RegistryReportBuilder method setup.

public void setup() {
    templateLoader = new ClassPathTemplateLoader();
    templateLoader.setPrefix("/templates");
    templateLoader.setSuffix(".hbt");
    handlebars = new Handlebars(templateLoader);
    handlebars.registerHelpers(new HandlebarsHelper());
    handlebars.registerHelpers(StringHelpers.class);
}
Also used : Handlebars(com.github.jknack.handlebars.Handlebars) ClassPathTemplateLoader(com.github.jknack.handlebars.io.ClassPathTemplateLoader) HandlebarsHelper(org.codice.ddf.registry.rest.endpoint.HandlebarsHelper)

Example 17 with Handlebars

use of com.github.jknack.handlebars.Handlebars in project Singularity by HubSpot.

the class SingularityExecutorModule method providesHandlebars.

@Provides
@Singleton
public Handlebars providesHandlebars() {
    // handlebars emits DEBUG logs before logger is properly configured
    SingularityRunnerBaseLogging.quietEagerLogging();
    final Handlebars handlebars = new Handlebars();
    handlebars.registerHelper(BashEscapedHelper.NAME, new BashEscapedHelper());
    handlebars.registerHelper(ShellQuoteHelper.NAME, new ShellQuoteHelper());
    handlebars.registerHelper(IfPresentHelper.NAME, new IfPresentHelper());
    handlebars.registerHelper(IfHasNewLinesOrBackticksHelper.NAME, new IfHasNewLinesOrBackticksHelper());
    handlebars.registerHelper(EscapeNewLinesAndQuotesHelper.NAME, new EscapeNewLinesAndQuotesHelper());
    return handlebars;
}
Also used : IfPresentHelper(com.hubspot.singularity.executor.handlebars.IfPresentHelper) Handlebars(com.github.jknack.handlebars.Handlebars) EscapeNewLinesAndQuotesHelper(com.hubspot.singularity.executor.handlebars.EscapeNewLinesAndQuotesHelper) ShellQuoteHelper(com.hubspot.singularity.executor.handlebars.ShellQuoteHelper) IfHasNewLinesOrBackticksHelper(com.hubspot.singularity.executor.handlebars.IfHasNewLinesOrBackticksHelper) BashEscapedHelper(com.hubspot.singularity.executor.handlebars.BashEscapedHelper) Singleton(com.google.inject.Singleton) Provides(com.google.inject.Provides)

Example 18 with Handlebars

use of com.github.jknack.handlebars.Handlebars 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)

Example 19 with Handlebars

use of com.github.jknack.handlebars.Handlebars in project ddf by codice.

the class LandingPage method compileTemplateWithProperties.

// package-private for unit testing
String compileTemplateWithProperties() {
    title = getTitle();
    version = branding.map(registry -> registry.getAttributeFromBranding(BrandingPlugin::getProductName)).orElse("");
    logoToUse = StringUtils.isNotEmpty(logo) ? logo : getProductImage();
    // FieldValueResolver so this class' fields can be accessed in the template.
    // MapValueResolver so we can access {{@index}} in the #each helper in the template.
    final Context context = Context.newBuilder(this).resolver(FieldValueResolver.INSTANCE, MapValueResolver.INSTANCE).build();
    // The template is "index.handlebars".
    final TemplateLoader templateLoader = new ClassPathTemplateLoader("/", ".handlebars");
    final Handlebars handlebars = new Handlebars(templateLoader);
    // extractDate(), extractAnnouncement(), expanded(), and in() are helper functions used in the
    // template.
    handlebars.registerHelpers(this);
    String landingPageHtml;
    try {
        final Template template = handlebars.compile(LANDING_PAGE_FILE);
        landingPageHtml = template.apply(context);
    } catch (IOException e) {
        LOGGER.info("Unable to compile Landing Page template.", e);
        landingPageHtml = "<p>We are experiencing some issues. Please contact an administrator.</p>";
    }
    return landingPageHtml;
}
Also used : Context(com.github.jknack.handlebars.Context) 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) IOException(java.io.IOException) Template(com.github.jknack.handlebars.Template)

Example 20 with Handlebars

use of com.github.jknack.handlebars.Handlebars in project hippo by NHS-digital-website.

the class SchemaHelper method initialiseHandlebars.

private Handlebars initialiseHandlebars(final MarkdownHelper markdownHelper, final String templatesClasspath) throws URISyntaxException {
    final TemplateLoader templateLoader = templatesClasspath == null ? new ClassPathTemplateLoader(TEMPLATES_CLASSPATH, TEMPLATE_EXTENSION) : new FileTemplateLoader(new File(templatesClasspath), TEMPLATE_EXTENSION);
    final ContextModelsStack.Factory contextStackFactory = new ContextModelsStack.Factory(new UniqueModelStackExtractor());
    return new Handlebars(templateLoader).parentScopeResolution(false).infiniteLoops(true).prettyPrint(true).registerHelper(MarkdownHelper.NAME, markdownHelper).registerHelper(IndentationHelper.NAME, new IndentationHelper(contextStackFactory)).registerHelper(IfNotNullHelper.NAME, IfNotNullHelper.INSTANCE).registerHelper(IfRequiredHelper.NAME, new IfRequiredHelper(contextStackFactory)).registerHelper(ConditionalHelpers.eq.name(), ConditionalHelpers.eq).registerHelper(ConditionalHelpers.or.name(), ConditionalHelpers.or).registerHelper(EnumHelper.NAME, EnumHelper.INSTANCE).registerHelper(TypeAnyHelper.NAME, TypeAnyHelper.INSTANCE).registerHelper(JacksonPrettyJsonHelper.NAME, JacksonPrettyJsonHelper.INSTANCE).registerHelper(TypeAnySanitisingHelper.NAME, TypeAnySanitisingHelper.INSTANCE).registerHelper(AssignHelper.NAME, AssignHelper.INSTANCE).registerHelper(VariableValueHelper.NAME, VariableValueHelper.INSTANCE).registerHelper(BorderHelper.NAME, new BorderHelper(contextStackFactory)).registerHelper(UuidHelper.NAME, UuidHelper.INSTANCE);
}
Also used : Handlebars(com.github.jknack.handlebars.Handlebars) ClassPathTemplateLoader(com.github.jknack.handlebars.io.ClassPathTemplateLoader) FileTemplateLoader(com.github.jknack.handlebars.io.FileTemplateLoader) TemplateLoader(com.github.jknack.handlebars.io.TemplateLoader) ClassPathTemplateLoader(com.github.jknack.handlebars.io.ClassPathTemplateLoader) FileTemplateLoader(com.github.jknack.handlebars.io.FileTemplateLoader) File(java.io.File)

Aggregations

Handlebars (com.github.jknack.handlebars.Handlebars)24 IOException (java.io.IOException)13 Template (com.github.jknack.handlebars.Template)10 ClassPathTemplateLoader (com.github.jknack.handlebars.io.ClassPathTemplateLoader)8 Context (com.github.jknack.handlebars.Context)6 FileTemplateLoader (com.github.jknack.handlebars.io.FileTemplateLoader)6 TemplateLoader (com.github.jknack.handlebars.io.TemplateLoader)3 Date (java.util.Date)3 UIContext (com.github.bordertech.wcomponents.UIContext)2 WComponent (com.github.bordertech.wcomponents.WComponent)2 SystemException (com.github.bordertech.wcomponents.util.SystemException)2 Provides (com.google.inject.Provides)2 Singleton (com.google.inject.Singleton)2 AsyncHttpServer (com.koushikdutta.async.http.server.AsyncHttpServer)2 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)2 Placemark (de.micromata.opengis.kml.v_2_2_0.Placemark)2 TimeSpan (de.micromata.opengis.kml.v_2_2_0.TimeSpan)2 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 DateFormat (java.text.DateFormat)2