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);
}
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();
}
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());
}
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));
}
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();
}
Aggregations