use of org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer in project wombat by PLOS.
the class SpringConfiguration method freeMarkerConfig.
@Bean
public FreeMarkerConfig freeMarkerConfig(ServletContext servletContext, SiteSet siteSet, IsDevFeatureEnabledDirective isDevFeatureEnabledDirective, SiteLinkDirective siteLinkDirective, RenderCssLinksDirective renderCssLinksDirective, RenderJsDirective renderJsDirective, BuildInfoDirective buildInfoDirective, FetchHtmlDirective fetchHtmlDirective, ThemeConfigDirective themeConfigDirective, AppLinkDirective appLinkDirective, ArticleExcerptTransformDirective articleExcerptTransformDirective, GlobalConfigDirective globalConfigDirective) throws IOException {
SiteTemplateLoader loader = new SiteTemplateLoader(servletContext, siteSet);
FreeMarkerConfigurer config = new FreeMarkerConfigurer();
config.setPreTemplateLoaders(loader);
// Freemarker custom directives used throughout the app.
// TODO: should all of these be their own @Beans? I'm only doing that now for
// ones that have dependencies on spring-injection.
ImmutableMap.Builder<String, Object> variables = ImmutableMap.builder();
variables.put("formatJsonDate", new Iso8601DateDirective());
variables.put("replaceParams", new ReplaceParametersDirective());
variables.put("siteLink", siteLinkDirective);
variables.put("isDevFeatureEnabled", isDevFeatureEnabledDirective);
variables.put("cssLink", new CssLinkDirective());
variables.put("renderCssLinks", renderCssLinksDirective);
variables.put("js", new JsDirective());
variables.put("renderJs", renderJsDirective);
variables.put("buildInfo", buildInfoDirective);
variables.put("fetchHtml", fetchHtmlDirective);
variables.put("themeConfig", themeConfigDirective);
variables.put("appLink", appLinkDirective);
variables.put("abbreviatedName", new AbbreviatedNameDirective());
variables.put("xform", articleExcerptTransformDirective);
variables.put("globalConfig", globalConfigDirective);
config.setFreemarkerVariables(variables.build());
return config;
}
use of org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer in project Ganster-CMS by Gangster-trio.
the class FreemarkerConfig method loadPathConfig.
@Bean
public FreeMarkerConfigurer loadPathConfig() {
FreeMarkerConfigurer configurer = new FreeMarkerConfigurer();
String path = settingService.get(CmsConst.SKIN_PATH_SETTING);
String DEFAULT_SKIN_PATH = "classpath:templates";
if (!path.isEmpty()) {
configurer.setTemplateLoaderPaths(DEFAULT_SKIN_PATH, path);
LOGGER.info("Gangster CMS : templates path = {},{}", DEFAULT_SKIN_PATH, path);
} else {
configurer.setTemplateLoaderPath(DEFAULT_SKIN_PATH);
// configurer.setTemplateLoaderPath("file:/home/bigmeng/Desktop/templates/");
}
configurer.setDefaultEncoding("UTF-8");
return configurer;
}
use of org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer in project spring-boot by spring-projects.
the class FreeMarkerAutoConfigurationServletIntegrationTests method renderTemplate.
@Test
void renderTemplate() throws Exception {
load();
FreeMarkerConfigurer freemarker = this.context.getBean(FreeMarkerConfigurer.class);
StringWriter writer = new StringWriter();
freemarker.getConfiguration().getTemplate("message.ftlh").process(new DataModel(), writer);
assertThat(writer.toString()).contains("Hello World");
}
use of org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer in project spring-boot by spring-projects.
the class FreeMarkerServletWebConfiguration method freeMarkerConfigurer.
@Bean
@ConditionalOnMissingBean(FreeMarkerConfig.class)
FreeMarkerConfigurer freeMarkerConfigurer() {
FreeMarkerConfigurer configurer = new FreeMarkerConfigurer();
applyProperties(configurer);
return configurer;
}
use of org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer in project leopard by tanhaichao.
the class FreeMarkerUtil method getFreeMarkerConfigurer.
public static FreeMarkerConfigurer getFreeMarkerConfigurer(ApplicationContext applicationContext, String templateLoaderPath) {
Map<String, Object> freemarkerVariables = new HashMap<String, Object>();
freemarkerVariables.put("xml_escape", "fmXmlEscape");
freemarkerVariables.put("replaceParam", new ReplaceParamTemplateMethod());
freemarkerVariables.put("timeAgo", new TimeAgoTemplateMethod());
freemarkerVariables.putAll(listTemplateMethod(applicationContext));
Properties freemarkerSettings = new Properties();
freemarkerSettings.put("template_update_delay", "1");
freemarkerSettings.put("defaultEncoding", "UTF-8");
FreeMarkerConfigurer configurer = new FreeMarkerConfigurer();
configurer.setTemplateLoaderPath(templateLoaderPath);
configurer.setFreemarkerVariables(freemarkerVariables);
configurer.setFreemarkerSettings(freemarkerSettings);
try {
configurer.afterPropertiesSet();
} catch (IOException e) {
throw new RuntimeException(e.getMessage(), e);
} catch (TemplateException e) {
throw new RuntimeException(e.getMessage(), e);
}
return configurer;
}
Aggregations