Java Code Examples for org.beetl.core.GroupTemplate#setSharedVars()

The following examples show how to use org.beetl.core.GroupTemplate#setSharedVars() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BeetlFrameworkConfig.java    From feiqu-opensource with Apache License 2.0 6 votes vote down vote up
@Bean
public BeetlTemplateCustomize beetlTemplateCustomize(@Qualifier("beetl_functions") Functions fn) {
    return new BeetlTemplateCustomize() {

        @Override
        public void customize(GroupTemplate groupTemplate) {
            groupTemplate.registerFunctionPackage("c", fn);
            Map vars = new HashMap<String, Object>() {{
                put("VERSION", Global.getConfig("feiqu.cssVersion"));
                put("LAYUI_VERSION", Global.getConfig("feiqu.layuiVersion"));
                put("DOMAIN_URL", Global.getConfig("feiqu.domainUrl"));
            }};
            groupTemplate.setSharedVars(vars);

        }

    };
}
 
Example 2
Source File: BeetlTest.java    From seed with Apache License 2.0 6 votes vote down vote up
@Test
public void buildFromFile() throws IOException {
    /*
    <!DOCTYPE HTML>
    <html>
    <head>
        <meta charset="UTF-8">
        <title>beetl demo</title>
    </head>
    <body>
        长篇架空武侠小说:${book},真的忍心烂尾么??
    </body>
    </html>
    */
    //使用模板文件位置实例化模板对象
    GroupTemplate groupTemplate = new GroupTemplate(new FileResourceLoader("C:/Users/Jadyer/Desktop/"), Configuration.defaultConfiguration());
    //设置模板所需的共享变量
    Map<String, Object> sharedVars = new HashMap<>();
    sharedVars.put("book", "英雄志");
    groupTemplate.setSharedVars(sharedVars);
    //模板解析成真实的HTML到文件(注意:模板文件source.html必须存在,dest.html不存在时beetl会自动创建并填充内容,dest.html存在时beetl会覆盖该文件)
    groupTemplate.getTemplate("source.html").renderTo(FileUtils.openOutputStream(new File("C:/Users/Jadyer/Desktop/dest.html")));
    //生成PDF文件
    //WkhtmltopdfUtil.convert(null, "C:/Users/Jadyer/Desktop/dest.html", "C:/Users/Jadyer/Desktop/dest.pdf");
}
 
Example 3
Source File: SharedVars.java    From beetl2.0 with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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);


}
 
Example 4
Source File: Config.java    From zooadmin with MIT License 5 votes vote down vote up
public void configConstant(Constants me) {
    me.setDevMode(false);
    JFinal3BeetlRenderFactory rf = new JFinal3BeetlRenderFactory();
    rf.config();
    me.setRenderFactory(rf);
    // 获取GroupTemplate ,可置共享变量等操作
    GroupTemplate group = rf.groupTemplate;
    Map<String, Object> shared = new HashMap<String, Object>();
    group.setSharedVars(shared);
}
 
Example 5
Source File: Config.java    From zooadmin with MIT License 5 votes vote down vote up
public void configConstant(Constants me) {
    me.setDevMode(false);
    JFinal3BeetlRenderFactory rf = new JFinal3BeetlRenderFactory();
    rf.config();
    me.setRenderFactory(rf);
    // 获取GroupTemplate ,可置共享变量等操作
    GroupTemplate group = rf.groupTemplate;
    Map<String, Object> shared = new HashMap<String, Object>();
    group.setSharedVars(shared);
}