Search in sources :

Example 1 with PluralizeDirective

use of org.ambraproject.wombat.freemarker.PluralizeDirective 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, RuntimeConfiguration runtimeConfiguration) 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("pluralize", new PluralizeDirective());
    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);
    variables.put("collectionsUrl", runtimeConfiguration.getCollectionsUrl());
    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) PluralizeDirective(org.ambraproject.wombat.freemarker.PluralizeDirective) 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)1 SiteTemplateLoader (org.ambraproject.wombat.config.site.SiteTemplateLoader)1 AbbreviatedNameDirective (org.ambraproject.wombat.freemarker.AbbreviatedNameDirective)1 Iso8601DateDirective (org.ambraproject.wombat.freemarker.Iso8601DateDirective)1 PluralizeDirective (org.ambraproject.wombat.freemarker.PluralizeDirective)1 ReplaceParametersDirective (org.ambraproject.wombat.freemarker.ReplaceParametersDirective)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 Bean (org.springframework.context.annotation.Bean)1 FreeMarkerConfigurer (org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer)1