use of io.vertx.ext.web.common.template.TemplateEngine in project vertx-web by vert-x3.
the class ThymeleafTemplateTest method testTemplateHandlerOnClasspath.
@Test
public void testTemplateHandlerOnClasspath(TestContext should) {
TemplateEngine engine = ThymeleafTemplateEngine.create(vertx);
final JsonObject context = new JsonObject().put("foo", "badger").put("bar", "fox").put("context", new JsonObject().put("path", "/test-thymeleaf-template2.html"));
engine.render(context, "somedir/test-thymeleaf-template2.html", should.asyncAssertSuccess(render -> {
final String expected = "<!doctype html>\n" + "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" + "<head>\n" + " <meta charset=\"utf-8\">\n" + "</head>\n" + "<body>\n" + "<p>badger</p>\n" + "<p>fox</p>\n" + "<p>/test-thymeleaf-template2.html</p>\n" + "</body>\n" + "</html>\n";
should.assertEquals(expected, normalizeCRLF(render.toString()));
}));
}
use of io.vertx.ext.web.common.template.TemplateEngine in project vertx-web by vert-x3.
the class PebbleTemplateNoCacheTest method testCachingDisabled.
@Test
public void testCachingDisabled(TestContext should) throws IOException {
System.setProperty("vertxweb.environment", "development");
TemplateEngine engine = PebbleTemplateEngine.create(vertx);
File temp = File.createTempFile("template", ".peb", new File("target/classes"));
temp.deleteOnExit();
try (PrintWriter out = new PrintWriter(temp)) {
out.print("before");
out.flush();
}
engine.render(new JsonObject(), temp.getParent() + "/" + temp.getName(), should.asyncAssertSuccess(render -> {
should.assertEquals("before", PebbleTemplateTest.normalizeCRLF(render.toString()));
try (PrintWriter out2 = new PrintWriter(temp)) {
out2.print("after");
out2.flush();
} catch (IOException e) {
should.fail(e);
}
engine.render(new JsonObject(), temp.getParent() + "/" + temp.getName(), should.asyncAssertSuccess(render2 -> {
should.assertEquals("after", PebbleTemplateTest.normalizeCRLF(render2.toString()));
}));
}));
}
use of io.vertx.ext.web.common.template.TemplateEngine in project vertx-web by vert-x3.
the class JadeTemplateTest method testCachingEnabled.
@Test
public void testCachingEnabled(TestContext should) throws IOException {
System.setProperty("vertxweb.environment", "production");
TemplateEngine engine = JadeTemplateEngine.create(vertx);
File temp = File.createTempFile("template", ".jade", new File("target/classes"));
temp.deleteOnExit();
try (PrintWriter out = new PrintWriter(temp)) {
out.print("before");
out.flush();
}
engine.render(new JsonObject(), temp.getParent() + "/" + temp.getName(), should.asyncAssertSuccess(render -> {
should.assertEquals("<before></before>", normalizeCRLF(render.toString()));
try (PrintWriter out2 = new PrintWriter(temp)) {
out2.print("after");
out2.flush();
} catch (IOException e) {
should.fail(e);
}
engine.render(new JsonObject(), temp.getParent() + "/" + temp.getName(), should.asyncAssertSuccess(render2 -> {
should.assertEquals("<before></before>", normalizeCRLF(render2.toString()));
}));
}));
}
use of io.vertx.ext.web.common.template.TemplateEngine in project vertx-web by vert-x3.
the class JadeTemplateTest method testNoSuchTemplate.
@Test
public void testNoSuchTemplate(TestContext should) {
TemplateEngine engine = JadeTemplateEngine.create(vertx, "made");
final JsonObject context = new JsonObject();
engine.render(context, "somedir/foo", should.asyncAssertFailure());
}
use of io.vertx.ext.web.common.template.TemplateEngine in project vertx-web by vert-x3.
the class RockerTemplateEngineTest method testTemplateWithUndrescoreKeysHandler.
@Test
public void testTemplateWithUndrescoreKeysHandler(TestContext should) {
TemplateEngine engine = RockerTemplateEngine.create();
final JsonObject context = new JsonObject().put("foo", "badger").put("bar", "fox").put("context", new JsonObject().put("path", "/TestRockerTemplate2.rocker.html")).put("__body-handled", true);
engine.render(context, "somedir/TestRockerTemplate2.rocker.html", should.asyncAssertSuccess(render -> {
should.assertEquals("Hello badger and fox\nRequest path is /TestRockerTemplate2.rocker.html\n", normalizeCRLF(render.toString()));
}));
}
Aggregations