final PebbleTemplateEngine engine = PebbleTemplateEngine.create(vertx);
/** * Create a template engine using defaults * * @return the engine */ static io.vertx.ext.web.templ.pebble.PebbleTemplateEngine create(Vertx vertx) { return io.vertx.ext.web.templ.pebble.PebbleTemplateEngine.create(vertx); }
/** * Create a template engine using defaults * @param vertx * @return the engine */ public static io.vertx.rxjava.ext.web.templ.pebble.PebbleTemplateEngine create(io.vertx.rxjava.core.Vertx vertx) { io.vertx.rxjava.ext.web.templ.pebble.PebbleTemplateEngine ret = io.vertx.rxjava.ext.web.templ.pebble.PebbleTemplateEngine.newInstance(io.vertx.ext.web.templ.pebble.PebbleTemplateEngine.create(vertx.getDelegate())); return ret; }
/** * Create a template engine using defaults * @param vertx * @return the engine */ public static io.vertx.rxjava.ext.web.templ.pebble.PebbleTemplateEngine create(io.vertx.rxjava.core.Vertx vertx) { io.vertx.rxjava.ext.web.templ.pebble.PebbleTemplateEngine ret = io.vertx.rxjava.ext.web.templ.pebble.PebbleTemplateEngine.newInstance(io.vertx.ext.web.templ.pebble.PebbleTemplateEngine.create(vertx.getDelegate())); return ret; }
@Test public void testTemplateHandlerOnFileSystem(TestContext should) { final Async test = should.async(); TemplateEngine engine = PebbleTemplateEngine.create(vertx); final JsonObject context = new JsonObject() .put("foo", "badger") .put("bar", "fox") .put("context", new JsonObject().put("path", "/test-pebble-template3.peb")); engine.render(context, "src/test/filesystemtemplates/test-pebble-template3.peb", render -> { should.assertTrue(render.succeeded()); should.assertEquals("Hello badger and foxRequest path is /test-pebble-template3.peb", render.result().toString()); test.complete(); }); test.await(); }
@Test public void testTemplateComplex(TestContext should) { final Async test = should.async(); TemplateEngine engine = PebbleTemplateEngine.create(vertx); String expected = "Hello.Hi fox.\nHi badger!\nFooter - badger"; final JsonObject context = new JsonObject() .put("foo", "badger") .put("bar", "fox"); engine.render(context, "src/test/filesystemtemplates/test-pebble-complex.peb", render -> { should.assertTrue(render.succeeded()); should.assertEquals(expected, render.result().toString()); test.complete(); }); }
@Test public void testTemplateHandlerChangeExtension(TestContext should) { final Async test = should.async(); TemplateEngine engine = PebbleTemplateEngine.create(vertx).setExtension("beb"); final JsonObject context = new JsonObject() .put("foo", "badger") .put("bar", "fox") .put("context", new JsonObject().put("path", "/test-pebble-template2.peb")); engine.render(context, "somedir/test-pebble-template2", render -> { should.assertTrue(render.succeeded()); should.assertEquals("Cheerio badger and foxRequest path is /test-pebble-template2.peb", render.result().toString()); test.complete(); }); test.await(); }
@Test public void testTemplateHandlerOnClasspath(TestContext should) { final Async test = should.async(); TemplateEngine engine = PebbleTemplateEngine.create(vertx); final JsonObject context = new JsonObject() .put("foo", "badger") .put("bar", "fox") .put("context", new JsonObject().put("path", "/test-pebble-template2.peb")); engine.render(context, "somedir/test-pebble-template2.peb", render -> { should.assertTrue(render.succeeded()); should.assertEquals("Hello badger and foxRequest path is /test-pebble-template2.peb", render.result().toString()); test.complete(); }); test.await(); }
@Test public void testTemplateHandlerNoExtension(TestContext should) { final Async test = should.async(); TemplateEngine engine = PebbleTemplateEngine.create(vertx); final JsonObject context = new JsonObject() .put("foo", "badger") .put("bar", "fox") .put("context", new JsonObject().put("path", "/test-pebble-template2.peb")); engine.render(context, "somedir/test-pebble-template2", render -> { should.assertTrue(render.succeeded()); should.assertEquals("Hello badger and foxRequest path is /test-pebble-template2.peb", render.result().toString()); test.complete(); }); test.await(); }
@Test public void acceptLanguageHeaderShouldBeUsedWhenSet(TestContext should) { final Async test = should.async(); Locale.setDefault(Locale.US); final TemplateEngine engine = PebbleTemplateEngine.create(vertx); engine.render(new JsonObject().put("lang", "de-DE"), "src/test/filesystemtemplates/test-pebble-template-i18n.peb", render2 -> { should.assertTrue(render2.succeeded()); should.assertEquals("Hallo", render2.result().toString()); test.complete(); }); test.await(); } }
@Test public void noLocaleShouldUseDefaultLocale(TestContext should) { final Async test = should.async(); Locale.setDefault(Locale.US); final TemplateEngine engine = PebbleTemplateEngine.create(vertx); engine.render(new JsonObject(), "src/test/filesystemtemplates/test-pebble-template-i18n.peb", render2 -> { should.assertTrue(render2.succeeded()); should.assertEquals("Hi", render2.result().toString()); test.complete(); }); test.await(); }
TemplateEngine engine = PebbleTemplateEngine.create(vertx);
@Test public void testNoSuchTemplate(TestContext should) { final Async test = should.async(); TemplateEngine engine = PebbleTemplateEngine.create(vertx); final JsonObject context = new JsonObject(); engine.render(context, "non-existing", render -> { should.assertFalse(render.succeeded()); test.complete(); }); test.await(); }
TemplateEngine engine = PebbleTemplateEngine.create(vertx);
@Test public void customBuilderShouldRender(TestContext should) { final Async test = should.async(); final TemplateEngine engine = PebbleTemplateEngine.create(new PebbleEngine.Builder().extension(new TestExtension()).loader(new PebbleVertxLoader(vertx)).build()); final JsonObject context = new JsonObject() .put("foo", "badger") .put("bar", "fox") .put("context", new JsonObject().put("path", "/test-pebble-template5.peb")); engine.render(context, "src/test/filesystemtemplates/test-pebble-template5.peb", render -> { should.assertTrue(render.succeeded()); should.assertEquals("Hello badger and foxString is TESTRequest path is /test-pebble-template5.peb", render.result().toString()); test.complete(); }); }
@Test public void testTemplateBigAndComplex(TestContext should) { final Async test = should.async(); TemplateEngine engine = PebbleTemplateEngine.create(vertx);