本文整理汇总了Java中org.wisdom.api.templates.Template.render方法的典型用法代码示例。如果您正苦于以下问题:Java Template.render方法的具体用法?Java Template.render怎么用?Java Template.render使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.wisdom.api.templates.Template
的用法示例。
在下文中一共展示了Template.render方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testJsonTemplate
import org.wisdom.api.templates.Template; //导入方法依赖的package包/类
@Test
public void testJsonTemplate() throws MalformedURLException {
Template template = osgi.getServiceObject(Template.class, "(name=kitten2)");
assertThat(template).isNotNull();
assertThat(template.engine()).isEqualTo("mustache");
assertThat(template.mimetype()).isEqualTo(MimeTypes.JSON);
assertThat(template.name()).isEqualTo("kitten2");
Renderable renderable = template.render(new DefaultController() {
}, ImmutableMap.<String, Object>of("items", Cat.cats()));
assertThat(renderable.mimetype()).isEqualTo(MimeTypes.JSON);
assertThat((String) renderable.content())
.contains("\"name\": \"romeo\",")
.contains("\"name\": \"tom\",");
}
示例2: testTemplateUsingAFunction
import org.wisdom.api.templates.Template; //导入方法依赖的package包/类
@Test
public void testTemplateUsingAFunction() throws MalformedURLException {
Template template = osgi.getServiceObject(Template.class, "(name=function/function)");
assertThat(template.engine()).isEqualTo("mustache");
assertThat(template.mimetype()).isEqualTo(MimeTypes.TEXT);
assertThat(template.name()).isEqualTo("function/function");
Renderable renderable = template.render(new DefaultController() {
}, ImmutableMap.of(
"name", "Wisdom",
"wrapped", new TemplateFunction() {
@Nullable
@Override
public String apply(String input) {
return "<b>" + input + "</b>";
}
}
));
assertThat(renderable.mimetype()).isEqualTo(MimeTypes.TEXT);
assertThat((String) renderable.content()).contains("<b>").contains("Wisdom is awesome.").contains("</b>");
}
示例3: testMailTemplate
import org.wisdom.api.templates.Template; //导入方法依赖的package包/类
@Test
public void testMailTemplate() throws MalformedURLException {
Template template = osgi.getServiceObject(Template.class, "(name=mustache/mail)");
assertThat(template.engine()).isEqualTo("mustache");
assertThat(template.mimetype()).isEqualTo(MimeTypes.TEXT);
assertThat(template.name()).isEqualTo("mustache/mail");
Renderable renderable = template.render(new DefaultController() {
}, ImmutableMap.<String, Object>of(
"name", "Wisdom",
"value", 10000,
"taxed_value", 10000 - (10000 * 0.4),
"in_ca", true
));
assertThat(renderable.mimetype()).isEqualTo(MimeTypes.TEXT);
assertThat((String) renderable.content())
.contains("Hello Wisdom")
.contains("You have just won 10000 dollars!")
.contains("Well, 6000.0 dollars, after taxes.");
}
示例4: testSectionAndInvertedSection
import org.wisdom.api.templates.Template; //导入方法依赖的package包/类
@Test
public void testSectionAndInvertedSection() throws MalformedURLException {
Template template = osgi.getServiceObject(Template.class, "(name=mustache/section)");
Renderable renderable = template.render(new DefaultController() {
}, ImmutableMap.<String, Object>of(
"repo", ImmutableList.of(
ImmutableMap.of("name", "central"),
ImmutableMap.of("name", "local"))
));
assertThat(renderable.mimetype()).isEqualTo(MimeTypes.TEXT);
assertThat((String) renderable.content())
.contains("<b>central</b>")
.contains("<b>local</b>");
renderable = template.render(new DefaultController() {
}, ImmutableMap.<String, Object>of(
"repo", ImmutableList.of()
));
assertThat((String) renderable.content())
.contains("No repos :(");
}
示例5: testPartials
import org.wisdom.api.templates.Template; //导入方法依赖的package包/类
@Test
public void testPartials() throws MalformedURLException {
Template template = osgi.getServiceObject(Template.class, "(name=mustache/base)");
assertThat(template.engine()).isEqualTo("mustache");
assertThat(template.mimetype()).isEqualTo(MimeTypes.HTML);
assertThat(template.name()).isEqualTo("mustache/base");
Renderable renderable = template.render(new DefaultController() {
}, ImmutableMap.<String, Object>of(
"names", ImmutableList.of(
ImmutableMap.of("name", "romeo"),
ImmutableMap.of("name", "gros minet"),
ImmutableMap.of("name", "tom")
)
));
assertThat(renderable.mimetype()).isEqualTo(MimeTypes.HTML);
assertThat((String) renderable.content())
.contains("<strong>romeo</strong")
.contains("<strong>gros minet</strong>")
.contains("<strong>tom</strong>");
}
示例6: testPartialsUsingAbsolutePath
import org.wisdom.api.templates.Template; //导入方法依赖的package包/类
@Test
public void testPartialsUsingAbsolutePath() throws MalformedURLException {
Template template = osgi.getServiceObject(Template.class, "(name=mustache/baseUsingAbsolutePath)");
assertThat(template.engine()).isEqualTo("mustache");
assertThat(template.mimetype()).isEqualTo(MimeTypes.HTML);
assertThat(template.name()).isEqualTo("mustache/baseUsingAbsolutePath");
Renderable renderable = template.render(new DefaultController() {
}, ImmutableMap.<String, Object>of(
"names", ImmutableList.of(
ImmutableMap.of("name", "romeo"),
ImmutableMap.of("name", "gros minet"),
ImmutableMap.of("name", "tom")
)
));
assertThat(renderable.mimetype()).isEqualTo(MimeTypes.HTML);
assertThat((String) renderable.content())
.contains("<strong>romeo</strong")
.contains("<strong>gros minet</strong>")
.contains("<strong>tom</strong>");
}
示例7: testInheritance
import org.wisdom.api.templates.Template; //导入方法依赖的package包/类
@Test
public void testInheritance() throws MalformedURLException {
Template template = osgi.getServiceObject(Template.class, "(name=inheritance/home/welcome)");
assertThat(template.engine()).isEqualTo("mustache");
assertThat(template.mimetype()).isEqualTo(MimeTypes.HTML);
Renderable renderable = template.render(new DefaultController() {
}, ImmutableMap.<String, Object>of(
"title", "Hello Wisdom", "name", "you")
);
assertThat(renderable.mimetype()).isEqualTo(MimeTypes.HTML);
assertThat((String) renderable.content())
.contains("<title>Welcome page</title>")
.contains("<p>Content from base</p>")
.contains("<h1>Hello you,");
}
示例8: render
import org.wisdom.api.templates.Template; //导入方法依赖的package包/类
/**
* Renders the given template.
*
* @param template the template
* @param parameters the parameters given as list following the scheme: key, value, key, value...
* @return the renderable object.
*/
public Renderable<?> render(Template template, Object... parameters) {
Map<String, Object> map = Maps.newHashMap();
String key = null;
for (Object parameter : parameters) {
if (key == null) {
if (!(parameter instanceof String)) {
throw new IllegalArgumentException("The template variable name " + parameter + " must be a string");
} else {
key = (String) parameter;
}
} else {
map.put(key, parameter);
key = null;
}
}
if (key != null) {
throw new IllegalArgumentException("Illegal number of parameter, the variable " + key + " has no value");
}
return template.render(this, map);
}