Refine search
@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); }
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 Template createTemplate(Resource resource) throws IOException { try (Reader reader = getReader(resource)) { return this.compiler.compile(reader); } }
@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)); }
/** Compiles the supplied template into a repeatedly executable intermediate form. */ public Template compile (String template) { return compile(new StringReader(template)); }
/** 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); } } }
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 ); }
public static Template compile(String name, CharSource charSource) { try (Reader reader = charSource.openBufferedStream()) { return createCompiler().compile(reader); } catch (IOException e) { throw new RuntimeException(e); } }
@Override public Mustache.Compiler processCompiler(Mustache.Compiler compiler) { // To avoid unexpected behaviors when options are passed programmatically such as { "useCollection": "" } return super.processCompiler(compiler).emptyStringIsFalse(true); }
@Override public Mustache.Compiler processCompiler(Mustache.Compiler compiler) { // To avoid unexpected behaviors when options are passed programmatically such as { "useCollection": "" } return super.processCompiler(compiler).emptyStringIsFalse(true); } }
public static Template compile(String name, CharSource charSource) { try (Reader reader = charSource.openBufferedStream()) { return createCompiler().compile(reader); } catch (IOException e) { throw new RuntimeException(e); } }
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); } }
@Override public Mustache.Compiler processCompiler(Mustache.Compiler compiler) { // To avoid unexpected behaviors when options are passed programmatically such as { "supportsAsync": "" } return super.processCompiler(compiler).emptyStringIsFalse(true); } }
@Override public Mustache.Compiler processCompiler(Mustache.Compiler compiler) { // To avoid unexpected behaviors when options are passed programmatically such as { "supportsAsync": "" } return super.processCompiler(compiler).emptyStringIsFalse(true); } }
@Override public Mustache.Compiler processCompiler(Mustache.Compiler compiler) { // To avoid unexpected behaviors when options are passed programmatically such as { "supportsAsync": "" } return super.processCompiler(compiler).emptyStringIsFalse(true); } }
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)); }
/** * Override the Mustache compiler configuration. * <p> * We don't want to have special characters escaped * * @param compiler the compiler. * @return the compiler to use. */ @Override public Mustache.Compiler processCompiler(Mustache.Compiler compiler) { compiler = super.processCompiler(compiler).emptyStringIsFalse(true); return compiler.withEscaper(Escapers.NONE); }
private Template template(InputStream template, String path) { if (reloading) { return compiler.compile(new InputStreamReader(template, UTF8)); } else { Template t = templates.get(path); if (t == null) { t = compiler.compile(new InputStreamReader(template, UTF8)); templates.put(path, t); } return t; } } }