use of org.beetl.core.Template in project beetl2.0 by javamonkey.
the class SimpleVATest method testFunctionAttribute.
@Test
public void testFunctionAttribute() throws Exception {
gt.registerFunction("userArray", new Function() {
@Override
public Object call(Object[] paras, Context ctx) {
// TODO Auto-generated method stub
return new Object[] { User.getTestUser(), "a" };
}
});
Template t = gt.getTemplate("/va/va_fun_template.html");
String str = t.render();
AssertJUnit.assertEquals(this.getFileContent("/va/va_fun_expected.html"), str);
t = gt.getTemplate("/va/va_fun_template.html");
str = t.render();
AssertJUnit.assertEquals(this.getFileContent("/va/va_fun_expected.html"), str);
}
use of org.beetl.core.Template in project beetl2.0 by javamonkey.
the class VirtualAttributeTest method testFastjosnVirtualAttribute.
@Test
public void testFastjosnVirtualAttribute() throws Exception {
String json = "{\"name\":\"lijz\",\"id\":10}";
JSONObject node = (JSONObject) JSON.parse(json);
gt.registerVirtualAttributeEval(new VirtualAttributeEval() {
@Override
public Object eval(Object o, String attributeName, Context ctx) {
return ((JSONObject) o).get(attributeName);
}
@Override
public boolean isSupport(Class c, String attributeName) {
if (c == JSONObject.class || c == JSONArray.class) {
return true;
} else {
return false;
}
}
});
String str = "${json.~name}";
Template template = gt.getTemplate(str, new StringTemplateResourceLoader());
template.binding("json", node);
String ret = template.render();
AssertJUnit.assertEquals("lijz", ret);
}
use of org.beetl.core.Template in project beetl2.0 by javamonkey.
the class ResourceLoaderTest method testExtraLoader2.
@Test
public void testExtraLoader2() throws Exception {
Map data = getData();
MapResourceLoader strLoader = new MapResourceLoader(data);
Template t = gt.getTemplate("db:2", strLoader);
String result = t.render();
AssertJUnit.assertEquals("hello", result);
}
use of org.beetl.core.Template in project beetl2.0 by javamonkey.
the class HtmlTagTest method testHolderInAttr.
@Test
public void testHolderInAttr() throws Exception {
Template t = gt.getTemplate("/tag/html8_template.html");
t.binding("a", 1);
String str = t.render();
AssertJUnit.assertEquals(this.getFileContent("/tag/html8_expected.html"), str);
t = gt.getTemplate("/tag/html8_template.html");
t.binding("a", 1);
str = t.render();
AssertJUnit.assertEquals(this.getFileContent("/tag/html8_expected.html"), str);
}
use of org.beetl.core.Template in project beetl2.0 by javamonkey.
the class HtmlTagTest method testExpTag.
@Test
public void testExpTag() throws Exception {
Template t = gt.getTemplate("/tag/html6_template.html");
String str = t.render();
AssertJUnit.assertEquals(this.getFileContent("/tag/html6_expected.html"), str);
t = gt.getTemplate("/tag/html6_template.html");
str = t.render();
AssertJUnit.assertEquals(this.getFileContent("/tag/html6_expected.html"), str);
}
Aggregations