本文整理汇总了Java中org.jtwig.JtwigTemplate.render方法的典型用法代码示例。如果您正苦于以下问题:Java JtwigTemplate.render方法的具体用法?Java JtwigTemplate.render怎么用?Java JtwigTemplate.render使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jtwig.JtwigTemplate
的用法示例。
在下文中一共展示了JtwigTemplate.render方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: extendFirstAvailableOfFallbacksFromArrayModel
import org.jtwig.JtwigTemplate; //导入方法依赖的package包/类
@Test
public void extendFirstAvailableOfFallbacksFromArrayModel() throws Exception {
JtwigTemplate template = JtwigTemplate.inlineTemplate("{% extends paths %}", configuration()
.resources().resourceLoaders().add(new TypedResourceLoader(MEMORY, InMemoryResourceLoader
.builder()
.withResource("a", "{% block one %}{{ 'a' }}{% endblock %}")
.withResource("b", "{% block one %}{{ 'b' }}{% endblock %}")
.build())).and().and()
.build()
);
Map<String, Object> modelData = new HashMap<>();
modelData.put("paths", new String[] {"memory:b", "memory:a"});
String result = template.render(JtwigModel.newModel(modelData));
assertThat(result, is("b"));
}
示例2: render
import org.jtwig.JtwigTemplate; //导入方法依赖的package包/类
@Override
public String render(String templatePath, Map<String, Object> data) throws Exception {
// TODO template cache when startup
JtwigTemplate template = JtwigTemplate.classpathTemplate(templatePath);
JtwigModel model = JtwigModel.newModel(data);
return template.render(model);
}
示例3: getDSL
import org.jtwig.JtwigTemplate; //导入方法依赖的package包/类
@Override
public String getDSL() {
JtwigTemplate template = JtwigTemplate.classpathTemplate("templates/filters.twig");
JtwigModel model = JtwigModel.newModel().with("var", "World");
String result = template.render(model);
logger.info("get search dsl " + result);
return result;
}
示例4: createQuery
import org.jtwig.JtwigTemplate; //导入方法依赖的package包/类
public String createQuery() {
JtwigTemplate template = JtwigTemplate.classpathTemplate("templates/" + templateName);
JtwigModel model = JtwigModel.newModel();
modelParams.forEach(model::with);
return template.render(model);
}
示例5: outputWithoutEndCodeIsland
import org.jtwig.JtwigTemplate; //导入方法依赖的package包/类
@Test
public void outputWithoutEndCodeIsland() throws Exception {
JtwigTemplate template = JtwigTemplate.inlineTemplate(" {{- variable } ");
expectedException.expect(ParseException.class);
expectedException.expectMessage(containsString("Expecting end of output code island"));
template.render(newModel());
}
示例6: ifConditionWhiteSpaceControlEndIf
import org.jtwig.JtwigTemplate; //导入方法依赖的package包/类
@Test
public void ifConditionWhiteSpaceControlEndIf() throws Exception {
JtwigTemplate jtwigTemplate = JtwigTemplate.inlineTemplate("{% if (true) -%} ok{% else %}ko{% endif %}");
String result = jtwigTemplate.render(newModel());
assertThat(result, is("ok"));
}
示例7: ifConditionMissingEnd
import org.jtwig.JtwigTemplate; //导入方法依赖的package包/类
@Test
public void ifConditionMissingEnd() throws Exception {
// For the time being we will use this, but we might want to improve our messages and try to check the if syntax
JtwigTemplate jtwigTemplate = JtwigTemplate.inlineTemplate("{% if (false) %}ko");
expectedException.expect(ParseException.class);
expectedException.expectMessage(containsString("Missing endif tag"));
jtwigTemplate.render(newModel());
}
示例8: ifConditionWhiteSpaceControl
import org.jtwig.JtwigTemplate; //导入方法依赖的package包/类
@Test
public void ifConditionWhiteSpaceControl() throws Exception {
JtwigTemplate jtwigTemplate = JtwigTemplate.inlineTemplate(" {%- if (false) -%} ko {%- else -%} ok {%- endif -%} ");
String result = jtwigTemplate.render(newModel());
assertThat(result, is("ok"));
}
示例9: render
import org.jtwig.JtwigTemplate; //导入方法依赖的package包/类
public void render (OutputStream outputStream) {
ResourceMetadata resourceMetadata = environment.getResourceEnvironment().getResourceService().loadMetadata(resourceReference);
if (!resourceMetadata.exists())
throw new ResourceNotFoundException(String.format("Resource %s not found", resourceReference));
JtwigTemplate jtwigTemplate = new JtwigTemplate(environment, resourceReference);
jtwigTemplate.render(model, outputStream);
}
示例10: setNotEnding
import org.jtwig.JtwigTemplate; //导入方法依赖的package包/类
@Test
public void setNotEnding() throws Exception {
JtwigTemplate jtwigTemplate = JtwigTemplate.inlineTemplate(" {%- set variable = 1 {{ variable }}");
expectedException.expect(ParseException.class);
expectedException.expectMessage(containsString("Expecting end of set code island"));
jtwigTemplate.render(newModel());
}
示例11: blockMissingEndTag
import org.jtwig.JtwigTemplate; //导入方法依赖的package包/类
@Test
public void blockMissingEndTag() throws Exception {
JtwigTemplate template = JtwigTemplate.inlineTemplate("{% block one %}hello");
expectedException.expect(ParseException.class);
expectedException.expectMessage(containsString("Missing endblock tag"));
template.render(newModel());
}
示例12: includingFirstAvailableOfFallbacks
import org.jtwig.JtwigTemplate; //导入方法依赖的package包/类
@Test
public void includingFirstAvailableOfFallbacks() throws Exception {
JtwigTemplate template = JtwigTemplate.inlineTemplate("{% include ['memory:b', 'memory:a'] %}", configuration()
.resources().resourceLoaders().add(new TypedResourceLoader(MEMORY, InMemoryResourceLoader
.builder()
.withResource("a", "{{ 'a' }}")
.withResource("b", "{{ 'b' }}")
.build())).and().and()
.build()
);
String result = template.render(newModel());
assertThat(result, is("b"));
}
示例13: blockEndMissingEndCode
import org.jtwig.JtwigTemplate; //导入方法依赖的package包/类
@Test
public void blockEndMissingEndCode() throws Exception {
JtwigTemplate template = JtwigTemplate.inlineTemplate("{% block name %}hello{% endblock name");
expectedException.expect(ParseException.class);
expectedException.expectMessage(containsString("Missing end of code island"));
template.render(newModel());
}
示例14: ifConditionWhiteSpaceControlStartIf
import org.jtwig.JtwigTemplate; //导入方法依赖的package包/类
@Test
public void ifConditionWhiteSpaceControlStartIf() throws Exception {
JtwigTemplate jtwigTemplate = JtwigTemplate.inlineTemplate(" {%- if (true) -%} ok{% else %}ko{% endif %}");
String result = jtwigTemplate.render(newModel());
assertThat(result, is("ok"));
}
示例15: invalidForMissingEndTag
import org.jtwig.JtwigTemplate; //导入方法依赖的package包/类
@Test
public void invalidForMissingEndTag() throws Exception {
JtwigTemplate jtwigTemplate = JtwigTemplate.inlineTemplate("{% for k in list %}");
expectedException.expect(ParseException.class);
expectedException.expectMessage(containsString("Missing endfor tag"));
jtwigTemplate.render(newModel());
}