use of groovy.text.markup.MarkupTemplateEngine in project spring-framework by spring-projects.
the class GroovyMarkupConfigurer method createTemplateEngine.
protected MarkupTemplateEngine createTemplateEngine() throws IOException {
if (this.templateEngine == null) {
ClassLoader templateClassLoader = createTemplateClassLoader();
this.templateEngine = new MarkupTemplateEngine(templateClassLoader, this, new LocaleTemplateResolver());
}
return this.templateEngine;
}
use of groovy.text.markup.MarkupTemplateEngine in project ratpack by ratpack.
the class MarkupTemplateModule method provideTemplateEngine.
@SuppressWarnings("UnusedDeclaration")
@Provides
@Singleton
MarkupTemplateEngine provideTemplateEngine(ServerConfig serverConfig, Config config) {
ClassLoader parent = Thread.currentThread().getContextClassLoader();
TemplateConfiguration effectiveConfiguration = new TemplateConfiguration(config);
// not copied by constructor
effectiveConfiguration.setCacheTemplates(config.isCacheTemplates());
Path templatesDir = serverConfig.getBaseDir().file(config.getTemplatesDirectory());
return new MarkupTemplateEngine(parent, effectiveConfiguration, new CachingTemplateResolver(templatesDir));
}
use of groovy.text.markup.MarkupTemplateEngine in project spring-framework by spring-projects.
the class GroovyMarkupConfigurerTests method customTemplateConfiguration.
@Test
public void customTemplateConfiguration() throws Exception {
this.configurer.setApplicationContext(this.applicationContext);
this.configurer.setCacheTemplates(false);
this.configurer.afterPropertiesSet();
TemplateEngine engine = this.configurer.getTemplateEngine();
assertThat(engine).isNotNull();
assertThat(engine.getClass()).isEqualTo(MarkupTemplateEngine.class);
MarkupTemplateEngine markupEngine = (MarkupTemplateEngine) engine;
TemplateConfiguration configuration = markupEngine.getTemplateConfiguration();
assertThat(configuration).isNotNull();
assertThat(configuration.isCacheTemplates()).isFalse();
}
use of groovy.text.markup.MarkupTemplateEngine in project spring-framework by spring-projects.
the class GroovyMarkupConfigurerTests method defaultTemplateEngine.
@Test
public void defaultTemplateEngine() throws Exception {
this.configurer.setApplicationContext(this.applicationContext);
this.configurer.afterPropertiesSet();
TemplateEngine engine = this.configurer.getTemplateEngine();
assertThat(engine).isNotNull();
assertThat(engine.getClass()).isEqualTo(MarkupTemplateEngine.class);
MarkupTemplateEngine markupEngine = (MarkupTemplateEngine) engine;
TemplateConfiguration configuration = markupEngine.getTemplateConfiguration();
assertThat(configuration).isNotNull();
assertThat(configuration.getClass()).isEqualTo(GroovyMarkupConfigurer.class);
}
use of groovy.text.markup.MarkupTemplateEngine in project spring-boot by spring-projects.
the class GroovyTemplateAutoConfigurationTests method renderTemplate.
@Test
void renderTemplate() throws Exception {
registerAndRefreshContext();
GroovyMarkupConfig config = this.context.getBean(GroovyMarkupConfig.class);
MarkupTemplateEngine engine = config.getTemplateEngine();
Writer writer = new StringWriter();
engine.createTemplate(new ClassPathResource("templates/message.tpl").getFile()).make(new HashMap<String, Object>(Collections.singletonMap("greeting", "Hello World"))).writeTo(writer);
assertThat(writer.toString()).contains("Hello World");
}
Aggregations