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


Java PebbleTemplate.evaluateBlock方法代码示例

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

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

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

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

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


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