public Builder withCaching() { log.debug("Using caching handlebars"); handlebars.with(new ConcurrentMapTemplateCache()); return this; }
private String applyTemplateAsString(Dag dag, Dag.Node node, String templateAsString) throws IOException { // strange cache where you need to read the content ('source') before querying ?! // I guess caching means 'template generation caching' final TemplateSource source = new StringTemplateSource("jobNameTemplate", templateAsString); final Template template = this.cache.get(source, this.parser); final Writer writer = new StringWriter(); template.apply(DagAndNode.get(dag, node), writer); writer.flush(); return writer.toString(); } }
private HB() { this.cache = new ConcurrentMapTemplateCache(); this.handlebars = new Handlebars(); this.parser = handlebars.getParserFactory().create(handlebars, "{{", "}}"); } private String applyTemplateAsString(Dag dag, Dag.Node node, String templateAsString) throws IOException {
private static Handlebars handlebars(Env env, Resources resources, CompilerFacade compilers, MarkdownCompiler markdownCompiler) { return new Handlebars() .startDelimiter("[[") .endDelimiter("]]") .registerHelpers(new EachReverseHelperSource()) .registerHelpers(new EachValueHelperSource()) .registerHelpers(new GoogleAnalyticsHelper()) .registerHelpers(new LiveReloadHelper(env.prodMode())) .registerHelpers(new AssetsHelperSource(env.prodMode(), resources, compilers)) .registerHelpers(new WebjarHelperSource(env.prodMode())) .registerHelpers(StringHelpers.class) .infiniteLoops(true) .with(new ConcurrentMapTemplateCache()) .with(new AbstractTemplateLoader() { @Override public TemplateSource sourceAt(String location) throws IOException { Path include = resources.findExistingPath("_includes/" + location); if (include == null) { throw new IOException("Template not found " + location); } String body = resources.sourceFile(include).getSource(); if (MarkdownCompiler.supports(include)) { body = markdownCompiler.compile(body); } return new StringTemplateSource(location, body); } }); }