use of io.vertx.ext.web.common.template.TemplateEngine in project vertx-web by vert-x3.
the class JadeTemplateTest method testTemplateHandlerOnFileSystem.
@Test
public void testTemplateHandlerOnFileSystem(TestContext should) {
TemplateEngine engine = JadeTemplateEngine.create(vertx);
final JsonObject context = new JsonObject().put("foo", "badger").put("bar", "fox");
context.put("context", new JsonObject().put("path", "/test-jade-template3.jade"));
engine.render(context, "src/test/filesystemtemplates/test-jade-template3.jade", should.asyncAssertSuccess(render -> {
should.assertEquals("<!DOCTYPE html><html><head><title>badger/test-jade-template3.jade</title></head><body></body></html>", normalizeCRLF(render.toString()));
}));
}
use of io.vertx.ext.web.common.template.TemplateEngine in project vertx-web by vert-x3.
the class JadeTemplateTest method testTemplateHandlerOnClasspath.
@Test
public void testTemplateHandlerOnClasspath(TestContext should) {
TemplateEngine engine = JadeTemplateEngine.create(vertx);
final JsonObject context = new JsonObject().put("foo", "badger").put("bar", "fox");
context.put("context", new JsonObject().put("path", "/test-jade-template2.jade"));
engine.render(context, "somedir/test-jade-template2.jade", should.asyncAssertSuccess(render -> {
should.assertEquals("<!DOCTYPE html><html><head><title>badger/test-jade-template2.jade</title></head><body></body></html>", normalizeCRLF(render.toString()));
}));
}
use of io.vertx.ext.web.common.template.TemplateEngine in project vertx-web by vert-x3.
the class JadeTemplateTest method testTemplateHandlerChangeExtension.
@Test
public void testTemplateHandlerChangeExtension(TestContext should) {
TemplateEngine engine = JadeTemplateEngine.create(vertx, "made");
final JsonObject context = new JsonObject().put("foo", "badger").put("bar", "fox");
context.put("context", new JsonObject().put("path", "/test-jade-template2.jade"));
engine.render(context, "somedir/test-jade-template2", should.asyncAssertSuccess(render -> {
should.assertEquals("<!DOCTYPE html><html><head><title>aardvark/test-jade-template2.jade</title></head><body></body></html>", normalizeCRLF(render.toString()));
}));
}
use of io.vertx.ext.web.common.template.TemplateEngine in project vertx-web by vert-x3.
the class TemplateHandlerImplTest method testSimpleTemplate.
@Test
public void testSimpleTemplate() {
TemplateEngine templateEngine = mock(TemplateEngine.class);
RoutingContext routingContext = mock(RoutingContext.class);
when(routingContext.normalizedPath()).thenReturn("/about");
Route currentRoute = mock(Route.class);
when(currentRoute.getPath()).thenReturn("/");
when(routingContext.currentRoute()).thenReturn(currentRoute);
TemplateHandler templateHandler = new TemplateHandlerImpl(templateEngine, "templates", "ext");
templateHandler.handle(routingContext);
verify(templateEngine).render(any(JsonObject.class), eq("templates/about"), any());
}
use of io.vertx.ext.web.common.template.TemplateEngine in project vertx-web by vert-x3.
the class TemplateHandlerImplTest method testTurnOffIndex.
@Test
public void testTurnOffIndex() {
TemplateEngine templateEngine = mock(TemplateEngine.class);
RoutingContext routingContext = mock(RoutingContext.class);
when(routingContext.normalizedPath()).thenReturn("/");
Route currentRoute = mock(Route.class);
when(currentRoute.getPath()).thenReturn("/");
when(routingContext.currentRoute()).thenReturn(currentRoute);
TemplateHandler templateHandler = new TemplateHandlerImpl(templateEngine, "templates", "ext");
templateHandler.setIndexTemplate(null);
templateHandler.handle(routingContext);
verify(templateEngine).render(any(JsonObject.class), eq("templates/"), any());
}
Aggregations