use of org.springframework.web.servlet.view.mustache.jmustache.JMustacheTemplateFactory in project alf.io by alfio-event.
the class MvcConfiguration method getTemplateFactory.
@Bean
public JMustacheTemplateFactory getTemplateFactory() throws Exception {
final JMustacheTemplateFactory templateFactory = new JMustacheTemplateFactory();
templateFactory.setPrefix("/WEB-INF/templates");
templateFactory.setSuffix(".ms");
templateFactory.setTemplateLoader(templateLoader);
templateFactory.setCompiler(Mustache.compiler().escapeHTML(true).standardsMode(false).defaultValue("").nullValue("").withFormatter((o) -> {
if (o instanceof ZonedDateTime) {
return DateTimeFormatter.ISO_ZONED_DATE_TIME.format((ZonedDateTime) o);
} else if (o instanceof DefaultMessageSourceResolvable) {
DefaultMessageSourceResolvable m = ((DefaultMessageSourceResolvable) o);
return m.getCode() + " " + Arrays.stream(Optional.ofNullable(m.getArguments()).orElse(new Object[] {})).map(x -> "[" + x.toString() + "]").collect(Collectors.joining(" "));
} else {
return String.valueOf(o);
}
}).withLoader(templateLoader));
templateFactory.afterPropertiesSet();
return templateFactory;
}
Aggregations