本文整理汇总了Java中com.mitchellbosecke.pebble.template.PebbleTemplate.evaluateBlock方法的典型用法代码示例。如果您正苦于以下问题:Java PebbleTemplate.evaluateBlock方法的具体用法?Java PebbleTemplate.evaluateBlock怎么用?Java PebbleTemplate.evaluateBlock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.mitchellbosecke.pebble.template.PebbleTemplate
的用法示例。
在下文中一共展示了PebbleTemplate.evaluateBlock方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testRenderSingleBlockWithContext
import com.mitchellbosecke.pebble.template.PebbleTemplate; //导入方法依赖的package包/类
@Test
public void testRenderSingleBlockWithContext() throws PebbleException, IOException {
PebbleEngine pebble = new PebbleEngine.Builder().loader(new StringLoader()).strictVariables(false).build();
String source = "Prefix {% block block_a %}{{vara}}{% endblock %}{% block block_b %}{{varb}}{% endblock %} Postfix";
PebbleTemplate template = pebble.getTemplate(source);
Map<String, Object> context = new HashMap<>();
context.put("vara", "FOO");
context.put("varb", "BAR");
Writer writer_a = new StringWriter();
template.evaluateBlock("block_a", writer_a, context, CANADA);
assertEquals("FOO", writer_a.toString());
Writer writer_b = new StringWriter();
template.evaluateBlock("block_b", writer_b, context, CANADA);
assertEquals("BAR", writer_b.toString());
}
示例2: testRenderSingleBlockWithContextAndLocale
import com.mitchellbosecke.pebble.template.PebbleTemplate; //导入方法依赖的package包/类
@Test
public void testRenderSingleBlockWithContextAndLocale() throws PebbleException, IOException {
PebbleEngine pebble = new PebbleEngine.Builder().loader(new StringLoader()).strictVariables(false).build();
String source = "Prefix {% block block_a %}{{vara}}{% endblock %}{% block block_b %}{{varb}}{% endblock %} Postfix";
PebbleTemplate template = pebble.getTemplate(source);
Map<String, Object> context = new HashMap<>();
context.put("vara", "FOO");
context.put("varb", "BAR");
Writer writer_a = new StringWriter();
template.evaluateBlock("block_a", writer_a, context);
assertEquals("FOO", writer_a.toString());
Writer writer_b = new StringWriter();
template.evaluateBlock("block_b", writer_b, context);
assertEquals("BAR", writer_b.toString());
}
示例3: testRenderSingleBlock
import com.mitchellbosecke.pebble.template.PebbleTemplate; //导入方法依赖的package包/类
@Test
public void testRenderSingleBlock() throws PebbleException, IOException {
PebbleEngine pebble = new PebbleEngine.Builder().loader(new StringLoader()).strictVariables(false).build();
String source = "Prefix {% block block_a %}Block A{% endblock %}{% block block_b %}Block B{% endblock %} Postfix";
PebbleTemplate template = pebble.getTemplate(source);
Writer writer_a = new StringWriter();
template.evaluateBlock("block_a", writer_a);
assertEquals("Block A", writer_a.toString());
Writer writer_b = new StringWriter();
template.evaluateBlock("block_b", writer_b);
assertEquals("Block B", writer_b.toString());
}
示例4: testRenderSingleBlockWithLocale
import com.mitchellbosecke.pebble.template.PebbleTemplate; //导入方法依赖的package包/类
@Test
public void testRenderSingleBlockWithLocale() throws PebbleException, IOException {
PebbleEngine pebble = new PebbleEngine.Builder().loader(new StringLoader()).strictVariables(false).build();
String source = "Prefix {% block block_a %}Block A{% endblock %}{% block block_b %}Block B{% endblock %} Postfix";
PebbleTemplate template = pebble.getTemplate(source);
Writer writer_a = new StringWriter();
template.evaluateBlock("block_a", writer_a, CANADA);
assertEquals("Block A", writer_a.toString());
Writer writer_b = new StringWriter();
template.evaluateBlock("block_b", writer_b, CANADA);
assertEquals("Block B", writer_b.toString());
}
示例5: testRenderSingleExtendedBlock
import com.mitchellbosecke.pebble.template.PebbleTemplate; //导入方法依赖的package包/类
@Test
public void testRenderSingleExtendedBlock() throws PebbleException, IOException {
PebbleEngine pebble = new PebbleEngine.Builder().strictVariables(true).build();
PebbleTemplate template = pebble.getTemplate("templates/single-block/template.renderextendedblock1.peb");
Writer writer_a = new StringWriter();
template.evaluateBlock("container_a", writer_a);
assertEquals("Block A extended", writer_a.toString());
Writer writer_b = new StringWriter();
template.evaluateBlock("container_b", writer_b);
assertEquals("Block B extended", writer_b.toString());
}