当前位置: 首页>>代码示例>>Java>>正文


Java PebbleTemplate.evaluate方法代码示例

本文整理汇总了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);
	}
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:17,代码来源:PebbleTheme.java

示例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);
    }
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:23,代码来源:StrictModeTest.java

示例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());
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:17,代码来源:LogicTest.java

示例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());
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:21,代码来源:ForNodeTest.java

示例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());
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:12,代码来源:CoreFiltersTest.java

示例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());
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:13,代码来源:CoreFiltersTest.java

示例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());
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:10,代码来源:CoreFunctionsTest.java

示例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());
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:13,代码来源:ArraySyntaxTest.java

示例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());
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:15,代码来源:CoreFiltersTest.java

示例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());
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:13,代码来源:WhitespaceControlTest.java

示例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());
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:14,代码来源:CoreFiltersTest.java

示例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());
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:17,代码来源:CoreTagsTest.java

示例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());
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:15,代码来源:CoreTagsTest.java

示例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());
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:13,代码来源:WhitespaceControlTest.java

示例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);
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:11,代码来源:CoreTestsTest.java


注:本文中的com.mitchellbosecke.pebble.template.PebbleTemplate.evaluate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。