protected Template loadTemplate(String name) { try { Reader template; template = this.mustache.loader.getTemplate(name); return this.mustache.compile(template); } catch (Exception ex) { throw new IllegalStateException("Cannot load template " + name, ex); } }
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)); }
public static Template compile(String name, CharSource charSource) { try (Reader reader = charSource.openBufferedStream()) { return createCompiler().compile(reader); } catch (IOException e) { throw new RuntimeException(e); } }
@VisibleForTesting public String executeTemplateText(final String templateText, final Map<String, Object> data) { final Template template = Mustache.compiler().compile(templateText); return template.execute(data); }
public MustacheTemplate getTemplate(String templateURL) throws MustacheTemplateException { try { final Reader templateReader = templateLoader.getTemplate(templateURL); return new JMustacheTemplate(compiler.compile(templateReader)); } catch (Exception e) { throw new MustacheTemplateException(e); } }
/** * 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)); }
public MustacheTemplate getTemplate(String templateURL) throws MustacheTemplateException { try { final Reader templateReader = templateLoader.getTemplate(templateURL); return new JMustacheTemplate(compiler.compile(templateReader)); } catch (Exception e) { throw new MustacheTemplateException(e); } }
/** Compiles the supplied template into a repeatedly executable intermediate form. */ public Template compile (String template) { return compile(new StringReader(template)); }
private static Template compile(Plugin plugin, String path) { InputStream in = null; try { in = plugin.getResourceAsStream(path); return Mustache.compiler().standardsMode(true).compile(new InputStreamReader(in)); } finally { IOUtils.closeQuietly(in); } }
/** * Compile template. * * @return * @throws IOException Signals that an I/O exception has occurred. */ protected static Template compileTemplate(Path templateFilepath) throws IOException { Compiler compiler = Mustache.compiler(); String templateHtml = new String(Files.readAllBytes(templateFilepath), StandardCharsets.UTF_8); return compiler.compile(templateHtml); }
public static Template compile(String name, CharSource charSource) { try (Reader reader = charSource.openBufferedStream()) { return createCompiler().compile(reader); } catch (IOException e) { throw new RuntimeException(e); } }
protected Path resolvePath(Path path, String relative, Object scope) { return path.resolve(Mustaches.execute( Mustache.compiler().escapeHTML(false).compile(relative), scope)); }
@Override public String executeTemplateText(final String templateText, final Map<String, Object> data) { final Template template = Mustache.compiler().nullValue("").compile(templateText); return template.execute(data); } }
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 ); }
/** Loads and compiles the template {@code name} using this compiler's configured template * loader. Note that this does no caching: the caller should cache the loaded template if * they expect to use it multiple times. * @return the compiled template. * @throw MustacheException if the template could not be loaded (due to I/O exception) or * compiled (due to syntax error, etc.). */ public Template loadTemplate (String name) throws MustacheException { Reader tin = null; try { tin = loader.getTemplate(name); return compile(tin); } catch (Exception e) { if (e instanceof RuntimeException) { throw (RuntimeException)e; } else { throw new MustacheException("Unable to load template: " + name, e); } } finally { if (tin != null) try { tin.close(); } catch (IOException ioe) { throw new RuntimeException(ioe); } } }
/** Compiles the supplied template into a repeatedly executable intermediate form. */ public Template compile (String template) { return compile(new StringReader(template)); }
private Template createTemplate(Resource resource) throws IOException { try (Reader reader = getReader(resource)) { return this.compiler.compile(reader); } }
@Override public View getView(String viewName, final ResourceLoader resourceLoader) throws Exception { String filename = filename(viewName); byte[] bytes = resourceLoader.load(filename); if (bytes == null) return null; Mustache.TemplateLoader loader = loader(resourceLoader); String template = new String(bytes); Mustache.Compiler compiler = getViewFactory(resourceLoader); Template mustache = compiler.withLoader(loader).compile(template); return view(mustache); }
@Override public String executeTemplateText(final String templateText, final Map<String, Object> data) { final Template template = Mustache.compiler().nullValue("").compile(templateText); return template.execute(data); } }