protected View view(final Template mustache) { return (model, out) -> { PrintWriter writer = new PrintWriter(out); mustache.execute(model, writer); writer.flush(); }; } }
/** * Decomposes the compound key {@code name} into components and resolves the value they * reference. */ protected Object getCompoundValue (Context ctx, String name, int line, boolean missingIsNull) { String[] comps = name.split("\\."); // we want to allow the first component of a compound key to be located in a parent // context, but once we're selecting sub-components, they must only be resolved in the // object that represents that component Object data = getValue(ctx, comps[0], line, missingIsNull); for (int ii = 1; ii < comps.length; ii++) { if (data == NO_FETCHER_FOUND) { if (!missingIsNull) throw new MustacheException.Context( "Missing context for compound variable '" + name + "' on line " + line + ". '" + comps[ii - 1] + "' was not found.", name, line); return null; } else if (data == null) { return null; } // once we step into a composite key, we drop the ability to query our parent contexts; // that would be weird and confusing data = getValueIn(data, comps[ii], line); } return checkForMissing(name, line, missingIsNull, data); }
Object value = getValueIn(ctx.data, name, line); return checkForMissing(name, line, missingIsNull, value); Object value = getValueIn(pctx.data, name, line); if (value != NO_FETCHER_FOUND) return value; return getCompoundValue(ctx, name, line, missingIsNull); } else { return checkForMissing(name, line, missingIsNull, NO_FETCHER_FOUND);
/** * Compiles the supplied template into a repeatedly executable intermediate form. */ protected static Template compile (Reader source, Compiler compiler) { Accumulator accum = new Parser(compiler).parse(source); return new Template(trim(accum.finish(), true), compiler); }
Object value = getValueIn(ctx.data, name, line); return checkForMissing(name, line, missingIsNull, value); Object value = getValueIn(pctx.data, name, line); if (value != NO_FETCHER_FOUND) return value; return getCompoundValue(ctx, name, line, missingIsNull); } else { return checkForMissing(name, line, missingIsNull, NO_FETCHER_FOUND);
/** * Compiles the supplied template into a repeatedly executable intermediate form. */ protected static Template compile (Reader source, Compiler compiler) { Accumulator accum = new Parser(compiler).parse(source); return new Template(trim(accum.finish(), true), compiler); }
public String process(String name, Map<String, ?> model) { try { Template template = getTemplate(name); return template.execute(model); } catch (Exception ex) { log.error("Cannot render: " + name, ex); throw new IllegalStateException("Cannot render template", ex); } }
/** * Decomposes the compound key {@code name} into components and resolves the value they * reference. */ protected Object getCompoundValue (Context ctx, String name, int line, boolean missingIsNull) { String[] comps = name.split("\\."); // we want to allow the first component of a compound key to be located in a parent // context, but once we're selecting sub-components, they must only be resolved in the // object that represents that component Object data = getValue(ctx, comps[0].intern(), line, missingIsNull); for (int ii = 1; ii < comps.length; ii++) { if (data == NO_FETCHER_FOUND) { if (!missingIsNull) throw new MustacheException.Context( "Missing context for compound variable '" + name + "' on line " + line + ". '" + comps[ii - 1] + "' was not found.", name, line); return null; } else if (data == null) { return null; } // once we step into a composite key, we drop the ability to query our parent contexts; // that would be weird and confusing data = getValueIn(data, comps[ii].intern(), line); } return checkForMissing(name, line, missingIsNull, data); }
@Override public String executeTemplateText(final String templateText, final Map<String, Object> data) { final Template template = Mustache.compiler().nullValue("").compile(templateText); return template.execute(data); } }
@Override protected void renderMergedTemplateModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception { Template template = createTemplate( getApplicationContext().getResource(this.getUrl())); if (template != null) { template.execute(model, response.getWriter()); } }
private void printReport() { Template tmpl= Mustache.compiler().compile(getString(R.string.report_body)); WebView print=prepPrintWebView(getString(R.string.tps_report)); print.loadData(tmpl.execute(new TpsReportContext(prose.getText() .toString())), "text/html; charset=UTF-8", null); }
@Override protected Mono<Void> renderInternal(Map<String, Object> model, MediaType contentType, ServerWebExchange exchange) { Resource resource = resolveResource(); if (resource == null) { return Mono.error(new IllegalStateException( "Could not find Mustache template with URL [" + getUrl() + "]")); } DataBuffer dataBuffer = exchange.getResponse().bufferFactory().allocateBuffer(); try (Reader reader = getReader(resource)) { Template template = this.compiler.compile(reader); Charset charset = getCharset(contentType).orElse(getDefaultCharset()); try (Writer writer = new OutputStreamWriter(dataBuffer.asOutputStream(), charset)) { template.execute(model, writer); writer.flush(); } } catch (Exception ex) { DataBufferUtils.release(dataBuffer); return Mono.error(ex); } return exchange.getResponse().writeWith(Flux.just(dataBuffer)); }
/** * Executes this template with the given context, returning the results as a string. * @throws MustacheException if an error occurs while executing or writing the template. */ public String execute (Object context) throws MustacheException { StringWriter out = new StringWriter(); execute(context, out); return out.toString(); }
public static String execute(Template mustache, Object scope) { return mustache.execute(scope); }
public void execute(Object context, Object parentContext, Writer out) throws MustacheTemplateException { template.execute(context, parentContext, out); } }
public void execute(Object context, Object parentContext, Writer out) throws MustacheTemplateException { template.execute(context, parentContext, out); } }
public static String execute(Template mustache, Object scope) { return mustache.execute(scope); }
public void execute(Object context, Writer out) throws MustacheTemplateException { template.execute(context, out); }
public void execute(Object context, Writer out) throws MustacheTemplateException { template.execute(context, out); }
/** * Executes this template with the given context, returning the results as a string. * @throws MustacheException if an error occurs while executing or writing the template. */ public String execute (Object context) throws MustacheException { StringWriter out = new StringWriter(); execute(context, out); return out.toString(); }