Search in sources :

Example 11 with TemplateEngine

use of org.thymeleaf.TemplateEngine in project thymeleaf-tests by thymeleaf.

the class TemplateResolverAttributesTest method testTemplateResolutionAttributes02.

@Test
public void testTemplateResolutionAttributes02() throws Exception {
    final AttributeTesterTemplateResolver templateResolver = new AttributeTesterTemplateResolver(EXPECTED_ATTRIBUTES2);
    final TemplateEngine templateEngine = new TemplateEngine();
    templateEngine.setTemplateResolver(templateResolver);
    final TemplateSpec templateSpec = new TemplateSpec("temp", EXPECTED_ATTRIBUTES2);
    final String output = templateEngine.process(templateSpec, new Context());
    Assert.assertTrue(templateResolver.tempCalled);
    Assert.assertTrue(templateResolver.fragCalled);
    Assert.assertEquals(EXPECTED_OUTPUT, output);
}
Also used : Context(org.thymeleaf.context.Context) TemplateEngine(org.thymeleaf.TemplateEngine) TemplateSpec(org.thymeleaf.TemplateSpec) Test(org.junit.Test)

Example 12 with TemplateEngine

use of org.thymeleaf.TemplateEngine in project thymeleaf-tests by thymeleaf.

the class TestTemplateEngineConfigurationBuilder method build.

public static IEngineConfiguration build(final Set<IDialect> dialects) {
    final TemplateEngine templateEngine = new TemplateEngine();
    templateEngine.setDialects(dialects);
    return templateEngine.getConfiguration();
}
Also used : TemplateEngine(org.thymeleaf.TemplateEngine)

Example 13 with TemplateEngine

use of org.thymeleaf.TemplateEngine in project thymeleaf-tests by thymeleaf.

the class ExpressionBenchmark method main.

public static void main(String[] args) throws Exception {
    final Map<String, String> expressionsMap = ExpressionBenchmarkDefinitions.createExpressionsMap();
    final TemplateEngine templateEngine = new TemplateEngine();
    final IEngineConfiguration configuration = templateEngine.getConfiguration();
    final IExpressionContext processingContext = new ExpressionContext(configuration);
    final IStandardExpressionParser parser = new StandardExpressionParser();
    for (final Map.Entry<String, String> expressionEntry : expressionsMap.entrySet()) {
        final String expression = expressionEntry.getKey();
        final String expectedParsingResult = expressionEntry.getValue();
        final IStandardExpression parsedExpression = parser.parseExpression(processingContext, expression);
        Assert.assertNotNull(parsedExpression);
        final String exp = parsedExpression.getStringRepresentation();
        Assert.assertEquals(expectedParsingResult, exp);
    }
    final StopWatch sw = new StopWatch();
    sw.start();
    for (int x = 0; x < 1000; x++) for (final String expression : expressionsMap.keySet()) parser.parseExpression(processingContext, expression);
    sw.stop();
    System.out.println("First pass: " + sw.toString());
    sw.reset();
    sw.start();
    for (int x = 0; x < 1000; x++) for (final String expression : expressionsMap.keySet()) parser.parseExpression(processingContext, expression);
    sw.stop();
    System.out.println("Second pass: " + sw.toString());
}
Also used : IEngineConfiguration(org.thymeleaf.IEngineConfiguration) StopWatch(org.apache.commons.lang3.time.StopWatch) TemplateEngine(org.thymeleaf.TemplateEngine) IExpressionContext(org.thymeleaf.context.IExpressionContext) IExpressionContext(org.thymeleaf.context.IExpressionContext) ExpressionContext(org.thymeleaf.context.ExpressionContext) Map(java.util.Map)

Example 14 with TemplateEngine

use of org.thymeleaf.TemplateEngine in project jlineup by otto-de.

the class HTMLReportWriter method renderReport.

String renderReport(String template, List<ScreenshotComparisonResult> screenshotComparisonResults) throws FileNotFoundException {
    ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
    templateResolver.setTemplateMode("HTML");
    templateResolver.setPrefix("templates/");
    templateResolver.setSuffix(".html");
    TemplateEngine templateEngine = new TemplateEngine();
    templateEngine.setTemplateResolver(templateResolver);
    final Map<String, Object> variables = prepareVariablesForReportTemplate(screenshotComparisonResults);
    return templateEngine.process(template, new Context(Locale.US, variables));
}
Also used : Context(org.thymeleaf.context.Context) ClassLoaderTemplateResolver(org.thymeleaf.templateresolver.ClassLoaderTemplateResolver) TemplateEngine(org.thymeleaf.TemplateEngine)

Example 15 with TemplateEngine

use of org.thymeleaf.TemplateEngine in project nutzboot by nutzam.

the class MainLauncher method init.

public void init() {
    engine = new TemplateEngine();
    ServletContextTemplateResolver templateResolver = new ServletContextTemplateResolver(Mvcs.getServletContext());
    templateResolver.setTemplateMode(TemplateMode.TEXT);
    engine.setTemplateResolver(templateResolver);
    tmpDir = new File(conf.get("nutz.maker.tmpdir", "/tmp/maker")).getAbsoluteFile();
}
Also used : TemplateEngine(org.thymeleaf.TemplateEngine) ServletContextTemplateResolver(org.thymeleaf.templateresolver.ServletContextTemplateResolver) File(java.io.File)

Aggregations

TemplateEngine (org.thymeleaf.TemplateEngine)49 Context (org.thymeleaf.context.Context)28 Test (org.junit.Test)17 ClassLoaderTemplateResolver (org.thymeleaf.templateresolver.ClassLoaderTemplateResolver)13 MockServletContext (org.springframework.mock.web.MockServletContext)11 RequestContext (org.springframework.web.servlet.support.RequestContext)10 Test (org.junit.jupiter.api.Test)7 WebContext (org.thymeleaf.context.WebContext)7 SpringTemplateEngine (org.thymeleaf.spring5.SpringTemplateEngine)6 SpringTemplateEngine (org.thymeleaf.spring6.SpringTemplateEngine)6 ServletContext (jakarta.servlet.ServletContext)5 Matchers.containsString (org.hamcrest.Matchers.containsString)5 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)5 AnnotationConfigWebApplicationContext (org.springframework.web.context.support.AnnotationConfigWebApplicationContext)5 StringTemplateResolver (org.thymeleaf.templateresolver.StringTemplateResolver)5 ServletContextTemplateResolver (org.thymeleaf.templateresolver.ServletContextTemplateResolver)4 IEngineConfiguration (org.thymeleaf.IEngineConfiguration)3 TemplateSpec (org.thymeleaf.TemplateSpec)3 Provides (com.google.inject.Provides)2 Singleton (com.google.inject.Singleton)2