本文整理汇总了Java中de.neuland.jade4j.JadeConfiguration.setSharedVariables方法的典型用法代码示例。如果您正苦于以下问题:Java JadeConfiguration.setSharedVariables方法的具体用法?Java JadeConfiguration.setSharedVariables怎么用?Java JadeConfiguration.setSharedVariables使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类de.neuland.jade4j.JadeConfiguration
的用法示例。
在下文中一共展示了JadeConfiguration.setSharedVariables方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: configure
import de.neuland.jade4j.JadeConfiguration; //导入方法依赖的package包/类
@Override
public void configure(final Env env, final Config conf, final Binder binder) {
JadeConfiguration jadeconf = new JadeConfiguration();
boolean dev = env.name().equals("dev");
boolean caching = conf.hasPath("jade.caching")
? conf.getBoolean("jade.caching")
: !dev;
boolean prettyPrint = conf.hasPath("jade.prettyprint")
? conf.getBoolean("jade.prettyprint")
: dev;
jadeconf.setCaching(caching);
jadeconf.setPrettyPrint(prettyPrint);
Map<String, Object> sharedVariables = new HashMap<>(2);
sharedVariables.put("env", env);
sharedVariables.put("xss", new XssHelper(env));
jadeconf.setSharedVariables(sharedVariables);
jadeconf.setTemplateLoader(new ClasspathTemplateLoader());
if (callback != null) {
callback.accept(jadeconf, conf);
}
// rewrite template loader avoid NPE
jadeconf.setTemplateLoader(new IOTemplateLoader(jadeconf.getTemplateLoader()));
binder.bind(JadeConfiguration.class)
.toInstance(jadeconf);
Multibinder.newSetBinder(binder, Renderer.class).addBinding()
.toInstance(new Engine(jadeconf, suffix));
}
示例3: jade
import de.neuland.jade4j.JadeConfiguration; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private Block jade(final String suffix, final boolean caching, final boolean prettyPrint) {
return unit -> {
JadeConfiguration jadeConfiguration = unit.mockConstructor(JadeConfiguration.class);
jadeConfiguration.setCaching(caching);
jadeConfiguration.setPrettyPrint(prettyPrint);
Env env = unit.get(Env.class);
Map<String, Object> sharedVariables = unit.constructor(HashMap.class)
.build(2);
expect(sharedVariables.put(eq( "env"), eq(env))).andReturn(null);
expect(sharedVariables.put(eq( "xss"), isA(XssHelper.class))).andReturn(null);
jadeConfiguration.setSharedVariables(sharedVariables);
ClasspathTemplateLoader classpathTemplateLoader = unit
.mockConstructor(ClasspathTemplateLoader.class);
jadeConfiguration.setTemplateLoader(classpathTemplateLoader);
expect(jadeConfiguration.getTemplateLoader()).andReturn(classpathTemplateLoader);
Jade.IOTemplateLoader safetl = unit
.constructor(Jade.IOTemplateLoader.class)
.build(classpathTemplateLoader);
jadeConfiguration.setTemplateLoader(safetl);
AnnotatedBindingBuilder<JadeConfiguration> configBB = unit
.mock(AnnotatedBindingBuilder.class);
configBB.toInstance(jadeConfiguration);
Binder binder = unit.get(Binder.class);
expect(binder.bind(JadeConfiguration.class)).andReturn(configBB);
Engine engine = unit.mockConstructor(
Engine.class, new Class[]{JadeConfiguration.class, String.class },
jadeConfiguration, suffix);
LinkedBindingBuilder<Renderer> ffLBB = unit.mock(LinkedBindingBuilder.class);
ffLBB.toInstance(engine);
Multibinder<Renderer> formatter = unit.mock(Multibinder.class);
expect(formatter.addBinding()).andReturn(ffLBB);
unit.mockStatic(Multibinder.class);
expect(Multibinder.newSetBinder(binder, Renderer.class)).andReturn(formatter);
};
}