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


Java PebbleException类代码示例

本文整理汇总了Java中com.mitchellbosecke.pebble.error.PebbleException的典型用法代码示例。如果您正苦于以下问题:Java PebbleException类的具体用法?Java PebbleException怎么用?Java PebbleException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


PebbleException类属于com.mitchellbosecke.pebble.error包,在下文中一共展示了PebbleException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testDynamicInheritance

import com.mitchellbosecke.pebble.error.PebbleException; //导入依赖的package包/类
@Test
public void testDynamicInheritance() throws PebbleException, IOException {
	PebbleEngine pebble = new PebbleEngine.Builder().strictVariables(false).build();
	PebbleTemplate template = pebble.getTemplate("templates/template.dynamicChild.peb");
	Map<String, Object> context = new HashMap<>();
	context.put("extendNumberOne", true);

	Writer writer1 = new StringWriter();
	template.evaluate(writer1, context);
	assertEquals("ONE", writer1.toString());

	Writer writer2 = new StringWriter();
	context.put("extendNumberOne", false);
	template.evaluate(writer2, context);
	assertEquals("TWO", writer2.toString());
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:17,代码来源:InheritanceTest.java

示例2: testLast

import com.mitchellbosecke.pebble.error.PebbleException; //导入依赖的package包/类
@Test
public void testLast() throws PebbleException, IOException {
    PebbleEngine pebble = new PebbleEngine.Builder().loader(new StringLoader()).strictVariables(false).build();

    PebbleTemplate template = pebble.getTemplate("{{ names | last }}");

    List<String> names = new ArrayList<>();
    names.add("Alex");
    names.add("Joe");
    names.add("Bob");

    Map<String, Object> context = new HashMap<>();
    context.put("names", names);

    Writer writer = new StringWriter();
    template.evaluate(writer, context);
    assertEquals("Bob", writer.toString());
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:19,代码来源:CoreFiltersTest.java

示例3: testAccessingValueWithSubscript

import com.mitchellbosecke.pebble.error.PebbleException; //导入依赖的package包/类
@SuppressWarnings("serial")
@Test
public void testAccessingValueWithSubscript() throws PebbleException, IOException {
    PebbleEngine pebble = new PebbleEngine.Builder().loader(new StringLoader()).strictVariables(false).build();

    String source = "{{ person['first-name'] }}";
    PebbleTemplate template = pebble.getTemplate(source);

    Map<String, Object> context = new HashMap<>();
    context.put("person", new HashMap<String, Object>() {

        {
            put("first-name", "Bob");
        }
    });

    Writer writer = new StringWriter();
    template.evaluate(writer, context);
    assertEquals("Bob", writer.toString());
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:21,代码来源:AttributeSubscriptSyntaxTest.java

示例4: apply

import com.mitchellbosecke.pebble.error.PebbleException; //导入依赖的package包/类
@Override
public Object apply(Object input, Map<String, Object> args, PebbleTemplate self, EvaluationContext context, int lineNumber) throws PebbleException{
    if (input == null) {
        return null;
    }
    if (!(input instanceof Number)) {
        throw new PebbleException(null, "The input for the 'NumberFormat' filter has to be a number.", lineNumber, self.getName());
    }

    Number number = (Number) input;

    Locale locale = context.getLocale();

    if (args.get("format") != null) {
        Format format = new DecimalFormat((String) args.get("format"), new DecimalFormatSymbols(locale));
        return format.format(number);
    } else {
        NumberFormat numberFormat = NumberFormat.getInstance(locale);
        return numberFormat.format(number);
    }
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:22,代码来源:NumberFormatFilter.java

示例5: resolve

import com.mitchellbosecke.pebble.error.PebbleException; //导入依赖的package包/类
@Override
public Optional<ResolvedAttribute> resolve(final Object instance, final Object attribute, Object[] argumentValues,
        boolean isStrictVariables, final String filename, final int lineNumber) throws PebbleException {
    if (argumentValues==null) {
        if (instance instanceof Map) {
            return Optional.<ResolvedAttribute>of(new ResolvedAttribute() {
                
                @Override
                public Object evaluate() throws PebbleException {
                    return getObjectFromMap((Map<?, ?>) instance, attribute, filename, lineNumber);
                }
            });
        }
    }
    return Optional.empty();
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:17,代码来源:MapResolver.java

示例6: testMethodAttributeWithDifferentObjects

import com.mitchellbosecke.pebble.error.PebbleException; //导入依赖的package包/类
/**
 * The GetAttribute expression involves caching, we test with different
 * objects to make sure that the caching doesnt have any negative side
 * effects.
 *
 * @throws PebbleException
 * @throws IOException
 */
@Test
public void testMethodAttributeWithDifferentObjects() throws PebbleException, IOException {
    PebbleEngine pebble = new PebbleEngine.Builder().loader(new StringLoader()).strictVariables(true).build();
    PebbleTemplate template = pebble.getTemplate("hello {{ object.name }}");

    Map<String, Object> context1 = new HashMap<>();
    context1.put("object", new CustomizableObject("Alex"));
    Writer writer1 = new StringWriter();
    template.evaluate(writer1, context1);
    assertEquals("hello Alex", writer1.toString());

    Map<String, Object> context2 = new HashMap<>();
    context2.put("object", new CustomizableObject("Steve"));
    Writer writer2 = new StringWriter();
    template.evaluate(writer2, context2);
    assertEquals("hello Steve", writer2.toString());
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:26,代码来源:GetAttributeTest.java

示例7: cast

import com.mitchellbosecke.pebble.error.PebbleException; //导入依赖的package包/类
private static Object cast(Number number, Class<?> desiredType, String filename, int lineNumber) throws PebbleException {
    if (desiredType == Long.class) {
        return number.longValue();
    } else if (desiredType == Integer.class) {
        return number.intValue();
    } else if (desiredType == Double.class) {
        return number.doubleValue();
    } else if (desiredType == Float.class) {
        return number.floatValue();
    } else if (desiredType == Short.class) {
        return number.shortValue();
    } else if (desiredType == Byte.class) {
        return number.byteValue();
    }
    throw new PebbleException(null, String.format("type %s not supported for key %s", desiredType, number), lineNumber, filename);
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:17,代码来源:MapResolver.java

示例8: testDefinedWithMap

import com.mitchellbosecke.pebble.error.PebbleException; //导入依赖的package包/类
/**
 * Tests if the test function 'defined' is working on maps.
 */
@Test
public void testDefinedWithMap() throws PebbleException, IOException {
    PebbleEngine pebble = new PebbleEngine.Builder().loader(new StringLoader()).strictVariables(true).build();

    String source = "{% if test.test is defined %}yes{% else %}no{% endif %}{% if test.test2 is defined %}no{% else %}yes{% endif %}";
    PebbleTemplate template = pebble.getTemplate(source);

    Writer writer = new StringWriter();
    Map<String, Object> context = new HashMap<>();

    Map<String, Object> map = new HashMap<>();
    map.put("test", "yes");
    context.put("test", map);
    template.evaluate(writer, context);
    assertEquals("yesyes", writer.toString());
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:20,代码来源:CoreTestsTest.java

示例9: templatesWithSameNameOverridingCache

import com.mitchellbosecke.pebble.error.PebbleException; //导入依赖的package包/类
/**
 * There was once an issue where the cache was unable to differentiate
 * between templates of the same name but under different directories.
 * 
 * @throws PebbleException
 */
@Test
public void templatesWithSameNameOverridingCache() throws PebbleException, IOException {
	PebbleEngine engine = new PebbleEngine.Builder().strictVariables(false).build();

	PebbleTemplate cache1 = engine.getTemplate("templates/cache/cache1/template.cache.peb");
	PebbleTemplate cache2 = engine.getTemplate("templates/cache/cache2/template.cache.peb");

	Writer writer1 = new StringWriter();
	Writer writer2 = new StringWriter();

	cache1.evaluate(writer1);
	cache2.evaluate(writer2);

	String cache1Output = writer1.toString();
	String cache2Output = writer2.toString();

	assertFalse(cache1Output.equals(cache2Output));

}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:26,代码来源:CacheTest.java

示例10: testFunctionInMacroInvokedTwice

import com.mitchellbosecke.pebble.error.PebbleException; //导入依赖的package包/类
@Test
public void testFunctionInMacroInvokedTwice() throws PebbleException, IOException {

    TestingExtension extension = new TestingExtension();
    PebbleEngine pebble = new PebbleEngine.Builder().loader(new StringLoader()).strictVariables(false)
            .extension(extension).build();

    PebbleTemplate template = pebble
            .getTemplate("{{ test() }}{% macro test() %}{{ invocationCountingFunction() }}{% endmacro %}");

    Writer writer = new StringWriter();
    template.evaluate(writer);

    InvocationCountingFunction function = extension.getInvocationCountingFunction();
    assertEquals(1, function.getInvocationCount());
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:17,代码来源:MacroTest.java

示例11: testForWhenInvalidOrNoEndforTag

import com.mitchellbosecke.pebble.error.PebbleException; //导入依赖的package包/类
@Test
public void testForWhenInvalidOrNoEndforTag() throws PebbleException, IOException {
    PebbleEngine pebble = new PebbleEngine.Builder().loader(new StringLoader()).strictVariables(false).build();
    String source = "{% for i in 'a'..5 %}{{i}}% endfor %}";
    try {
        pebble.getTemplate(source);

        fail("Should fail due to invalid endfor tag");
    } catch (RuntimePebbleException ex) {
        assertTrue(ex.getCause() instanceof ParserException);
        ParserException parserException = (ParserException) ex.getCause();
        assertEquals(parserException.getPebbleMessage(), "Unexpected end of template. Pebble was looking for the \"endfor\" tag");
        assertEquals(parserException.getLineNumber(), (Integer) 1);
        assertEquals(parserException.getFileName(), source);
    }
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:17,代码来源:CoreTagsTest.java

示例12: testComparisons

import com.mitchellbosecke.pebble.error.PebbleException; //导入依赖的package包/类
@Test
public void testComparisons() throws PebbleException, IOException {
    
    PebbleEngine pebble = new PebbleEngine.Builder().loader(new StringLoader()).strictVariables(false).build();

    String source = "{% if 3 > 2 %}yes{% endif %}" +
                    "{% if 2 > 3 %}no{% endif %}" +
                    "{% if 2 > 2 %}no{% endif %}" +
                    "{% if 2 < 3 %}yes{% endif %}" +
                    "{% if 3 < 2 %}no{% endif %}" +
                    "{% if 2 < 2 %}no{% endif %}" +
                    "{% if 3 >= 3 %}yes{% endif %}" +
                    "{% if 3 >= 2 %}yes{% endif %}" +
                    "{% if 2 >= 3 %}no{% endif %}" +
                    "{% if 3 <= 3 %}yes{% endif %}" +
                    "{% if 3 <= 2 %}no{% endif %}" +
                    "{% if 2 <= 3 %}yes{% endif %}" +
                    "{% if 100 <= 100 %}yes{% endif %}" +
                    "{% if 2 == 2 %}yes{% endif %}" +
                    "{% if 2 == 3 %}no{% endif %}";
    PebbleTemplate template = pebble.getTemplate(source);

    Writer writer = new StringWriter();
    template.evaluate(writer);
    assertEquals("yesyesyesyesyesyesyesyes", writer.toString());
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:27,代码来源:LogicTest.java

示例13: testCustomEscapingStrategy

import com.mitchellbosecke.pebble.error.PebbleException; //导入依赖的package包/类
@Test
public void testCustomEscapingStrategy() throws PebbleException, IOException {
    PebbleEngine pebble = new PebbleEngine.Builder().loader(new StringLoader()).strictVariables(false)
            .defaultEscapingStrategy("custom").addEscapingStrategy("custom", new EscapingStrategy() {

                @Override
                public String escape(String input) {
                    return input.replace('a', 'b');
                }
            }).build();

    // replaces all a's with b's
    PebbleTemplate template = pebble.getTemplate("{{ text }}");
    Map<String, Object> context = new HashMap<>();
    context.put("text", "my name is alex");
    Writer writer = new StringWriter();
    template.evaluate(writer, context);
    assertEquals("my nbme is blex", writer.toString());
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:20,代码来源:EscaperExtensionTest.java

示例14: render

import com.mitchellbosecke.pebble.error.PebbleException; //导入依赖的package包/类
@Override
public void render(PebbleTemplateImpl self, Writer writer, EvaluationContextImpl context) throws PebbleException,
        IOException {
    String templateName = (String) includeExpression.evaluate(self, context);

    Map<?, ?> map = Collections.emptyMap();
    if (this.mapExpression != null) {
        map = this.mapExpression.evaluate(self, context);
    }

    if (templateName == null) {
        throw new PebbleException(
                null,
                String.format(
                        "The template name in an include tag evaluated to NULL. If the template name is static, make sure to wrap it in quotes.",
                        templateName), getLineNumber(), self.getName());
    }
    self.includeTemplate(writer, context, templateName, map);
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:20,代码来源:IncludeNode.java

示例15: testMacroSafeStringConcatenation

import com.mitchellbosecke.pebble.error.PebbleException; //导入依赖的package包/类
/**
 * Tests if the macro output SafeString concatenation is working.
 */
@Test
public void testMacroSafeStringConcatenation() throws PebbleException, IOException {

    PebbleEngine pebble = new PebbleEngine.Builder().loader(new StringLoader()).strictVariables(false).build();

    String source = "{% macro macro1() %}Bob{% endmacro %}\n"
                  + "{% macro macro2() %}Maria{% endmacro %}\n"
                  + "{% macro macro3() %}John{% endmacro %}\n"
                  + "{{ (macro1() + macro2() + macro3()) | lower }}";
    PebbleTemplate template = pebble.getTemplate(source);

    Map<String, Object> context = new HashMap<>();

    Writer writer = new StringWriter();
    template.evaluate(writer, context);
    assertEquals("bobmariajohn", writer.toString());

}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:22,代码来源:LogicTest.java


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