use of org.beetl.core.Configuration in project beetl2.0 by javamonkey.
the class CompositeResourceLoaderTest method testSimple.
@Test
public void testSimple() throws Exception {
Configuration conf = Configuration.defaultConfiguration();
CompositeResourceLoader loader = new CompositeResourceLoader();
String home = System.getProperty("user.dir");
String path1 = home + "/src/test/resources/template/resourceloader/var1";
String path2 = home + "/src/test/resources/template/resourceloader/var2";
FileResourceLoader fileLoader1 = new FileResourceLoader(path1);
FileResourceLoader fileLoader2 = new FileResourceLoader(path2);
Map data = getData();
// 根据id加载
MapResourceLoader mapLoader = new MapResourceLoader(data);
loader.addResourceLoader(new StartsWithMatcher("http:").withoutPrefix(), fileLoader2);
loader.addResourceLoader(new StartsWithMatcher("db:").withoutPrefix(), mapLoader);
loader.addResourceLoader(new AllowAllMatcher(), fileLoader1);
GroupTemplate gt = new GroupTemplate(loader, conf);
Template t = gt.getTemplate("/xxx.html");
t.binding("a", "hello");
String result = t.render();
;
AssertJUnit.assertEquals("hellohello--file2:hello--db=hello", result);
}
use of org.beetl.core.Configuration in project beetl2.0 by javamonkey.
the class GroupTemplateTest method main.
public static void main(String[] args) throws Exception {
String home = System.getProperty("user.dir") + File.separator + "template" + File.separator;
Configuration cf = Configuration.defaultConfiguration();
cf.setStatementStart("<!--:");
cf.setStatementEnd("-->");
FileResourceLoader rs = new FileResourceLoader(home, cf.getCharset());
GroupTemplate gt = new GroupTemplate(rs, cf);
List<StockModel> list = StockModel.dummyItems();
Template t = gt.getTemplate("/helloworld.html");
t.binding("items", list);
StringWriter sw = new StringWriter();
t.renderTo(sw);
System.out.println(sw.toString());
// 第二次
t = gt.getTemplate("/helloworld.html");
t.binding("items", list);
sw = new StringWriter();
t.renderTo(sw);
System.out.println(sw.toString());
}
use of org.beetl.core.Configuration in project beetl2.0 by javamonkey.
the class ErrorTest method main.
public static void main(String[] args) throws Exception {
ClasspathResourceLoader resourceLoader = new ClasspathResourceLoader();
Configuration cfg = Configuration.defaultConfiguration();
GroupTemplate gt = new GroupTemplate(resourceLoader, cfg);
Template t = gt.getTemplate("/org/beetl/sample/s0125/error1.txt");
String str = t.render();
t = gt.getTemplate("/org/beetl/sample/s0125/error2.txt");
str = t.render();
System.out.println(str);
}
Aggregations