Java Code Examples for com.blade.Blade#templateEngine()

The following examples show how to use com.blade.Blade#templateEngine() . 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: Bootstrap.java    From FrameworkBenchmarks with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void load(Blade blade) {
    try {
        JetbrickTemplateEngine templateEngine = new JetbrickTemplateEngine();
        blade.templateEngine(templateEngine);

        HikariConfig config = new HikariConfig();

        String url                   = blade.env("jdbc.url", "");
        String username              = blade.env("jdbc.username", "");
        String password              = blade.env("jdbc.password", "");
        String cachePrepStmts        = blade.env("datasource.cachePrepStmts", "true");
        String prepStmtCacheSize     = blade.env("datasource.prepStmtCacheSize", "250");
        String prepStmtCacheSqlLimit = blade.env("datasource.prepStmtCacheSqlLimit", "2048");

        config.setJdbcUrl(url);
        config.setUsername(username);
        config.setPassword(password);
        config.addDataSourceProperty("cachePrepStmts", cachePrepStmts);
        config.addDataSourceProperty("prepStmtCacheSize", prepStmtCacheSize);
        config.addDataSourceProperty("prepStmtCacheSqlLimit", prepStmtCacheSqlLimit);

        HikariDataSource ds = new HikariDataSource(config);
        Anima.open(ds);
    } catch (Exception e) {
        System.out.println("Connection database fail");
    }
}
 
Example 2
Source File: WebContext.java    From tale with MIT License 4 votes vote down vote up
@Override
public void processor(Blade blade) {
    JetbrickTemplateEngine templateEngine = new JetbrickTemplateEngine();

    List<String> macros = new ArrayList<>(8);
    macros.add(File.separatorChar + "comm" + File.separatorChar + "macros.html");
    // 扫描主题下面的所有自定义宏
    String themeDir = AttachController.CLASSPATH + "templates" + File.separatorChar + "themes";
    File[] dir      = new File(themeDir).listFiles();
    for (File f : dir) {
        if (f.isDirectory() && Files.exists(Paths.get(f.getPath() + File.separatorChar + "macros.html"))) {
            String macroName = File.separatorChar + "themes" + File.separatorChar + f.getName() + File.separatorChar + "macros.html";
            macros.add(macroName);
        }
    }
    StringBuffer sbuf = new StringBuffer();
    macros.forEach(s -> sbuf.append(',').append(s));
    templateEngine.addConfig("jetx.import.macros", sbuf.substring(1));

    GlobalResolver resolver = templateEngine.getGlobalResolver();
    resolver.registerFunctions(Commons.class);
    resolver.registerFunctions(Theme.class);
    resolver.registerFunctions(AdminCommons.class);
    resolver.registerTags(JetTag.class);

    JetGlobalContext context = templateEngine.getGlobalContext();
    context.set("version", environment.get("app.version", "v1.0"));
    context.set("enableCdn", environment.getBoolean("app.enableCdn", false));

    blade.templateEngine(templateEngine);

    TaleConst.ENABLED_CDN = environment.getBoolean("app.enableCdn", false);
    TaleConst.MAX_FILE_SIZE = environment.getInt("app.max-file-size", 20480);

    TaleConst.AES_SALT = environment.get("app.salt", "012c456789abcdef");
    TaleConst.OPTIONS.addAll(optionsService.getOptions());
    String ips = TaleConst.OPTIONS.get(Types.BLOCK_IPS, "");
    if (StringKit.isNotBlank(ips)) {
        TaleConst.BLOCK_IPS.addAll(Arrays.asList(ips.split(",")));
    }
    if (Files.exists(Paths.get(AttachController.CLASSPATH + "install.lock"))) {
        TaleConst.INSTALLED = Boolean.TRUE;
    }

    BaseController.THEME = "themes/" + Commons.site_option("site_theme");

    TaleConst.BCONF = environment;
}