本文整理汇总了Java中org.jtwig.JtwigTemplate.inlineTemplate方法的典型用法代码示例。如果您正苦于以下问题:Java JtwigTemplate.inlineTemplate方法的具体用法?Java JtwigTemplate.inlineTemplate怎么用?Java JtwigTemplate.inlineTemplate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jtwig.JtwigTemplate
的用法示例。
在下文中一共展示了JtwigTemplate.inlineTemplate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: elseIfConditionWithoutEndCode
import org.jtwig.JtwigTemplate; //导入方法依赖的package包/类
@Test
public void elseIfConditionWithoutEndCode() throws Exception {
JtwigTemplate jtwigTemplate = JtwigTemplate.inlineTemplate("{% if (true) %}{% elseif (true) ko{% endif %}");
expectedException.expect(ParseException.class);
expectedException.expectMessage(containsString("If condition code island not closed"));
jtwigTemplate.render(newModel());
}
示例2: nonExistingWithoutNames
import org.jtwig.JtwigTemplate; //导入方法依赖的package包/类
@Test
public void nonExistingWithoutNames() throws Exception {
JtwigTemplate template = JtwigTemplate.inlineTemplate("{{ callMeBaby('test', 1) }}");
expectedException.expect(CalculationException.class);
expectedException.expectMessage(containsString("Unable to resolve function 'callMeBaby' with arguments [test, 1]"));
template.render(JtwigModel.newModel());
}
示例3: nullPointerException
import org.jtwig.JtwigTemplate; //导入方法依赖的package包/类
@Test
public void nullPointerException() throws Exception {
JtwigTemplate jtwigTemplate = JtwigTemplate.inlineTemplate("{% if test.value.internal %}KO{% else %}OK{% endif %}");
String result1 = jtwigTemplate.render(JtwigModel.newModel().with("test", new TestBean(null)));
String result2 = jtwigTemplate.render(JtwigModel.newModel().with("test", new TestBean(null)));
assertThat(result1, is("OK"));
assertThat(result2, is("OK")); // testing cache
}
示例4: cachingPropertyResolutionWithDistinctModels
import org.jtwig.JtwigTemplate; //导入方法依赖的package包/类
@Test
public void cachingPropertyResolutionWithDistinctModels () {
JtwigTemplate template = JtwigTemplate.inlineTemplate("{{ value.key }}");
String result1 = template.render(JtwigModel.newModel().with("value", new SubModelA()));
String result2 = template.render(JtwigModel.newModel().with("value", new SubModelB()));
assertThat(result1, is("A"));
assertThat(result2, is("B"));
}
示例5: invalidForWithoutVariable
import org.jtwig.JtwigTemplate; //导入方法依赖的package包/类
@Test
public void invalidForWithoutVariable() throws Exception {
JtwigTemplate jtwigTemplate = JtwigTemplate.inlineTemplate("{% for in list %}{{k}}={{v}} {% endfor %}");
expectedException.expect(ParseException.class);
expectedException.expectMessage(containsString("Expecting a variable name in for loop"));
jtwigTemplate.render(newModel());
}
示例6: 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"));
}
示例7: simpleFlush
import org.jtwig.JtwigTemplate; //导入方法依赖的package包/类
@Test
public void simpleFlush() throws Exception {
OutputStream outputStream = mock(OutputStream.class);
JtwigTemplate result = JtwigTemplate.inlineTemplate("{% flush %}");
result.render(JtwigModel.newModel(), outputStream);
verify(outputStream).flush();
}
示例8: simpleIfSharedContext
import org.jtwig.JtwigTemplate; //导入方法依赖的package包/类
@Test
public void simpleIfSharedContext() throws Exception {
JtwigTemplate jtwigTemplate = JtwigTemplate.inlineTemplate("{% set a = 2 %}{% if (true) %}{% set a = 1 %}{% endif %}{{ a }}");
String result = jtwigTemplate.render(newModel());
assertThat(result, is("1"));
}
示例9: includeShouldExportModelAndExtraData
import org.jtwig.JtwigTemplate; //导入方法依赖的package包/类
@Test
public void includeShouldExportModelAndExtraData() throws Exception {
JtwigTemplate template = JtwigTemplate.inlineTemplate("{% include 'memory:a' with { joao: 'Melo' } %}", configuration()
.resources().resourceLoaders().add(new TypedResourceLoader(MEMORY, InMemoryResourceLoader.builder()
.withResource("a", "{{ name }} {{ joao }}")
.build())).and().and()
.build()
);
String result = template.render(newModel().with("name", "Hello"));
assertThat(result, is("Hello Melo"));
}
示例10: outputWithStripLeftWhiteSpace
import org.jtwig.JtwigTemplate; //导入方法依赖的package包/类
@Test
public void outputWithStripLeftWhiteSpace() throws Exception {
JtwigTemplate template = JtwigTemplate.inlineTemplate(" {{- variable }} ");
String result = template.render(newModel().with("variable", "hello"));
assertThat(result, is("hello "));
}
示例11: output
import org.jtwig.JtwigTemplate; //导入方法依赖的package包/类
@Test
public void output() throws Exception {
JtwigTemplate template = JtwigTemplate.inlineTemplate(" {{ variable }} ");
String result = template.render(newModel().with("variable", "hello"));
assertThat(result, is(" hello "));
}
示例12: outputWithStripBothWhiteSpace
import org.jtwig.JtwigTemplate; //导入方法依赖的package包/类
@Test
public void outputWithStripBothWhiteSpace() throws Exception {
JtwigTemplate template = JtwigTemplate.inlineTemplate(" {{- variable -}} ");
String result = template.render(newModel().with("variable", "hello"));
assertThat(result, is("hello"));
}
示例13: ifConditionIncorrectElseIf
import org.jtwig.JtwigTemplate; //导入方法依赖的package包/类
@Test
public void ifConditionIncorrectElseIf() 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{% else if (true) %}ok{% endif %}");
expectedException.expect(ParseException.class);
expectedException.expectMessage(containsString("Expecting ending of else block"));
jtwigTemplate.render(newModel());
}
示例14: 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());
}
示例15: blockDifferentNames
import org.jtwig.JtwigTemplate; //导入方法依赖的package包/类
@Test
public void blockDifferentNames() throws Exception {
JtwigTemplate template = JtwigTemplate.inlineTemplate("{% block one %}hello{% endblock name %}");
expectedException.expect(ParseException.class);
expectedException.expectMessage(containsString("Expecting block 'one' to end with the same identifier but found 'name' instead"));
template.render(newModel());
}