1 Star 0 Fork 0

Bluishoul/velocityjs for expressjs

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
express_velocity.js 748 Bytes
一键复制 编辑 原始数据 按行查看 历史
Bluishoul 提交于 2013-10-22 16:50 . init update
/**
* Created with IntelliJ IDEA.
* User: Bluishoul
* Date: 13-10-22
* Time: 下午4:38
*/
var Velocity = require("velocityjs");
var fs = require('fs');
var ExpressVelocity = {};
ExpressVelocity.render = function(template,context,fn){
try{
var t1 = Date.now();
var str = context.cache
? exports.cache[template] || (exports.cache[template] = fs.readFileSync(template, 'utf8'))
: fs.readFileSync(template, 'utf8');
var tpl = Velocity.render(str,context,context && context.macros);
var t2 = Date.now();
var cost = t2 - t1;
console.log("Generated tpl in "+cost+"[ms]");
tpl +="<!-- Generated by VelocityJS (page:" +cost+ "[ms]) -->";
fn(null, tpl);
} catch (err) {
fn(err);
}
};
module.exports = ExpressVelocity;
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/bluishoul/velocityjs-for-expressjs.git
git@gitee.com:bluishoul/velocityjs-for-expressjs.git
bluishoul
velocityjs-for-expressjs
velocityjs for expressjs
master

搜索帮助