tempistry

授权协议 BSD
开发语言 JavaScript
所属分类 Web应用开发、 常用JavaScript包
软件类型 开源软件
地区 不详
投 递 者 漆雕彬彬
操作系统 跨平台
开源组织 Yahoo
适用人群 未知
 软件概览

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