本文整理汇总了Java中de.neuland.jade4j.JadeConfiguration类的典型用法代码示例。如果您正苦于以下问题:Java JadeConfiguration类的具体用法?Java JadeConfiguration怎么用?Java JadeConfiguration使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JadeConfiguration类属于de.neuland.jade4j包,在下文中一共展示了JadeConfiguration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: produce
import de.neuland.jade4j.JadeConfiguration; //导入依赖的package包/类
@Produces
@ViewEngineConfig
JadeConfiguration produce() {
loadConfig();
JadeConfiguration jade = new JadeConfiguration();
jade.setMode(Mode.valueOf(property(MODE).orElse("XHTML")));
jade.setCaching(Boolean.valueOf(property(CACHING).orElse("true")));
jade.setPrettyPrint(Boolean.valueOf(property(PRETTY_PRINT).orElse("false")));
for (Map.Entry<String, Object> filter : getExtensions(FILTER_QUALIFIER).entrySet()) {
jade.setFilter(filter.getKey(), (Filter) filter.getValue());
}
jade.setSharedVariables(getExtensions(HELPER_QUALIFIER));
String encoding = property(ENCODING).orElse("UTF-8");
jade.setTemplateLoader(new ServletContextTemplateLoader(servletContext, encoding));
return jade;
}
示例2: init
import de.neuland.jade4j.JadeConfiguration; //导入依赖的package包/类
@Override
public void init(Application application) {
super.init(application);
Router router = getRouter();
PippoSettings pippoSettings = getPippoSettings();
configuration = new JadeConfiguration();
configuration.setTemplateLoader(new ClassTemplateLoader(JadeTemplateEngine.class, getTemplatePathPrefix()));
configuration.setMode(Mode.HTML);
if (pippoSettings.isDev()) {
configuration.setPrettyPrint(true);
configuration.setCaching(false); // disable cache
}
// set global template variables
configuration.getSharedVariables().put("contextPath", router.getContextPath());
configuration.getSharedVariables().put("appPath", router.getApplicationPath());
// allow custom initialization
init(application, configuration);
}
示例3: shouldRenderPrettyTemplateTemplate
import de.neuland.jade4j.JadeConfiguration; //导入依赖的package包/类
@Test
public void shouldRenderPrettyTemplateTemplate() throws Exception {
EnvironmentTestUtils.addEnvironment(this.context, "spring.jade4j.prettyPrint:true");
this.context.register(Jade4JAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class);
this.context.refresh();
JadeConfiguration engine = this.context.getBean(JadeConfiguration.class);
JadeTemplate template = engine.getTemplate("demo.jade");
Map<String, Object> params = Collections.emptyMap();
String result = engine.renderTemplate(template, params);
String expected = "<html>\n" +
" <head>\n" +
" <title>Jade</title>\n" +
" </head>\n" +
" <body>\n" +
" <h1>Jade - Template engine</h1>\n" +
" </body>\n" +
"</html>";
assertEquals(expected, result.trim());
}
示例4: renderNonWebAppTemplate
import de.neuland.jade4j.JadeConfiguration; //导入依赖的package包/类
@Test
@Ignore
public void renderNonWebAppTemplate() throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
Jade4JAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
assertEquals(0, context.getBeanNamesForType(ViewResolver.class).length);
try {
JadeConfiguration engine = this.context.getBean(JadeConfiguration.class);
JadeTemplate template = engine.getTemplate("demo.jade");
Map<String, Object> params = params();
String result = engine.renderTemplate(template, params);
assertThat(result, containsString("With user"));
} finally {
context.close();
}
}
示例5: configureJade4J
import de.neuland.jade4j.JadeConfiguration; //导入依赖的package包/类
private void configureJade4J() {
jadeConfiguration = new JadeConfiguration();
String srcDir = buildSrcDir();
if ((ninjaProperties.isDev() || ninjaProperties.isTest())
&& new File(srcDir).exists()) {
jadeConfiguration.setTemplateLoader(new FileTemplateLoader(srcDir,
"UTF-8"));
jadeConfiguration.setCaching(false);
jadeConfiguration.setPrettyPrint(true);
} else {
jadeConfiguration.setTemplateLoader(new ClasspathTemplateLoader());
jadeConfiguration.setCaching(true);
jadeConfiguration.setPrettyPrint(false);
}
jadeConfiguration.setMode(Mode.HTML);
}
示例6: JadeViewRenderer
import de.neuland.jade4j.JadeConfiguration; //导入依赖的package包/类
/**
* JadeViewRenderer constructor that allows you to provide an instance
* of the object mapper.
* @param objectMapper
*/
private JadeViewRenderer(ObjectMapper objectMapper) {
this.mapper = objectMapper;
this.cache = CacheBuilder.newBuilder()
.build(new CacheLoader<Class<? extends View>, JadeConfiguration>() {
@Override
public JadeConfiguration load(Class<? extends View> aClass) throws Exception {
logger.debug("building new JadeConfiguration for views class {}", aClass);
JadeConfiguration config = new JadeConfiguration();
config.setTemplateLoader(new JadeTemplateLoader(aClass));
return config;
}
});
}
示例7: jadeConfiguration
import de.neuland.jade4j.JadeConfiguration; //导入依赖的package包/类
@Bean
@ConditionalOnMissingBean(JadeConfiguration.class)
public JadeConfiguration jadeConfiguration(TemplateLoader jadeTemplateLoader) {
JadeConfiguration configuration = new JadeConfiguration();
configuration.setCaching(false); //Cache is handled by spring
configuration.setPrettyPrint(properties.isPrettyPrint());
configuration.setTemplateLoader(jadeTemplateLoader);
//configuration.setSharedVariables(sharedVariables);
//configuration.setFilter(name, filter);
//configuration.setMode(mode);
return configuration;
}
示例8: jadeViewResolver
import de.neuland.jade4j.JadeConfiguration; //导入依赖的package包/类
@Bean
@ConditionalOnMissingBean(JadeViewResolver.class)
public JadeViewResolver jadeViewResolver(JadeConfiguration jadeConfiguration) {
JadeViewResolver resolver = new JadeViewResolver();
resolver.setPrefix(properties.getPrefix());
resolver.setSuffix(properties.getSuffix());
resolver.setCache(properties.isCache());
resolver.setViewNames(properties.getViewNames());
resolver.setContentType(properties.getContentType());
resolver.setJadeConfiguration(jadeConfiguration);
resolver.setOrder(Ordered.LOWEST_PRECEDENCE-10);
return resolver;
}
示例9: jadeConfiguration
import de.neuland.jade4j.JadeConfiguration; //导入依赖的package包/类
@Bean
public JadeConfiguration jadeConfiguration(TemplateLoader jadeTemplateLoader) {
JadeConfiguration configuration = new JadeConfiguration();
configuration.setCaching(false);
configuration.setPrettyPrint(true);
configuration.setTemplateLoader(jadeTemplateLoader);
return configuration;
}
示例10: jadeViewResolver
import de.neuland.jade4j.JadeConfiguration; //导入依赖的package包/类
@Bean
public JadeViewResolver jadeViewResolver(JadeConfiguration jadeConfiguration) {
JadeViewResolver resolver = new JadeViewResolver();
resolver.setPrefix("classpath:/templates/");
resolver.setSuffix(".jade");
resolver.setCache(false);
resolver.setJadeConfiguration(jadeConfiguration);
resolver.setOrder(Ordered.LOWEST_PRECEDENCE-10);
return resolver;
}
示例11: renderString
import de.neuland.jade4j.JadeConfiguration; //导入依赖的package包/类
@Override
public void renderString(String templateContent, Map<String, Object> model, Writer writer) {
// prepare the locale-aware i18n method
String language = (String) model.get(PippoConstants.REQUEST_PARAMETER_LANG);
if (StringUtils.isNullOrEmpty(language)) {
language = getLanguageOrDefault(language);
}
// prepare the locale-aware prettyTime method
Locale locale = (Locale) model.get(PippoConstants.REQUEST_PARAMETER_LOCALE);
if (locale == null) {
locale = getLocaleOrDefault(language);
}
model.put("pippo", new PippoHelper(getMessages(), language, locale, getRouter()));
try (StringReader reader = new StringReader(templateContent)) {
ReaderTemplateLoader stringTemplateLoader = new ReaderTemplateLoader(reader, "StringTemplate");
JadeConfiguration stringTemplateConfiguration = new JadeConfiguration();
stringTemplateConfiguration.setCaching(false);
stringTemplateConfiguration.setTemplateLoader(stringTemplateLoader);
stringTemplateConfiguration.setMode(configuration.getMode());
stringTemplateConfiguration.setPrettyPrint(configuration.isPrettyPrint());
JadeTemplate stringTemplate = configuration.getTemplate("StringTemplate");
configuration.renderTemplate(stringTemplate, model, writer);
writer.flush();
} catch (Exception e) {
throw new PippoRuntimeException(e);
}
}
示例12: getJadeTemplate
import de.neuland.jade4j.JadeConfiguration; //导入依赖的package包/类
private JadeTemplate getJadeTemplate(String templatePath) throws IOException {
JadeConfiguration config = new JadeConfiguration();
if (isDebugEnabled) {
config.clearCache();
config.setCaching(false);
}
config.setTemplateLoader(new ClasspathTemplateLoader());
return config.getTemplate(templatePath);
}
示例13: defaultJadeConfiguration
import de.neuland.jade4j.JadeConfiguration; //导入依赖的package包/类
@Bean
public JadeConfiguration defaultJadeConfiguration() {
JadeConfiguration configuration = new JadeConfiguration();
configuration.setCaching(this.environment.getProperty("caching", Boolean.class, true));
configuration.setTemplateLoader(defaultSpringTemplateLoader());
configuration.setPrettyPrint(this.environment.getProperty("prettyPrint", Boolean.class, false));
configuration.setMode(this.environment.getProperty("mode", Jade4J.Mode.class, Jade4J.Mode.HTML));
return configuration;
}
示例14: shouldRenderTemplateAsExpected
import de.neuland.jade4j.JadeConfiguration; //导入依赖的package包/类
@Test
public void shouldRenderTemplateAsExpected() throws Exception {
EnvironmentTestUtils.addEnvironment(this.context, "spring.jade4j.mode:XHTML");
this.context.register(Jade4JAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class);
this.context.refresh();
JadeConfiguration engine = this.context.getBean(JadeConfiguration.class);
JadeTemplate template = engine.getTemplate("demo.jade");
Map<String, Object> params = Collections.emptyMap();
String result = engine.renderTemplate(template, params);
String expected = "<html><head><title>Jade</title></head><body><h1>Jade - Template engine</h1></body></html>";
assertEquals(expected, result);
}
示例15: shouldRenderTemplateWithParams
import de.neuland.jade4j.JadeConfiguration; //导入依赖的package包/类
@Test
public void shouldRenderTemplateWithParams() throws Exception {
EnvironmentTestUtils.addEnvironment(this.context, "spring.jade4j.mode:XHTML");
this.context.register(Jade4JAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class);
this.context.refresh();
JadeConfiguration engine = this.context.getBean(JadeConfiguration.class);
JadeTemplate template = engine.getTemplate("demo.jade");
Map<String, Object> params = params();
String result = engine.renderTemplate(template, params);
String expected = "<html><head><title>Jade</title></head><body><h1>Jade - Template engine</h1><h2>With user</h2></body></html>";
assertEquals(expected, result);
}