use of org.thymeleaf.TemplateEngine in project thymeleaf-tests by thymeleaf.
the class ContextSequenceTest method testContextSequenceNoSpring.
public void testContextSequenceNoSpring() throws Exception {
final TemplateEngine templateEngine = new TemplateEngine();
templateEngine.setTemplateResolver(new ClassLoaderTemplateResolver());
final Context ctx1 = new Context();
ctx1.setVariable("myObject", new MyObjectClass("one"));
final Context ctx2 = new Context();
ctx2.setVariable("myObject", new MyObjectClass("two"));
final String result1 = ResourceUtils.normalize(templateEngine.process("context/contextSequence.html", ctx1));
final String result2 = ResourceUtils.normalize(templateEngine.process("context/contextSequence.html", ctx2));
final String expected1 = ResourceUtils.read(ClassLoaderUtils.getClassLoader(ContextSequenceTest.class).getResourceAsStream("context/contextSequence-result1.html"), "UTF-8", true);
final String expected2 = ResourceUtils.read(ClassLoaderUtils.getClassLoader(ContextSequenceTest.class).getResourceAsStream("context/contextSequence-result2.html"), "UTF-8", true);
Assert.assertEquals(expected1, result1);
Assert.assertEquals(expected2, result2);
}
use of org.thymeleaf.TemplateEngine in project spring-boot by spring-projects.
the class ThymeleafServletAutoConfigurationTests method createFromConfigClass.
@Test
void createFromConfigClass() {
this.contextRunner.withPropertyValues("spring.thymeleaf.mode:HTML", "spring.thymeleaf.suffix:").run((context) -> {
assertThat(context).hasSingleBean(TemplateEngine.class);
TemplateEngine engine = context.getBean(TemplateEngine.class);
Context attrs = new Context(Locale.UK, Collections.singletonMap("foo", "bar"));
String result = engine.process("template.html", attrs).trim();
assertThat(result).isEqualTo("<html>bar</html>");
});
}
use of org.thymeleaf.TemplateEngine in project spring-boot by spring-projects.
the class ThymeleafServletAutoConfigurationTests method useDataDialect.
@Test
void useDataDialect() {
this.contextRunner.run((context) -> {
TemplateEngine engine = context.getBean(TemplateEngine.class);
Context attrs = new Context(Locale.UK, Collections.singletonMap("foo", "bar"));
String result = engine.process("data-dialect", attrs).trim();
assertThat(result).isEqualTo("<html><body data-foo=\"bar\"></body></html>");
});
}
use of org.thymeleaf.TemplateEngine in project spring-boot by spring-projects.
the class ThymeleafServletAutoConfigurationTests method renderTemplate.
@Test
void renderTemplate() {
this.contextRunner.run((context) -> {
TemplateEngine engine = context.getBean(TemplateEngine.class);
Context attrs = new Context(Locale.UK, Collections.singletonMap("foo", "bar"));
String result = engine.process("home", attrs).trim();
assertThat(result).isEqualTo("<html><body>bar</body></html>");
});
}
use of org.thymeleaf.TemplateEngine in project contribution by checkstyle.
the class SiteGenerator method generate.
/**
* Generates site report using thymeleaf template engine.
*
* @param diffReport
* container with parsed data.
* @param diffConfiguration
* merged configurations from both reports.
* @param paths
* CLI paths.
* @throws IOException
* on failure to write site to disc.
*/
public static void generate(DiffReport diffReport, MergedConfigurationModule diffConfiguration, CliPaths paths) throws IOException {
// setup thymeleaf engine
final TemplateEngine tplEngine = getTemplateEngine();
// setup xreference generator
final XrefGenerator xrefGenerator = new XrefGenerator(paths.getRefFilesPath(), paths.getOutputPath().resolve(Main.XREF_FILEPATH), paths.getOutputPath());
// html generation
final Path sitepath = paths.getOutputPath().resolve(SITEPATH);
final FileWriter writer = new FileWriter(sitepath.toString());
try {
// write statistics
generateHeader(tplEngine, writer, diffReport.getStatistics(), diffConfiguration);
// write parsed content
generateBody(tplEngine, writer, diffReport, paths, xrefGenerator);
// write html footer
tplEngine.process("footer", new Context(), writer);
} finally {
writer.close();
}
}
Aggregations