Search in sources :

Example 1 with ITemplateResolver

use of org.thymeleaf.templateresolver.ITemplateResolver in project ratpack by ratpack.

the class ThymeleafModule method provideTemplateResolver.

@Provides
@Singleton
ITemplateResolver provideTemplateResolver(ServerConfig serverConfig, Config config) {
    IResourceResolver resourceResolver = new FileSystemBindingThymeleafResourceResolver(serverConfig.getBaseDir());
    TemplateResolver templateResolver = new TemplateResolver();
    templateResolver.setResourceResolver(resourceResolver);
    templateResolver.setTemplateMode(getTemplatesModeSetting(config));
    templateResolver.setPrefix(getTemplatesPrefixSetting(config));
    templateResolver.setSuffix(getTemplatesSuffixSetting(config));
    templateResolver.setCacheable(getCacheSizeSetting(config) > 0);
    // Never use TTL expiration
    templateResolver.setCacheTTLMs(null);
    return templateResolver;
}
Also used : IResourceResolver(org.thymeleaf.resourceresolver.IResourceResolver) FileSystemBindingThymeleafResourceResolver(ratpack.thymeleaf.internal.FileSystemBindingThymeleafResourceResolver) TemplateResolver(org.thymeleaf.templateresolver.TemplateResolver) ITemplateResolver(org.thymeleaf.templateresolver.ITemplateResolver) Singleton(com.google.inject.Singleton) Provides(com.google.inject.Provides)

Example 2 with ITemplateResolver

use of org.thymeleaf.templateresolver.ITemplateResolver in project spring-boot by spring-projects.

the class ThymeleafAutoConfigurationTests method overrideTemplateResolverOrder.

@Test
public void overrideTemplateResolverOrder() throws Exception {
    EnvironmentTestUtils.addEnvironment(this.context, "spring.thymeleaf.templateResolverOrder:25");
    this.context.register(ThymeleafAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class);
    this.context.refresh();
    ITemplateResolver resolver = this.context.getBean(ITemplateResolver.class);
    assertThat(resolver.getOrder()).isEqualTo(Integer.valueOf(25));
}
Also used : ITemplateResolver(org.thymeleaf.templateresolver.ITemplateResolver) Test(org.junit.Test)

Example 3 with ITemplateResolver

use of org.thymeleaf.templateresolver.ITemplateResolver in project spring-boot by spring-projects.

the class ThymeleafAutoConfigurationTests method overrideCharacterEncoding.

@Test
public void overrideCharacterEncoding() throws Exception {
    EnvironmentTestUtils.addEnvironment(this.context, "spring.thymeleaf.encoding:UTF-16");
    this.context.register(ThymeleafAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class);
    this.context.refresh();
    ITemplateResolver resolver = this.context.getBean(ITemplateResolver.class);
    assertThat(resolver instanceof SpringResourceTemplateResolver).isTrue();
    assertThat(((SpringResourceTemplateResolver) resolver).getCharacterEncoding()).isEqualTo("UTF-16");
    ThymeleafViewResolver views = this.context.getBean(ThymeleafViewResolver.class);
    assertThat(views.getCharacterEncoding()).isEqualTo("UTF-16");
    assertThat(views.getContentType()).isEqualTo("text/html;charset=UTF-16");
}
Also used : SpringResourceTemplateResolver(org.thymeleaf.spring5.templateresolver.SpringResourceTemplateResolver) ITemplateResolver(org.thymeleaf.templateresolver.ITemplateResolver) ThymeleafViewResolver(org.thymeleaf.spring5.view.ThymeleafViewResolver) Test(org.junit.Test)

Example 4 with ITemplateResolver

use of org.thymeleaf.templateresolver.ITemplateResolver in project sling by apache.

the class ThymeleafScriptEngineFactory method setupTemplateEngine.

private void setupTemplateEngine() {
    logger.info("setting up new template engine");
    templateEngine = null;
    if (configuration == null) {
        logger.info("configuration is null, not setting up new template engine");
        return;
    }
    if (!configuration.useStandardEngineContextFactory() && engineContextFactory == null) {
        logger.info("no engine context factory available, not setting up new template engine");
        return;
    }
    // setup template engine
    final TemplateEngine templateEngine = new TemplateEngine();
    // Template Resolvers
    if (this.templateResolvers != null) {
        final Set<ITemplateResolver> templateResolvers = new HashSet<>(this.templateResolvers);
        templateEngine.setTemplateResolvers(templateResolvers);
    }
    // Message Resolvers
    if (this.messageResolvers != null) {
        final Set<IMessageResolver> messageResolvers = new HashSet<>(this.messageResolvers);
        templateEngine.setMessageResolvers(messageResolvers);
    }
    if (configuration.useStandardMessageResolver()) {
        final IMessageResolver standardMessageResolver = new StandardMessageResolver();
        templateEngine.addMessageResolver(standardMessageResolver);
    }
    // Link Builders
    if (this.linkBuilders != null) {
        final Set<ILinkBuilder> linkBuilders = new HashSet<>(this.linkBuilders);
        templateEngine.setLinkBuilders(linkBuilders);
    }
    if (configuration.useStandardLinkBuilder()) {
        final ILinkBuilder standardLinkBuilder = new StandardLinkBuilder();
        templateEngine.addLinkBuilder(standardLinkBuilder);
    }
    // Dialects
    if (this.dialects != null) {
        final Set<IDialect> dialects = new HashSet<>(this.dialects);
        templateEngine.setDialects(dialects);
    }
    if (configuration.useStandardDialect()) {
        final IDialect standardDialect = new StandardDialect();
        templateEngine.addDialect(standardDialect);
    }
    // Decoupled Template Logic Resolver
    if (!configuration.useStandardDecoupledTemplateLogicResolver()) {
        templateEngine.setDecoupledTemplateLogicResolver(decoupledTemplateLogicResolver);
    }
    // Cache Manager
    if (!configuration.useStandardCacheManager()) {
        templateEngine.setCacheManager(cacheManager);
    }
    // Engine Context Factory
    if (!configuration.useStandardEngineContextFactory()) {
        templateEngine.setEngineContextFactory(engineContextFactory);
    }
    //
    this.templateEngine = templateEngine;
}
Also used : StandardLinkBuilder(org.thymeleaf.linkbuilder.StandardLinkBuilder) ITemplateResolver(org.thymeleaf.templateresolver.ITemplateResolver) IDialect(org.thymeleaf.dialect.IDialect) StandardMessageResolver(org.thymeleaf.messageresolver.StandardMessageResolver) ITemplateEngine(org.thymeleaf.ITemplateEngine) TemplateEngine(org.thymeleaf.TemplateEngine) IMessageResolver(org.thymeleaf.messageresolver.IMessageResolver) ILinkBuilder(org.thymeleaf.linkbuilder.ILinkBuilder) StandardDialect(org.thymeleaf.standard.StandardDialect) HashSet(java.util.HashSet)

Aggregations

ITemplateResolver (org.thymeleaf.templateresolver.ITemplateResolver)4 Test (org.junit.Test)2 Provides (com.google.inject.Provides)1 Singleton (com.google.inject.Singleton)1 HashSet (java.util.HashSet)1 ITemplateEngine (org.thymeleaf.ITemplateEngine)1 TemplateEngine (org.thymeleaf.TemplateEngine)1 IDialect (org.thymeleaf.dialect.IDialect)1 ILinkBuilder (org.thymeleaf.linkbuilder.ILinkBuilder)1 StandardLinkBuilder (org.thymeleaf.linkbuilder.StandardLinkBuilder)1 IMessageResolver (org.thymeleaf.messageresolver.IMessageResolver)1 StandardMessageResolver (org.thymeleaf.messageresolver.StandardMessageResolver)1 IResourceResolver (org.thymeleaf.resourceresolver.IResourceResolver)1 SpringResourceTemplateResolver (org.thymeleaf.spring5.templateresolver.SpringResourceTemplateResolver)1 ThymeleafViewResolver (org.thymeleaf.spring5.view.ThymeleafViewResolver)1 StandardDialect (org.thymeleaf.standard.StandardDialect)1 TemplateResolver (org.thymeleaf.templateresolver.TemplateResolver)1 FileSystemBindingThymeleafResourceResolver (ratpack.thymeleaf.internal.FileSystemBindingThymeleafResourceResolver)1