Search in sources :

Example 1 with IResourceResolver

use of org.thymeleaf.resourceresolver.IResourceResolver 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 IResourceResolver

use of org.thymeleaf.resourceresolver.IResourceResolver in project thymeleaf-tests by thymeleaf.

the class TestTemplateResolver method resolveTemplate.

public TemplateResolution resolveTemplate(final TemplateProcessingParameters templateProcessingParameters) {
    final String templateName = templateProcessingParameters.getTemplateName();
    final int placeholderPos = this.template.indexOf("{%%}");
    final String result = this.template.substring(0, placeholderPos) + templateName + this.template.substring(placeholderPos + 4);
    final IResourceResolver resourceResolver = new TestResourceResolver(result);
    final TemplateResolution templateResolution = new TemplateResolution(templateName, "TEST", resourceResolver, "UTF-8", "HTML5", new NonCacheableCacheEntryValidity());
    return templateResolution;
}
Also used : IResourceResolver(org.thymeleaf.resourceresolver.IResourceResolver) TemplateResolution(org.thymeleaf.templateresolver.TemplateResolution) NonCacheableCacheEntryValidity(org.thymeleaf.cache.NonCacheableCacheEntryValidity)

Example 3 with IResourceResolver

use of org.thymeleaf.resourceresolver.IResourceResolver in project thymeleaf-tests by thymeleaf.

the class SpringResourceTemplateResolverSpring3Test method testResolveTemplate.

@Test
public void testResolveTemplate() throws Exception {
    final String templateLocation = "spring321/view/test.html";
    final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:spring321/view/applicationContext.xml");
    final SpringResourceTemplateResolver resolver = (SpringResourceTemplateResolver) context.getBean("springResourceTemplateResolver");
    resolver.initialize();
    final String templateMode = resolver.getTemplateMode();
    Assert.assertEquals("HTML5", templateMode);
    final TemplateProcessingParameters parameters = new TemplateProcessingParameters(new Configuration(), "classpath:" + templateLocation, new Context());
    final TemplateResolution resolution = resolver.resolveTemplate(parameters);
    final IResourceResolver resourceResolver = resolution.getResourceResolver();
    final InputStream is = resourceResolver.getResourceAsStream(parameters, resolution.getResourceName());
    final String testResource = ResourceUtils.normalize(ResourceUtils.read(is, "US-ASCII"));
    final String expected = ResourceUtils.read(ClassLoaderUtils.getClassLoader(SpringResourceTemplateResolverSpring3Test.class).getResourceAsStream(templateLocation), "US-ASCII", true);
    Assert.assertEquals(expected, testResource);
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Context(org.thymeleaf.context.Context) IResourceResolver(org.thymeleaf.resourceresolver.IResourceResolver) TemplateProcessingParameters(org.thymeleaf.TemplateProcessingParameters) Configuration(org.thymeleaf.Configuration) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) TemplateResolution(org.thymeleaf.templateresolver.TemplateResolution) InputStream(java.io.InputStream) Test(org.junit.Test)

Example 4 with IResourceResolver

use of org.thymeleaf.resourceresolver.IResourceResolver in project thymeleaf-tests by thymeleaf.

the class SpringResourceTemplateResolverSpring4Test method testResolveTemplate.

@Test
public void testResolveTemplate() throws Exception {
    final String templateLocation = "spring421/view/test.html";
    final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:spring421/view/applicationContext.xml");
    final SpringResourceTemplateResolver resolver = (SpringResourceTemplateResolver) context.getBean("springResourceTemplateResolver");
    resolver.initialize();
    final String templateMode = resolver.getTemplateMode();
    Assert.assertEquals("HTML5", templateMode);
    final TemplateProcessingParameters parameters = new TemplateProcessingParameters(new Configuration(), "classpath:" + templateLocation, new Context());
    final TemplateResolution resolution = resolver.resolveTemplate(parameters);
    final IResourceResolver resourceResolver = resolution.getResourceResolver();
    final InputStream is = resourceResolver.getResourceAsStream(parameters, resolution.getResourceName());
    final String testResource = ResourceUtils.normalize(ResourceUtils.read(is, "US-ASCII"));
    final String expected = ResourceUtils.read(ClassLoaderUtils.getClassLoader(SpringResourceTemplateResolverSpring4Test.class).getResourceAsStream(templateLocation), "US-ASCII", true);
    Assert.assertEquals(expected, testResource);
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Context(org.thymeleaf.context.Context) IResourceResolver(org.thymeleaf.resourceresolver.IResourceResolver) TemplateProcessingParameters(org.thymeleaf.TemplateProcessingParameters) Configuration(org.thymeleaf.Configuration) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) TemplateResolution(org.thymeleaf.templateresolver.TemplateResolution) InputStream(java.io.InputStream) Test(org.junit.Test)

Aggregations

IResourceResolver (org.thymeleaf.resourceresolver.IResourceResolver)4 TemplateResolution (org.thymeleaf.templateresolver.TemplateResolution)3 InputStream (java.io.InputStream)2 Test (org.junit.Test)2 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)2 Configuration (org.thymeleaf.Configuration)2 TemplateProcessingParameters (org.thymeleaf.TemplateProcessingParameters)2 Context (org.thymeleaf.context.Context)2 Provides (com.google.inject.Provides)1 Singleton (com.google.inject.Singleton)1 NonCacheableCacheEntryValidity (org.thymeleaf.cache.NonCacheableCacheEntryValidity)1 ITemplateResolver (org.thymeleaf.templateresolver.ITemplateResolver)1 TemplateResolver (org.thymeleaf.templateresolver.TemplateResolver)1 FileSystemBindingThymeleafResourceResolver (ratpack.thymeleaf.internal.FileSystemBindingThymeleafResourceResolver)1