Search in sources :

Example 1 with UnsafeCharArrayWriter

use of jetbrick.template.utils.UnsafeCharArrayWriter in project jetbrick-template-1x by subchen.

the class JetTagContext method getBodyContent.

public String getBodyContent() {
    UnsafeCharArrayWriter out = new UnsafeCharArrayWriter();
    String encoding = ctx.getEngine().getConfig().getOutputEncoding();
    try {
        render(ctx.getContext(), JetWriter.create(out, encoding));
    } catch (Throwable e) {
        handleException(e);
    }
    return out.toString();
}
Also used : UnsafeCharArrayWriter(jetbrick.template.utils.UnsafeCharArrayWriter)

Example 2 with UnsafeCharArrayWriter

use of jetbrick.template.utils.UnsafeCharArrayWriter in project jetbrick-template-1x by subchen.

the class ForDirectiveTest method forEnum.

@Test
public void forEnum() {
    JetTemplate template = engine.createTemplate("#for(item: items)${item}#end");
    UnsafeCharArrayWriter out = new UnsafeCharArrayWriter();
    JetContext context = new JetContext();
    context.put("items", MyEnum.class);
    template.render(context, out);
    Assert.assertEquals(out.toString(), "aabbccdd");
}
Also used : UnsafeCharArrayWriter(jetbrick.template.utils.UnsafeCharArrayWriter) Test(org.junit.Test)

Example 3 with UnsafeCharArrayWriter

use of jetbrick.template.utils.UnsafeCharArrayWriter in project jetbrick-template-1x by subchen.

the class GlobalVariablesTestCase method found.

@Test
public void found() throws Exception {
    JetTemplate template = engine.createTemplate("${copyright} - ${today.format('yyyy')}");
    UnsafeCharArrayWriter out = new UnsafeCharArrayWriter();
    template.render(new JetContext(), out);
    Assert.assertEquals(out.toString(), "copyright@2000-2010 - 2015");
}
Also used : UnsafeCharArrayWriter(jetbrick.template.utils.UnsafeCharArrayWriter) Test(org.junit.Test)

Example 4 with UnsafeCharArrayWriter

use of jetbrick.template.utils.UnsafeCharArrayWriter in project jetbrick-template-1x by subchen.

the class IssueTestCase method test100_2.

@Test
public void test100_2() throws Exception {
    String source = "#set(Map<String, Map<String, String>> map = {'me':{'name':'jetbrick'}})\n";
    source += "${map.me.name.length()}";
    JetTemplate template = engine.createTemplate(source);
    UnsafeCharArrayWriter out = new UnsafeCharArrayWriter();
    template.render(new JetContext(), out);
    Assert.assertEquals("8", out.toString());
}
Also used : UnsafeCharArrayWriter(jetbrick.template.utils.UnsafeCharArrayWriter) Test(org.junit.Test)

Example 5 with UnsafeCharArrayWriter

use of jetbrick.template.utils.UnsafeCharArrayWriter in project jetbrick-template-1x by subchen.

the class NoneCompileTestCase method noneCompiled.

@Test
public void noneCompiled() {
    Properties config = new Properties();
    config.put(JetConfig.COMPILE_STRATEGY, "none");
    JetEngine engine = JetEngine.create(config);
    JetTemplate template = engine.getTemplate("/template/text-plain.jetx");
    UnsafeCharArrayWriter out = new UnsafeCharArrayWriter();
    JetContext context = new JetContext();
    template.render(context, out);
    System.out.println(out.toString());
    // 在 none 的情况下,source code 还是要编译的
    template = engine.createTemplate("你好");
    out = new UnsafeCharArrayWriter();
    template.render(new JetContext(), out);
    System.out.println(out.toString());
    Assert.assertEquals(out.toString(), "你好");
}
Also used : UnsafeCharArrayWriter(jetbrick.template.utils.UnsafeCharArrayWriter) Properties(java.util.Properties) Test(org.junit.Test)

Aggregations

UnsafeCharArrayWriter (jetbrick.template.utils.UnsafeCharArrayWriter)14 Test (org.junit.Test)13 AccessControlException (java.security.AccessControlException)3 Properties (java.util.Properties)1