use of org.thymeleaf.spring6.SpringTemplateEngine in project thymeleaf-tests by thymeleaf.
the class LinkBuilderTest method testLinkBuilderSpring01.
@Test
public void testLinkBuilderSpring01() throws Exception {
final Context ctx = new Context();
ctx.setVariable("one", "This is one");
final TemplateEngine templateEngine = new SpringTemplateEngine();
templateEngine.setTemplateResolver(new StringTemplateResolver());
templateEngine.setLinkBuilder(new TestLinkBuilder());
final String result = templateEngine.process("<a th:href='@{/something}'>", ctx);
final String expected = "<a href='[/fromthebuilder/something]'>";
Assert.assertEquals(expected, result);
}
use of org.thymeleaf.spring6.SpringTemplateEngine in project thymeleaf-tests by thymeleaf.
the class TemplateEngineTest method testDefaultTemplateResolver06.
@Test
public void testDefaultTemplateResolver06() {
final TemplateEngine templateEngine = new SpringTemplateEngine();
final Context context = new Context();
context.setLocale(Locale.ENGLISH);
context.setVariable("one", "this value");
final StringTemplateResolver stringTemplateResolver = new StringTemplateResolver();
stringTemplateResolver.setResolvablePatterns(Collections.singleton("<div*"));
templateEngine.addTemplateResolver(stringTemplateResolver);
final DefaultTemplateResolver defaultTemplateResolver = new DefaultTemplateResolver();
defaultTemplateResolver.setTemplate("<p>inserted!</p>");
templateEngine.addTemplateResolver(defaultTemplateResolver);
templateEngine.initialize();
Assert.assertEquals("<div>some text <p><p>inserted!</p></p> other text</div>", templateEngine.process("<div>some text <p th:insert=\"nonexisting\">...</p> other text</div>", context));
}
use of org.thymeleaf.spring6.SpringTemplateEngine in project thymeleaf-tests by thymeleaf.
the class TemplateEngineTest method testTemplateResolverConfiguration02.
@Test
public void testTemplateResolverConfiguration02() {
final TemplateEngine templateEngine = new SpringTemplateEngine();
templateEngine.initialize();
final List<ITemplateResolver> templateResolvers = new ArrayList<ITemplateResolver>(templateEngine.getTemplateResolvers());
Assert.assertEquals(1, templateResolvers.size());
Assert.assertEquals("org.thymeleaf.templateresolver.StringTemplateResolver", templateResolvers.get(0).getName());
}
use of org.thymeleaf.spring6.SpringTemplateEngine in project thymeleaf-tests by thymeleaf.
the class TemplateEngineTest method testTemplateResolverConfiguration10.
@Test
public void testTemplateResolverConfiguration10() {
final TemplateEngine templateEngine = new SpringTemplateEngine();
final Set<ITemplateResolver> resolvers = new LinkedHashSet<ITemplateResolver>();
resolvers.add(new ClassLoaderTemplateResolver());
resolvers.add(new FileTemplateResolver());
templateEngine.setTemplateResolvers(resolvers);
templateEngine.initialize();
final List<ITemplateResolver> templateResolvers = new ArrayList<ITemplateResolver>(templateEngine.getTemplateResolvers());
Assert.assertEquals(2, templateResolvers.size());
Assert.assertEquals("org.thymeleaf.templateresolver.ClassLoaderTemplateResolver", templateResolvers.get(0).getName());
Assert.assertEquals("org.thymeleaf.templateresolver.FileTemplateResolver", templateResolvers.get(1).getName());
}
use of org.thymeleaf.spring6.SpringTemplateEngine in project Flare-event-calendar by PollubCafe.
the class ThymeleafConfig method springTemplateEngine.
@Bean
public SpringTemplateEngine springTemplateEngine() {
SpringTemplateEngine templateEngine = new SpringTemplateEngine();
templateEngine.addTemplateResolver(htmlTemplateResolver());
return templateEngine;
}
Aggregations