Java源码示例:io.vertx.ext.web.templ.jade.JadeTemplateEngine

示例1
private TemplateEngine createTemplateEngine(String templateType) {
    Vertx vertx;
    try {
        vertx = beanFactory.getBean(Vertx.class);
    } catch (BeansException e) {
        throw new IllegalStateException(e);
    }

    TemplateEngine templateEngine;
    if ("freemarker".equals(templateType)) {
        templateEngine = FreeMarkerTemplateEngine.create(vertx);
        return templateEngine;
    }

    if ("jade".equals(templateType)) {
        templateEngine = JadeTemplateEngine.create(vertx);
        return templateEngine;
    }

    if ("thymeleaf".equals(templateType)) {
        templateEngine = ThymeleafTemplateEngine.create(vertx);
        return templateEngine;
    }

    throw new IllegalStateException(String.format("unsupported type of template %s!", templateType));
}
 
示例2
@Test
public void testTemplateHandlerOnClasspath(TestContext should) {
  final Async test = should.async();
  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", render -> {
    should.assertTrue(render.succeeded());
    should.assertEquals("<!DOCTYPE html><html><head><title>badger/test-jade-template2.jade</title></head><body></body></html>", render.result().toString());
    test.complete();
  });
  test.await();
}
 
示例3
@Test
public void testTemplateHandlerOnFileSystem(TestContext should) {
  final Async test = should.async();
  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", render -> {
    should.assertTrue(render.succeeded());
    should.assertEquals("<!DOCTYPE html><html><head><title>badger/test-jade-template3.jade</title></head><body></body></html>", render.result().toString());
    test.complete();
  });
  test.await();
}
 
示例4
@Test
public void testTemplateHandlerNoExtension(TestContext should) {
  final Async test = should.async();
  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", render -> {
    should.assertTrue(render.succeeded());
    should.assertEquals("<!DOCTYPE html><html><head><title>badger/test-jade-template2.jade</title></head><body></body></html>", render.result().toString());
    test.complete();
  });
  test.await();
}
 
示例5
@Test
public void testTemplateHandlerChangeExtension(TestContext should) {
  final Async test = should.async();
  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", render -> {
    should.assertTrue(render.succeeded());
    should.assertEquals("<!DOCTYPE html><html><head><title>aardvark/test-jade-template2.jade</title></head><body></body></html>", render.result().toString());
    test.complete();
  });
  test.await();
}
 
示例6
@Test
public void testNoSuchTemplate(TestContext should) {
  final Async test = should.async();
  TemplateEngine engine = JadeTemplateEngine.create(vertx, "made");

  final JsonObject context = new JsonObject();

  engine.render(context, "somedir/foo", render -> {
    should.assertFalse(render.succeeded());
    test.complete();
  });
  test.await();
}
 
示例7
@Test
public void testGetJadeConfiguration() {
  JadeTemplateEngine engine = JadeTemplateEngine.create(vertx);
  assertNotNull(engine.getJadeConfiguration());
}