Search in sources :

Example 1 with FreeMarkerConfigurer

use of org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer in project cuba by cuba-platform.

the class AppFrontConfig method freemarkerConfig.

@Bean
public FreeMarkerConfigurer freemarkerConfig() {
    FreeMarkerConfigurer freemarkerConfig = new FreeMarkerConfigurer();
    freemarkerConfig.setTemplateLoaderPath("/front/");
    return freemarkerConfig;
}
Also used : FreeMarkerConfigurer(org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer) Bean(org.springframework.context.annotation.Bean)

Example 2 with FreeMarkerConfigurer

use of org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer in project wombat by PLOS.

the class WombatControllerTestConfig method freeMarkerConfig.

@Bean
public FreeMarkerConfig freeMarkerConfig(ServletContext servletContext) throws IOException {
    String[] templates = getFreeMarkerTemplateDirsForTest();
    List<TemplateLoader> loaders = new ArrayList<TemplateLoader>();
    for (String template : templates) {
        FileTemplateLoader loader = new FileTemplateLoader(new File(servletContext.getRealPath(template)));
        loaders.add(loader);
    }
    MultiTemplateLoader mtl = new MultiTemplateLoader(loaders.toArray(new TemplateLoader[0]));
    FreeMarkerConfigurer config = new FreeMarkerConfigurer();
    config.setPreTemplateLoaders(mtl);
    ImmutableMap.Builder<String, Object> variables = ImmutableMap.builder();
    variables.put("formatJsonDate", new Iso8601DateDirective());
    variables.put("replaceParams", new ReplaceParametersDirective());
    variables.put("siteLink", getEmptyTemplateDirectiveModel());
    variables.put("cssLink", getEmptyTemplateDirectiveModel());
    variables.put("renderCssLinks", getEmptyTemplateDirectiveModel());
    variables.put("js", getEmptyTemplateDirectiveModel());
    variables.put("renderJs", getEmptyTemplateDirectiveModel());
    variables.put("buildInfo", getEmptyTemplateDirectiveModel());
    variables.put("fetchHtml", getEmptyTemplateDirectiveModel());
    variables.put("themeConfig", getEmptyTemplateDirectiveModel());
    variables.put("appLink", getEmptyTemplateDirectiveModel());
    config.setFreemarkerVariables(variables.build());
    return config;
}
Also used : TemplateLoader(freemarker.cache.TemplateLoader) FileTemplateLoader(freemarker.cache.FileTemplateLoader) MultiTemplateLoader(freemarker.cache.MultiTemplateLoader) ArrayList(java.util.ArrayList) FreeMarkerConfigurer(org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer) ImmutableMap(com.google.common.collect.ImmutableMap) MultiTemplateLoader(freemarker.cache.MultiTemplateLoader) ReplaceParametersDirective(org.ambraproject.wombat.freemarker.ReplaceParametersDirective) FileTemplateLoader(freemarker.cache.FileTemplateLoader) File(java.io.File) Iso8601DateDirective(org.ambraproject.wombat.freemarker.Iso8601DateDirective) Bean(org.springframework.context.annotation.Bean)

Example 3 with FreeMarkerConfigurer

use of org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer in project tutorials by eugenp.

the class SpringWebConfig method freemarkerConfig.

@Bean
public FreeMarkerConfigurer freemarkerConfig() {
    FreeMarkerConfigurer freeMarkerConfigurer = new FreeMarkerConfigurer();
    freeMarkerConfigurer.setTemplateLoaderPath("/WEB-INF/views/ftl/");
    return freeMarkerConfigurer;
}
Also used : FreeMarkerConfigurer(org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer) Bean(org.springframework.context.annotation.Bean)

Example 4 with FreeMarkerConfigurer

use of org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer in project spring-cloud-netflix by spring-cloud.

the class HystrixDashboardConfiguration method freeMarkerConfigurer.

/**
 * Overrides Spring Boot's {@link FreeMarkerAutoConfiguration} to prefer using a
 * {@link SpringTemplateLoader} instead of the file system. This corrects an issue
 * where Spring Boot may use an empty 'templates' file resource to resolve templates
 * instead of the packaged Hystrix classpath templates.
 * @return FreeMarker configuration
 */
@Bean
public FreeMarkerConfigurer freeMarkerConfigurer() {
    FreeMarkerConfigurer configurer = new FreeMarkerConfigurer();
    configurer.setTemplateLoaderPaths(DEFAULT_TEMPLATE_LOADER_PATH);
    configurer.setDefaultEncoding(DEFAULT_CHARSET);
    configurer.setPreferFileSystemAccess(false);
    return configurer;
}
Also used : FreeMarkerConfigurer(org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer) ServletRegistrationBean(org.springframework.boot.web.servlet.ServletRegistrationBean) Bean(org.springframework.context.annotation.Bean)

Example 5 with FreeMarkerConfigurer

use of org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer in project GMM by Katharsas.

the class ApplicationConfiguration method freemarkerConfig.

/**
 * FreeMarker (ftl) configuration
 */
@Bean
public FreeMarkerConfigurer freemarkerConfig() throws IOException, TemplateException {
    final FreeMarkerConfigurer result = new FreeMarkerConfigurer();
    // template path
    result.setTemplateLoaderPath("/WEB-INF/ftl/");
    result.setDefaultEncoding("UTF-8");
    // static access
    final Version version = freemarker.template.Configuration.getVersion();
    final BeansWrapper wrapper = new BeansWrapper(version);
    final TemplateHashModel statics = wrapper.getStaticModels();
    final Map<String, Object> shared = new HashMap<>();
    for (final Class<?> clazz : ElFunctions.staticClasses) {
        shared.put(clazz.getSimpleName(), statics.get(clazz.getName()));
    }
    result.setFreemarkerVariables(shared);
    return result;
}
Also used : TemplateHashModel(freemarker.template.TemplateHashModel) Version(freemarker.template.Version) HashMap(java.util.HashMap) BeansWrapper(freemarker.ext.beans.BeansWrapper) FreeMarkerConfigurer(org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer) PropertiesFactoryBean(org.springframework.beans.factory.config.PropertiesFactoryBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

FreeMarkerConfigurer (org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer)17 Bean (org.springframework.context.annotation.Bean)12 Properties (java.util.Properties)4 ImmutableMap (com.google.common.collect.ImmutableMap)2 StringWriter (java.io.StringWriter)2 HashMap (java.util.HashMap)2 Iso8601DateDirective (org.ambraproject.wombat.freemarker.Iso8601DateDirective)2 ReplaceParametersDirective (org.ambraproject.wombat.freemarker.ReplaceParametersDirective)2 Test (org.junit.jupiter.api.Test)2 FileTemplateLoader (freemarker.cache.FileTemplateLoader)1 MultiTemplateLoader (freemarker.cache.MultiTemplateLoader)1 TemplateLoader (freemarker.cache.TemplateLoader)1 BeansWrapper (freemarker.ext.beans.BeansWrapper)1 Configuration (freemarker.template.Configuration)1 TemplateException (freemarker.template.TemplateException)1 TemplateHashModel (freemarker.template.TemplateHashModel)1 Version (freemarker.template.Version)1 ReplaceParamTemplateMethod (io.leopard.web.freemarker.template.ReplaceParamTemplateMethod)1 TimeAgoTemplateMethod (io.leopard.web.freemarker.template.TimeAgoTemplateMethod)1 File (java.io.File)1