本文整理汇总了Java中io.vertx.ext.web.templ.TemplateEngine类的典型用法代码示例。如果您正苦于以下问题:Java TemplateEngine类的具体用法?Java TemplateEngine怎么用?Java TemplateEngine使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TemplateEngine类属于io.vertx.ext.web.templ包,在下文中一共展示了TemplateEngine类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handle
import io.vertx.ext.web.templ.TemplateEngine; //导入依赖的package包/类
@Override
public void handle(RoutingContext context) {
String tplName = normalize(config.getTplDir()) + ViewResolver.getViewName(context);
TemplateEngine engine = fromViewName(tplName);
if (engine == null) {
LOG.error("No template handler found for " + tplName);
context.fail(500);
return;
}
engine.render(context, tplName, res -> {
if (res.succeeded()) {
context.response().putHeader(CONTENT_TYPE, "text/html").end(res.result());
} else {
context.fail(res.cause());
}
});
}
示例2: testDefaultIndex
import io.vertx.ext.web.templ.TemplateEngine; //导入依赖的package包/类
@Test
public void testDefaultIndex() {
TemplateEngine templateEngine = mock(TemplateEngine.class);
RoutingContext routingContext = mock(RoutingContext.class);
when(routingContext.normalisedPath()).thenReturn("/");
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(), eq("templates"), eq("/index"), any());
}
示例3: testSetIndex
import io.vertx.ext.web.templ.TemplateEngine; //导入依赖的package包/类
@Test
public void testSetIndex() {
TemplateEngine templateEngine = mock(TemplateEngine.class);
RoutingContext routingContext = mock(RoutingContext.class);
when(routingContext.normalisedPath()).thenReturn("/");
Route currentRoute = mock(Route.class);
when(currentRoute.getPath()).thenReturn("/");
when(routingContext.currentRoute()).thenReturn(currentRoute);
TemplateHandler templateHandler = new TemplateHandlerImpl(templateEngine, "templates", "ext");
templateHandler.setIndexTemplate("home");
templateHandler.handle(routingContext);
verify(templateEngine).render(any(), eq("templates"), eq("/home"), any());
}
示例4: testTurnOffIndex
import io.vertx.ext.web.templ.TemplateEngine; //导入依赖的package包/类
@Test
public void testTurnOffIndex() {
TemplateEngine templateEngine = mock(TemplateEngine.class);
RoutingContext routingContext = mock(RoutingContext.class);
when(routingContext.normalisedPath()).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(), eq("templates"), eq("/"), any());
}
示例5: testSimpleTemplate
import io.vertx.ext.web.templ.TemplateEngine; //导入依赖的package包/类
@Test
public void testSimpleTemplate() {
TemplateEngine templateEngine = mock(TemplateEngine.class);
RoutingContext routingContext = mock(RoutingContext.class);
when(routingContext.normalisedPath()).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(), eq("templates"), eq("/about"), any());
}
示例6: fromViewName
import io.vertx.ext.web.templ.TemplateEngine; //导入依赖的package包/类
public TemplateEngine fromViewName(String tplName) {
int pointIdx = tplName.lastIndexOf('.');
String extension = tplName.substring(pointIdx + 1, tplName.length());
return config.getTemplateEngines().get(extension);
}
示例7: registerTemplateEngine
import io.vertx.ext.web.templ.TemplateEngine; //导入依赖的package包/类
public void registerTemplateEngine(String extension, TemplateEngine engine) {
config.registerTemplateEngine(extension, engine);
}
示例8: TemplateHandlerImpl
import io.vertx.ext.web.templ.TemplateEngine; //导入依赖的package包/类
public TemplateHandlerImpl(TemplateEngine engine, String templateDirectory, String contentType) {
this.engine = engine;
this.templateDirectory = templateDirectory == null || templateDirectory.isEmpty() ? "." : templateDirectory;
this.contentType = contentType;
this.indexTemplate = DEFAULT_INDEX_TEMPLATE;
}
示例9: example41_2
import io.vertx.ext.web.templ.TemplateEngine; //导入依赖的package包/类
public void example41_2(Router router, TemplateEngine engine) {
TemplateHandler handler = TemplateHandler.create(engine);
router.get("/dynamic").handler(routingContext -> {
routingContext.put("request_path", routingContext.request().path());
routingContext.put("session_data", routingContext.session().data());
routingContext.next();
});
router.get("/dynamic/").handler(handler);
}
示例10: getThymeleafTemplateEngine
import io.vertx.ext.web.templ.TemplateEngine; //导入依赖的package包/类
/**
* Get a reference to the internal Thymeleaf TemplateEngine object so it
* can be configured.
*
* @return a reference to the internal Thymeleaf TemplateEngine instance.
*/
org.thymeleaf.TemplateEngine getThymeleafTemplateEngine();
示例11: create
import io.vertx.ext.web.templ.TemplateEngine; //导入依赖的package包/类
/**
* Create a handler
*
* @param engine the template engine
* @return the handler
*/
static TemplateHandler create(TemplateEngine engine) {
return new TemplateHandlerImpl(engine, DEFAULT_TEMPLATE_DIRECTORY, DEFAULT_CONTENT_TYPE);
}