protected View view(final Template mustache) { return (model, out) -> { PrintWriter writer = new PrintWriter(out); mustache.execute(model, writer); writer.flush(); }; } }
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); } }
@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(); }
/** * 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(); }
protected void generateJavaClass(String className, Template mustache, ImmutableMap<String, ? extends Object> ctx, Set<Element> originatingElements) throws IOException { JavaFileObject fileObject = processingEnv.getFiler().createSourceFile(className, Iterables.toArray(originatingElements, Element.class)); try (Writer writer = fileObject.openWriter()) { mustache.execute(ctx, writer); } }
public static void execute(Template mustache, Object scope, Path path) throws IOException { File file = path.toFile(); if (!file.getParentFile().exists()) { if (!file.getParentFile().mkdirs()) { throw new IOException(String.format("can't generate file to `%s`: can't create directory `%s`", file.getAbsolutePath(), file.getParentFile().getAbsolutePath())); } } try (FileWriter w = new FileWriter(file)) { mustache.execute(scope, w); } } }
@Override public byte[] process(byte[] template, String path, Object context) { Template t = template(new ByteArrayInputStream(template), path); return t.execute(context).getBytes(UTF8); }
@Override public String execute(HasContainer hasContainer) { Map<String, Object> stringObjectMap = toMap(hasContainer); return template.execute(stringObjectMap); }
private BaseRequest executeGet(String baseUrl, Object urlMap, Object bodyMap) { GetRequest getRequest = Unirest.get(baseUrl + urlTemplate.execute(urlMap)); Map<String, Object> map = (Map<String, Object>) bodyMap; if (field == null || !map.containsKey("predicates")) return getRequest; return getRequest .queryString(field, bodyTemplate.execute(bodyMap).replace("\n", "").replace("\r", "").replace("\t", "")); } }
@HtmlSafe @com.atlassian.velocity.htmlsafe.HtmlSafe public String render() { return template.execute(singletonMap("pluginModules", modules)); } }
@HtmlSafe @com.atlassian.velocity.htmlsafe.HtmlSafe public String render() { return template.execute(singletonMap("applinks", transform(newArrayList(applicationLinkService.getApplicationLinks()), new Function<ApplicationLink, Map<String, String>>() { public Map<String, String> apply(ApplicationLink from) { return ImmutableMap.of("id", from.getId().get(), "name", from.getName(), "type", i18nResolver.getText(from.getType().getI18nKey())); } }))); }
/** * Merges the specified template using the supplied mapping of string keys to objects. * * @return a string containing the merged text. */ protected String mergeTemplate (String template, Map<String, Object> data) throws IOException { Reader reader = new InputStreamReader(getClass().getClassLoader().getResourceAsStream(template), UTF_8); return convertEols(Mustache.compiler().escapeHTML(false).compile(reader).execute(data)); }
@Override public String getMessage(String key, MessageParams params, Locale locale) { return getTemplate(key, locale).execute(params.toMap()); }
private String doRender( final Resource view, final Object model ) { final String str = IOHelper.readString( view.getBytes() ); final Template template = this.compiler.compile( str ); return template.execute( model ); }
@Override public String executeTemplateText(final String templateText, final Map<String, Object> data) { final Template template = Mustache.compiler().nullValue("").compile(templateText); return template.execute(data); } }
@HtmlSafe @com.atlassian.velocity.htmlsafe.HtmlSafe public String render(UserExtension plugin) { plugin.getParams().put("screenshotUrl", contextPath + "/rest/speakeasy/1/plugins/screenshot/" + plugin.getKey() + ".png"); return rowTemplate.execute(plugin); } }