/** * Compiles a mustache template with a given scope (map of fields and values). * @param context a map of fields and values * @param template a Mustache template * @return the compiled template string */ public static String compileMustache(Map<String, Object> context, String template) { if (context == null || StringUtils.isBlank(template)) { return ""; } Writer writer = new StringWriter(); try { Mustache.compiler().escapeHTML(false).emptyStringIsFalse(true).compile(template).execute(context, writer); } finally { try { writer.close(); } catch (IOException e) { logger.error(null, e); } } return writer.toString(); }
/** * 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); }
@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); } }
@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); }