Search in sources :

Example 1 with Iso8601DateDirective

use of org.ambraproject.wombat.freemarker.Iso8601DateDirective 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 2 with Iso8601DateDirective

use of org.ambraproject.wombat.freemarker.Iso8601DateDirective 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;
}
Also used : AbbreviatedNameDirective(org.ambraproject.wombat.freemarker.AbbreviatedNameDirective) SiteTemplateLoader(org.ambraproject.wombat.config.site.SiteTemplateLoader) CssLinkDirective(org.ambraproject.wombat.freemarker.asset.CssLinkDirective) ReplaceParametersDirective(org.ambraproject.wombat.freemarker.ReplaceParametersDirective) Iso8601DateDirective(org.ambraproject.wombat.freemarker.Iso8601DateDirective) JsDirective(org.ambraproject.wombat.freemarker.asset.JsDirective) RenderJsDirective(org.ambraproject.wombat.freemarker.asset.RenderJsDirective) FreeMarkerConfigurer(org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer) ImmutableMap(com.google.common.collect.ImmutableMap) Bean(org.springframework.context.annotation.Bean)

Aggregations

ImmutableMap (com.google.common.collect.ImmutableMap)2 Iso8601DateDirective (org.ambraproject.wombat.freemarker.Iso8601DateDirective)2 ReplaceParametersDirective (org.ambraproject.wombat.freemarker.ReplaceParametersDirective)2 Bean (org.springframework.context.annotation.Bean)2 FreeMarkerConfigurer (org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer)2 FileTemplateLoader (freemarker.cache.FileTemplateLoader)1 MultiTemplateLoader (freemarker.cache.MultiTemplateLoader)1 TemplateLoader (freemarker.cache.TemplateLoader)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 SiteTemplateLoader (org.ambraproject.wombat.config.site.SiteTemplateLoader)1 AbbreviatedNameDirective (org.ambraproject.wombat.freemarker.AbbreviatedNameDirective)1 CssLinkDirective (org.ambraproject.wombat.freemarker.asset.CssLinkDirective)1 JsDirective (org.ambraproject.wombat.freemarker.asset.JsDirective)1 RenderJsDirective (org.ambraproject.wombat.freemarker.asset.RenderJsDirective)1