Search in sources :

Example 66 with Template

use of org.beetl.core.Template in project beetl2.0 by javamonkey.

the class NativeTest method testArray.

@Test
public void testArray() throws Exception {
    NativeTest test = new NativeTest();
    Template t = gt.getTemplate("/nat/nat_array_template.html");
    this.bind(t, "test", test);
    String str = t.render();
    AssertJUnit.assertEquals(this.getFileContent("/nat/nat_array_expected.html"), str);
    t = gt.getTemplate("/nat/nat_array_template.html");
    this.bind(t, "test", test);
    str = t.render();
    AssertJUnit.assertEquals(this.getFileContent("/nat/nat_array_expected.html"), str);
}
Also used : GroupTemplate(org.beetl.core.GroupTemplate) Template(org.beetl.core.Template) Test(org.testng.annotations.Test)

Example 67 with Template

use of org.beetl.core.Template in project beetl2.0 by javamonkey.

the class NativeTest method testAttr.

@Test
public void testAttr() throws Exception {
    NativeTest test = new NativeTest();
    Template t = gt.getTemplate("/nat/nat_attr_template.html");
    this.bind(t, "test", test);
    String str = t.render();
    AssertJUnit.assertEquals(this.getFileContent("/nat/nat_attr_expected.html"), str);
    t = gt.getTemplate("/nat/nat_attr_template.html");
    this.bind(t, "test", test);
    str = t.render();
    AssertJUnit.assertEquals(this.getFileContent("/nat/nat_attr_expected.html"), str);
}
Also used : GroupTemplate(org.beetl.core.GroupTemplate) Template(org.beetl.core.Template) Test(org.testng.annotations.Test)

Example 68 with Template

use of org.beetl.core.Template in project beetl2.0 by javamonkey.

the class HTMLTagSupportWrapper method callHtmlTag.

protected void callHtmlTag(String path) {
    Template t = null;
    t = gt.getHtmlFunctionOrTagTemplate(path, this.ctx.getResourceId());
    t.binding(ctx.globalVar);
    t.dynamic(ctx.objectKeys);
    if (args.length == 2) {
        Map<String, Object> map = (Map<String, Object>) args[1];
        for (Entry<String, Object> entry : map.entrySet()) {
            t.binding(entry.getKey(), entry.getValue());
        }
    }
    BodyContent bodyContent = super.getBodyContent();
    t.binding("tagBody", bodyContent);
    t.renderTo(ctx.byteWriter);
}
Also used : BodyContent(org.beetl.core.BodyContent) Map(java.util.Map) Template(org.beetl.core.Template)

Example 69 with Template

use of org.beetl.core.Template in project hello-world by haoziapple.

the class BasicUse method main.

public static void main(String[] args) throws Exception {
    StringTemplateResourceLoader resourceLoader = new StringTemplateResourceLoader();
    Configuration cfg = Configuration.defaultConfiguration();
    GroupTemplate gt = new GroupTemplate(resourceLoader, cfg);
    Template t = gt.getTemplate("hello,${name}");
    t.binding("name", "beetl");
    String str = t.render();
    System.out.println(str);
}
Also used : Configuration(org.beetl.core.Configuration) StringTemplateResourceLoader(org.beetl.core.resource.StringTemplateResourceLoader) GroupTemplate(org.beetl.core.GroupTemplate) GroupTemplate(org.beetl.core.GroupTemplate) Template(org.beetl.core.Template)

Example 70 with Template

use of org.beetl.core.Template in project vip by guangdada.

the class GunsTemplateEngine method generateFile.

public void generateFile(String template, String filePath) {
    Template pageTemplate = groupTemplate.getTemplate(template);
    configTemplate(pageTemplate);
    // filePath = filePath.replaceAll("\\\\",File.separator);
    File file = new File(filePath);
    File parentFile = file.getParentFile();
    if (!parentFile.exists()) {
        parentFile.mkdirs();
    }
    try {
        pageTemplate.renderTo(new FileOutputStream(file));
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) File(java.io.File) GroupTemplate(org.beetl.core.GroupTemplate) Template(org.beetl.core.Template)

Aggregations

Template (org.beetl.core.Template)122 Test (org.testng.annotations.Test)96 GroupTemplate (org.beetl.core.GroupTemplate)41 Map (java.util.Map)15 User (org.beetl.core.User)14 HashMap (java.util.HashMap)13 Configuration (org.beetl.core.Configuration)13 FileResourceLoader (org.beetl.core.resource.FileResourceLoader)6 StringTemplateResourceLoader (org.beetl.core.resource.StringTemplateResourceLoader)6 Context (org.beetl.core.Context)5 JSONObject (com.alibaba.fastjson.JSONObject)4 List (java.util.List)4 ClasspathResourceLoader (org.beetl.core.resource.ClasspathResourceLoader)4 VirtualAttributeEval (org.beetl.core.VirtualAttributeEval)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 BodyContent (org.beetl.core.BodyContent)2 BeetlException (org.beetl.core.exception.BeetlException)2 WebRender (org.beetl.ext.web.WebRender)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1