Java源码示例:org.jtwig.environment.EnvironmentConfigurationBuilder
示例1
@Override
public void configure(EnvironmentConfigurationBuilder configurationBuilder) {
configurationBuilder.functions()
.add(new JtwigFunction() {
@Override
public String name() {
return "void";
}
@Override
public Collection<String> aliases() {
return Collections.emptyList();
}
@Override
public Object execute(FunctionRequest request) {
return request.get(0);
}
});
}
示例2
@Override
public void configure(JtwigViewResolver viewResolver) {
viewResolver.setRenderer(
new JtwigRenderer(
EnvironmentConfigurationBuilder
.configuration()
.extensions().add(new SpringTranslateExtension(SpringTranslateExtensionConfiguration
.builder(messageSource)
.withLocaleResolver(localeResolver)
.build())).and()
.build()
)
);
viewResolver.setViewNames("*-jtwig");
viewResolver.setPrefix("/WEB-INF/jtwig/");
viewResolver.setSuffix(".twig");
}
示例3
@Bean
public JtwigViewResolver rqueueViewResolver() {
EnvironmentConfiguration configuration =
EnvironmentConfigurationBuilder.configuration()
.functions()
.add(new DateTimeFunction())
.and()
.build();
JtwigRenderer renderer = new JtwigRenderer(configuration);
JtwigViewResolver viewResolver = new JtwigViewResolver();
viewResolver.setRenderer(renderer);
viewResolver.setPrefix("classpath:/templates/rqueue/");
viewResolver.setSuffix(".html");
return viewResolver;
}
示例4
public static EnvironmentConfiguration get() {
if (configuration == null) {
configuration = EnvironmentConfigurationBuilder
.configuration()
.parser()
.syntax()
.withStartCode("/*").withEndCode("*/")
.and()
.withoutTemplateCache()
.and()
.build();
}
return configuration;
}
示例5
@Test(expected = CalculationException.class)
public void resolveMapPropertyWhenNotPresentStrictMode() {
JtwigTemplate.inlineTemplate("{{ value.test }}", EnvironmentConfigurationBuilder.configuration()
.render()
.withStrictMode(true)
.and()
.build())
.render(JtwigModel.newModel().with("value", ImmutableMap.builder().build()));
}
示例6
@Test
public void configWithMultipleFileLoadersAnyType() throws Exception {
File tempFile = File.createTempFile("jtwig-", ".twig");
String parent = tempFile.getParent();
String filename = tempFile.getName();
FileUtils.write(tempFile, "Hello");
String result = JtwigTemplate.inlineTemplate("{% include '" + filename + "' %}", EnvironmentConfigurationBuilder.configuration()
.resources().resourceLoaders().add(new TypedResourceLoader(ResourceReference.FILE, new FileResourceLoader(new File(parent)))).and().and()
.build()).render(JtwigModel.newModel());
assertThat(result, is("Hello"));
}
示例7
@Test
public void configWithMultipleFileLoadersFileType() throws Exception {
File tempFile = File.createTempFile("jtwig-", ".twig");
String parent = tempFile.getParent();
String filename = tempFile.getName();
FileUtils.write(tempFile, "Hello");
String result = JtwigTemplate.inlineTemplate("{% include 'file:" + filename + "' %}", EnvironmentConfigurationBuilder.configuration()
.resources().resourceLoaders().add(new TypedResourceLoader(ResourceReference.FILE, new FileResourceLoader(new File(parent)))).and().and()
.build()).render(JtwigModel.newModel());
assertThat(result, is("Hello"));
}
示例8
@Test
public void configWithoutLoaderFileType() throws Exception {
File tempFile = File.createTempFile("jtwig-", ".twig");
expectedException.expectMessage("Resource 'file:blah' (resolved to 'file:blah') not found");
expectedException.expect(ResourceNotFoundException.class);
JtwigTemplate.inlineTemplate("{% include 'file:blah' %}", EnvironmentConfigurationBuilder.configuration()
.resources().resourceLoaders().add(new TypedResourceLoader(ResourceReference.FILE, new FileResourceLoader(tempFile.getParentFile()))).and().and()
.build())
.render(JtwigModel.newModel());
}
示例9
@Test
public void cachingPropertyResolutionWithCache() {
JtwigTemplate template = JtwigTemplate.inlineTemplate("{{ value.key }}", EnvironmentConfigurationBuilder.configuration()
.propertyResolver().withCache(new SelectionPropertyResolverPersistentCache(new ConcurrentHashMap<SelectionPropertyResolverCacheKey, PropertyResolver>())).and()
.build());
String result1 = template.render(JtwigModel.newModel().with("value", new SubModelA()));
String result2 = template.render(JtwigModel.newModel().with("value", new SubModelB()));
assertThat(result1, is("A"));
assertThat(result2, is("B"));
}
示例10
@Before
public void setupConfiguration() {
final ConcurrentHashMap<SelectionPropertyResolverCacheKey, PropertyResolver> resolverHashMap = new ConcurrentHashMap<>();
final SelectionPropertyResolverPersistentCache resolverCache = new SelectionPropertyResolverPersistentCache(resolverHashMap);
configuration = EnvironmentConfigurationBuilder.configuration()
.propertyResolver().withCache(resolverCache).and()
.build();
}
示例11
public AndRenderConfigurationBuilder(EnvironmentConfigurationBuilder parent) {
this.parent = parent;
}
示例12
public AndRenderConfigurationBuilder(RenderConfiguration prototype, EnvironmentConfigurationBuilder parent) {
super(prototype);
this.parent = parent;
}
示例13
@Override
public EnvironmentConfigurationBuilder and () {
return parent;
}
示例14
public AndEscapeEngineConfigurationBuilder(EscapeEngineConfiguration prototype, EnvironmentConfigurationBuilder parent) {
super(prototype);
this.parent = parent;
}
示例15
public AndEscapeEngineConfigurationBuilder(EnvironmentConfigurationBuilder parent) {
this.parent = parent;
}
示例16
@Override
public EnvironmentConfigurationBuilder and() {
return parent;
}
示例17
public AndValueConfigurationBuilder(EnvironmentConfigurationBuilder environmentConfigurationBuilder) {
this.environmentConfigurationBuilder = environmentConfigurationBuilder;
}
示例18
public AndValueConfigurationBuilder(ValueConfiguration prototype, EnvironmentConfigurationBuilder environmentConfigurationBuilder) {
super(prototype);
this.environmentConfigurationBuilder = environmentConfigurationBuilder;
}
示例19
@Override
public EnvironmentConfigurationBuilder and() {
return environmentConfigurationBuilder;
}
示例20
public AndResourceConfigurationBuilder(EnvironmentConfigurationBuilder parent) {
this.parent = parent;
}
示例21
public AndResourceConfigurationBuilder(ResourceConfiguration prototype, EnvironmentConfigurationBuilder parent) {
super(prototype);
this.parent = parent;
}
示例22
@Override
public EnvironmentConfigurationBuilder and() {
return parent;
}
示例23
public AndJtwigParserConfigurationBuilder(EnvironmentConfigurationBuilder environmentConfigurationBuilder) {
super();
this.environmentConfigurationBuilder = environmentConfigurationBuilder;
}
示例24
public AndJtwigParserConfigurationBuilder(JtwigParserConfiguration prototype, EnvironmentConfigurationBuilder environmentConfigurationBuilder) {
super(prototype);
this.environmentConfigurationBuilder = environmentConfigurationBuilder;
}
示例25
@Override
public EnvironmentConfigurationBuilder and () {
return environmentConfigurationBuilder;
}
示例26
public AndPropertyResolverConfigurationBuilder(EnvironmentConfigurationBuilder parent) {
this.parent = parent;
}
示例27
public AndPropertyResolverConfigurationBuilder(PropertyResolverConfiguration prototype, EnvironmentConfigurationBuilder parent) {
super(prototype);
this.parent = parent;
}
示例28
@Override
public EnvironmentConfigurationBuilder and() {
return parent;
}
示例29
void configure (EnvironmentConfigurationBuilder configurationBuilder);