tempistry 是超轻量级的序列化 JavaScript 模板和先后呈现逻辑注册。
安装:
npm install tempistry
使用 temper 来编译,所以支持以下渲染引擎:
jade
ejs
hogan.js
mustache
handlebars
var tempistry = require('tempistry'); var templateString = tempistry.serialize('/my/templates/file.jade'); // you can send this to the browser as a string and call the function var clientJS = "var myTemplate = " + templateString;
var tempistry = require('tempistry'); // register functions w/ the global tempistry lib, receive the template function back var template = tempistry.register(function() { /** function string provided from server-side tempistry.serialize() call*/}); // mixin pre/post render logic tempistry.on('pre-render', function(data) { // override "name" data.name = 'asher'; }); // wire in post-render logic, receiving the data that was rendered and the html string tempistry.on('post-render', function(result) { console.log(result.data.name); // asher console.log(result.html); // html string returned from template fn }); // call the template function var html = template({ name: 'kellan' }); // name will be 'asher' in the html produced