本文整理汇总了Java中com.mitchellbosecke.pebble.template.PebbleTemplate.evaluate方法的典型用法代码示例。如果您正苦于以下问题:Java PebbleTemplate.evaluate方法的具体用法?Java PebbleTemplate.evaluate怎么用?Java PebbleTemplate.evaluate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.mitchellbosecke.pebble.template.PebbleTemplate
的用法示例。
在下文中一共展示了PebbleTemplate.evaluate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: render
import com.mitchellbosecke.pebble.template.PebbleTemplate; //导入方法依赖的package包/类
private String render(Renderable renderable, PebbleTemplate template) {
try {
StringWriter writer=new StringWriter();
PebbleWrapper it = PebbleWrapper.builder()
.markupRenderFactory(markupRenderFactory)
.context(renderable.context())
.addAllAllBlobs(renderable.blobs())
.build();
template.evaluate(writer, Maps.newLinkedHashMap(ImmutableMap.of("it",it)));
return writer.toString();
} catch (PebbleException | IOException | RuntimePebbleException px) {
throw new RuntimeException("rendering fails for "+template.getName(),px);
}
}
示例2: testComplexVariable
import com.mitchellbosecke.pebble.template.PebbleTemplate; //导入方法依赖的package包/类
/**
* Tests that the line number and file name is correctly passed to the
* exception in strict mode.
*/
@Test()
public void testComplexVariable() throws PebbleException, IOException {
PebbleEngine pebble = new PebbleEngine.Builder().strictVariables(true).build();
PebbleTemplate template = pebble.getTemplate("templates/template.strictModeComplexExpression.peb");
Map<String, Object> context = new HashMap<>();
Writer writer = new StringWriter();
try {
template.evaluate(writer, context);
Assert.fail("Exception " + RootAttributeNotFoundException.class.getCanonicalName() + " is expected.");
} catch (RootAttributeNotFoundException e) {
Assert.assertEquals(e.getFileName(), "templates/template.strictModeComplexExpression.peb");
Assert.assertEquals(e.getLineNumber(), (Integer) 2);
}
}
示例3: testComparisonWithNull2
import com.mitchellbosecke.pebble.template.PebbleTemplate; //导入方法依赖的package包/类
@Test()
public void testComparisonWithNull2() throws PebbleException, IOException {
PebbleEngine pebble = new PebbleEngine.Builder().loader(new StringLoader()).strictVariables(false).build();
String source = "{% if number1 > number2 %}yes{% else %}no{% endif %}";
PebbleTemplate template = pebble.getTemplate(source);
Map<String, Object> context = new HashMap<>();
context.put("number1", BigDecimal.valueOf(3d));
context.put("number2", null);
Writer writer = new StringWriter();
template.evaluate(writer, context);
assertEquals("no", writer.toString());
}
示例4: testLoopIndex
import com.mitchellbosecke.pebble.template.PebbleTemplate; //导入方法依赖的package包/类
@Test
public void testLoopIndex() throws Exception {
PebbleEngine pebble = new PebbleEngine.Builder().loader(new StringLoader()).strictVariables(false).build();
StringBuilder source = new StringBuilder("{% for i in 0..2 %}");
source.append("{% for j in 0..2 %}");
source.append("inner={{ loop.index }} ");
source.append("{% endfor %}");
source.append("outer={{ loop.index }} ");
source.append("{% endfor %}");
source.append("outside loop={{ loop.index }} ");
PebbleTemplate template = pebble.getTemplate(source.toString());
Map<String, Object> context = new HashMap<>();
Writer writer = new StringWriter();
template.evaluate(writer, context);
assertEquals("inner=0 inner=1 inner=2 outer=0 inner=0 inner=1 inner=2 outer=1 inner=0 inner=1 inner=2 outer=2 outside loop= ", writer.toString());
}
示例5: testAbbreviate
import com.mitchellbosecke.pebble.template.PebbleTemplate; //导入方法依赖的package包/类
@Test
public void testAbbreviate() throws PebbleException, IOException {
PebbleEngine pebble = new PebbleEngine.Builder().loader(new StringLoader()).strictVariables(false).build();
PebbleTemplate template = pebble
.getTemplate("{{ 'This is a test of the abbreviate filter' | abbreviate(16) }}");
Writer writer = new StringWriter();
template.evaluate(writer);
assertEquals("This is a tes...", writer.toString());
}
示例6: testDefaultWithNamedArguments
import com.mitchellbosecke.pebble.template.PebbleTemplate; //导入方法依赖的package包/类
@Test
public void testDefaultWithNamedArguments() throws PebbleException, IOException {
PebbleEngine pebble = new PebbleEngine.Builder().loader(new StringLoader()).strictVariables(false).build();
PebbleTemplate template = pebble.getTemplate("{{ obj|default(default='ONE') }}");
Map<String, Object> context = new HashMap<>();
context.put("obj", null);
Writer writer = new StringWriter();
template.evaluate(writer, context);
assertEquals("ONE", writer.toString());
}
示例7: testParentThenMacro
import com.mitchellbosecke.pebble.template.PebbleTemplate; //导入方法依赖的package包/类
@Test
public void testParentThenMacro() throws PebbleException, IOException {
PebbleEngine pebble = new PebbleEngine.Builder().strictVariables(false).build();
PebbleTemplate template = pebble.getTemplate("templates/function/template.childThenParentThenMacro.peb");
Writer writer = new StringWriter();
template.evaluate(writer);
assertEquals("test", writer.toString());
}
示例8: testSortFilter
import com.mitchellbosecke.pebble.template.PebbleTemplate; //导入方法依赖的package包/类
@Test
public void testSortFilter() throws PebbleException, IOException {
PebbleEngine pebble = new PebbleEngine.Builder().loader(new StringLoader()).strictVariables(false).build();
String source = "{% set arr = [3,2,1,0] %}{{ arr | sort }}";
PebbleTemplate template = pebble.getTemplate(source);
Writer writer = new StringWriter();
template.evaluate(writer, new HashMap<String, Object>());
assertEquals("[0, 1, 2, 3]", writer.toString());
}
示例9: testNumberFormatFilterWithNamedArgument
import com.mitchellbosecke.pebble.template.PebbleTemplate; //导入方法依赖的package包/类
@Test
public void testNumberFormatFilterWithNamedArgument() throws PebbleException, IOException {
PebbleEngine pebble = new PebbleEngine.Builder().loader(new StringLoader()).strictVariables(false)
.defaultLocale(Locale.US).build();
PebbleTemplate template = pebble
.getTemplate("You owe me {{ 10000.235166 | numberformat(format=currencyFormat) }}.");
Map<String, Object> context = new HashMap<>();
context.put("currencyFormat", "$#,###,###,##0.00");
Writer writer = new StringWriter();
template.evaluate(writer, context);
assertEquals("You owe me $10,000.24.", writer.toString());
}
示例10: testWhitespaceTrimInPresenceOfMultipleTags
import com.mitchellbosecke.pebble.template.PebbleTemplate; //导入方法依赖的package包/类
@Test
public void testWhitespaceTrimInPresenceOfMultipleTags() throws PebbleException, IOException {
PebbleEngine pebble = new PebbleEngine.Builder().loader(new StringLoader()).strictVariables(true).build();
PebbleTemplate template = pebble.getTemplate("{{ foo }} <li> {{- foo -}} </li> {{ foo }}");
Writer writer = new StringWriter();
Map<String, Object> context = new HashMap<>();
context.put("foo", "bar");
template.evaluate(writer, context);
assertEquals("bar <li>bar</li> bar", writer.toString());
}
示例11: testLastWithPrimitiveArrayInput
import com.mitchellbosecke.pebble.template.PebbleTemplate; //导入方法依赖的package包/类
@Test
public void testLastWithPrimitiveArrayInput() throws PebbleException, IOException {
PebbleEngine pebble = new PebbleEngine.Builder().loader(new StringLoader()).strictVariables(false).build();
PebbleTemplate template = pebble.getTemplate("{{ ages | last }}");
Map<String, Object> context = new HashMap<>();
context.put("ages", new int[] { 28, 30 });
Writer writer = new StringWriter();
template.evaluate(writer, context);
assertEquals("30", writer.toString());
}
示例12: testIncludeOverridesBlocks
import com.mitchellbosecke.pebble.template.PebbleTemplate; //导入方法依赖的package包/类
/**
* Ensures that when including a template it is safe to have conflicting
* block names.
*
* @throws PebbleException
* @throws IOException
*/
@Test
public void testIncludeOverridesBlocks() throws PebbleException, IOException {
PebbleEngine pebble = new PebbleEngine.Builder().strictVariables(false).build();
PebbleTemplate template = pebble.getTemplate("templates/template.includeOverrideBlock.peb");
Writer writer = new StringWriter();
template.evaluate(writer);
assertEquals("TWO" + LINE_SEPARATOR + "ONE" + LINE_SEPARATOR + "TWO" + LINE_SEPARATOR, writer.toString());
}
示例13: testIncludeWithinParallelTag
import com.mitchellbosecke.pebble.template.PebbleTemplate; //导入方法依赖的package包/类
@Test(timeout = 300)
public void testIncludeWithinParallelTag() throws PebbleException, IOException {
PebbleEngine pebble = new PebbleEngine.Builder().strictVariables(true)
.executorService(Executors.newCachedThreadPool()).build();
PebbleTemplate template = pebble.getTemplate("templates/template.parallelInclude1.peb");
Writer writer = new StringWriter();
Map<String, Object> context = new HashMap<>();
context.put("slowObject", new SlowObject());
template.evaluate(writer, context);
assertEquals("first" + LINE_SEPARATOR + "TEMPLATE1" + LINE_SEPARATOR + "first", writer.toString());
}
示例14: testWhitespaceTrimRemovesNewlines
import com.mitchellbosecke.pebble.template.PebbleTemplate; //导入方法依赖的package包/类
@Test
public void testWhitespaceTrimRemovesNewlines() throws PebbleException, IOException {
PebbleEngine pebble = new PebbleEngine.Builder().loader(new StringLoader()).strictVariables(true).build();
PebbleTemplate template = pebble.getTemplate("<li>\n{{- foo -}}\n</li>");
Writer writer = new StringWriter();
Map<String, Object> context = new HashMap<>();
context.put("foo", "bar");
template.evaluate(writer, context);
assertEquals("<li>bar</li>", writer.toString());
}
示例15: testNullOdd
import com.mitchellbosecke.pebble.template.PebbleTemplate; //导入方法依赖的package包/类
@Test(expected = PebbleException.class)
public void testNullOdd() throws PebbleException, IOException {
PebbleEngine pebble = new PebbleEngine.Builder().loader(new StringLoader()).strictVariables(false).build();
String source = "{% if null is odd %}yes{% else %}no{% endif %}";
PebbleTemplate template = pebble.getTemplate(source);
Writer writer = new StringWriter();
template.evaluate(writer);
}