Search in sources :

Example 1 with MarkupTemplateEngine

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;
}
Also used : URLClassLoader(java.net.URLClassLoader) MarkupTemplateEngine(groovy.text.markup.MarkupTemplateEngine)

Example 2 with MarkupTemplateEngine

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));
}
Also used : Path(java.nio.file.Path) CachingTemplateResolver(ratpack.groovy.template.internal.CachingTemplateResolver) TemplateConfiguration(groovy.text.markup.TemplateConfiguration) MarkupTemplateEngine(groovy.text.markup.MarkupTemplateEngine) Singleton(javax.inject.Singleton) Provides(com.google.inject.Provides)

Example 3 with MarkupTemplateEngine

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();
}
Also used : MarkupTemplateEngine(groovy.text.markup.MarkupTemplateEngine) TemplateEngine(groovy.text.TemplateEngine) TemplateConfiguration(groovy.text.markup.TemplateConfiguration) MarkupTemplateEngine(groovy.text.markup.MarkupTemplateEngine) Test(org.junit.jupiter.api.Test)

Example 4 with MarkupTemplateEngine

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);
}
Also used : MarkupTemplateEngine(groovy.text.markup.MarkupTemplateEngine) TemplateEngine(groovy.text.TemplateEngine) TemplateConfiguration(groovy.text.markup.TemplateConfiguration) MarkupTemplateEngine(groovy.text.markup.MarkupTemplateEngine) Test(org.junit.jupiter.api.Test)

Example 5 with MarkupTemplateEngine

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");
}
Also used : StringWriter(java.io.StringWriter) HashMap(java.util.HashMap) GroovyMarkupConfig(org.springframework.web.servlet.view.groovy.GroovyMarkupConfig) MarkupTemplateEngine(groovy.text.markup.MarkupTemplateEngine) StringWriter(java.io.StringWriter) Writer(java.io.Writer) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.jupiter.api.Test)

Aggregations

MarkupTemplateEngine (groovy.text.markup.MarkupTemplateEngine)5 TemplateConfiguration (groovy.text.markup.TemplateConfiguration)3 Test (org.junit.jupiter.api.Test)3 TemplateEngine (groovy.text.TemplateEngine)2 Provides (com.google.inject.Provides)1 StringWriter (java.io.StringWriter)1 Writer (java.io.Writer)1 URLClassLoader (java.net.URLClassLoader)1 Path (java.nio.file.Path)1 HashMap (java.util.HashMap)1 Singleton (javax.inject.Singleton)1 ClassPathResource (org.springframework.core.io.ClassPathResource)1 GroovyMarkupConfig (org.springframework.web.servlet.view.groovy.GroovyMarkupConfig)1 CachingTemplateResolver (ratpack.groovy.template.internal.CachingTemplateResolver)1