From a100c61ee6786f9149770e21c22ee4adcef689ed Mon Sep 17 00:00:00 2001 From: Alexander Alexeev Date: Mon, 12 Dec 2016 19:37:38 +0700 Subject: using thymeleaf static variables for show settings --- .../com/juick/www/configuration/WebAppConfiguration.java | 6 ------ .../juick/www/configuration/WwwServletConfiguration.java | 13 +++++++++++++ 2 files changed, 13 insertions(+), 6 deletions(-) (limited to 'juick-spring-www/src/main/java/com/juick/www/configuration') diff --git a/juick-spring-www/src/main/java/com/juick/www/configuration/WebAppConfiguration.java b/juick-spring-www/src/main/java/com/juick/www/configuration/WebAppConfiguration.java index a6632289..28a0f29a 100644 --- a/juick-spring-www/src/main/java/com/juick/www/configuration/WebAppConfiguration.java +++ b/juick-spring-www/src/main/java/com/juick/www/configuration/WebAppConfiguration.java @@ -2,7 +2,6 @@ package com.juick.www.configuration; import com.juick.www.HelpService; import com.juick.www.WebApp; -import com.juick.www.settings.TemplateSettingsHolder; import org.springframework.cache.annotation.EnableCaching; import org.springframework.cache.guava.GuavaCacheManager; import org.springframework.cache.interceptor.KeyGenerator; @@ -37,11 +36,6 @@ public class WebAppConfiguration { return messageSource; } - @Bean - public TemplateSettingsHolder settingsHolder() { - return new TemplateSettingsHolder(env); - } - @Bean public WebApp webApp() { return new WebApp(env); diff --git a/juick-spring-www/src/main/java/com/juick/www/configuration/WwwServletConfiguration.java b/juick-spring-www/src/main/java/com/juick/www/configuration/WwwServletConfiguration.java index 8da3321e..15f85c9a 100644 --- a/juick-spring-www/src/main/java/com/juick/www/configuration/WwwServletConfiguration.java +++ b/juick-spring-www/src/main/java/com/juick/www/configuration/WwwServletConfiguration.java @@ -4,10 +4,12 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; import com.juick.www.formatter.SpringDateFormatter; import nz.net.ultraq.thymeleaf.LayoutDialect; +import org.apache.commons.lang3.BooleanUtils; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; +import org.springframework.core.env.Environment; import org.springframework.format.FormatterRegistry; import org.springframework.http.CacheControl; import org.springframework.http.converter.HttpMessageConverter; @@ -25,6 +27,7 @@ import org.thymeleaf.spring4.templateresolver.SpringResourceTemplateResolver; import org.thymeleaf.spring4.view.ThymeleafViewResolver; import org.thymeleaf.templatemode.TemplateMode; +import javax.annotation.Resource; import java.util.List; import java.util.concurrent.TimeUnit; @@ -35,6 +38,8 @@ import java.util.concurrent.TimeUnit; @ComponentScan(basePackages = {"com.juick.www.controllers"}) @PropertySource("classpath:juick.conf") public class WwwServletConfiguration extends WebMvcConfigurationSupport { + @Resource + private Environment env; @Bean public SpringResourceTemplateResolver templateResolver() { @@ -79,6 +84,14 @@ public class WwwServletConfiguration extends WebMvcConfigurationSupport { ThymeleafViewResolver viewResolver = new ThymeleafViewResolver(); viewResolver.setTemplateEngine(templateEngine()); viewResolver.setCharacterEncoding("UTF-8"); + + viewResolver.addStaticVariable( + "showSape", BooleanUtils.toBoolean(env.getProperty("template.showSape", "true"))); + viewResolver.addStaticVariable( + "showAdv", BooleanUtils.toBoolean(env.getProperty("template.showAdv", "true"))); + viewResolver.addStaticVariable( + "showSponsors", BooleanUtils.toBoolean(env.getProperty("template.showSponsors", "false"))); + return viewResolver; } -- cgit v1.2.3