Search in sources :

Example 16 with Template

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

the class SharedVars method main.

public static void main(String[] args) throws Exception {
    ClasspathResourceLoader resourceLoader = new ClasspathResourceLoader();
    Configuration cfg = Configuration.defaultConfiguration();
    GroupTemplate gt = new GroupTemplate(resourceLoader, cfg);
    Map<String, Object> shared = new HashMap<String, Object>();
    shared.put("name", "beetl");
    gt.setSharedVars(shared);
    Template t = gt.getTemplate("/org/beetl/sample/s0208/t1.txt");
    String str = t.render();
    System.out.println(str);
    t = gt.getTemplate("/org/beetl/sample/s0208/t2.txt");
    str = t.render();
    System.out.println(str);
}
Also used : Configuration(org.beetl.core.Configuration) HashMap(java.util.HashMap) ClasspathResourceLoader(org.beetl.core.resource.ClasspathResourceLoader) GroupTemplate(org.beetl.core.GroupTemplate) GroupTemplate(org.beetl.core.GroupTemplate) Template(org.beetl.core.Template)

Example 17 with Template

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

the class RegisterFunctionByFile method main.

public static void main(String[] args) throws Exception {
    String root = System.getProperty("user.dir") + File.separator + "template";
    FileResourceLoader resourceLoader = new FileResourceLoader(root, "utf-8");
    Configuration cfg = Configuration.defaultConfiguration();
    GroupTemplate gt = new GroupTemplate(resourceLoader, cfg);
    gt.registerFunctionPackage("t", new FunctionPackage());
    Template t = gt.getTemplate("/s32/functionPackage.html");
    String str = t.render();
    System.out.println(str);
}
Also used : Configuration(org.beetl.core.Configuration) FileResourceLoader(org.beetl.core.resource.FileResourceLoader) GroupTemplate(org.beetl.core.GroupTemplate) GroupTemplate(org.beetl.core.GroupTemplate) Template(org.beetl.core.Template)

Example 18 with Template

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

the class RegisterFunctionPackage method main.

public static void main(String[] args) throws Exception {
    String root = System.getProperty("user.dir") + File.separator + "template";
    FileResourceLoader resourceLoader = new FileResourceLoader(root, "utf-8");
    Configuration cfg = Configuration.defaultConfiguration();
    GroupTemplate gt = new GroupTemplate(resourceLoader, cfg);
    Template t = gt.getTemplate("/s32/pagefunction.html");
    String str = t.render();
    System.out.println(str);
}
Also used : Configuration(org.beetl.core.Configuration) FileResourceLoader(org.beetl.core.resource.FileResourceLoader) GroupTemplate(org.beetl.core.GroupTemplate) GroupTemplate(org.beetl.core.GroupTemplate) Template(org.beetl.core.Template)

Example 19 with Template

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

the class ResourceLoaderTest method testRemove.

@Test
public void testRemove() throws Exception {
    Map data = getData();
    MapResourceLoader strLoader = new MapResourceLoader(data);
    Template t = gt.getTemplate("db:2", strLoader);
    String result = t.render();
    gt.removeTemplate("db:2");
    AssertJUnit.assertEquals(false, gt.hasTemplate("db:2"));
}
Also used : Map(java.util.Map) HashMap(java.util.HashMap) Template(org.beetl.core.Template) Test(org.testng.annotations.Test)

Example 20 with Template

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

the class ResourceLoaderTest method testExtraLoader.

@Test
public void testExtraLoader() throws Exception {
    Map data = getData();
    MapResourceLoader strLoader = new MapResourceLoader(data);
    Template t = gt.getTemplate("db:1", strLoader);
    t.binding("a", "abc");
    String result = t.render();
    AssertJUnit.assertEquals("abc", result);
}
Also used : Map(java.util.Map) HashMap(java.util.HashMap) Template(org.beetl.core.Template) Test(org.testng.annotations.Test)

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