tempistry
ultra light-weight registry for serializing javascript templates and applying pre/post render logic
Install
npm install tempistry
Uses temper for compilation, so supports the following rendering engines:
- jade
- ejs
- hogan.js
- mustache
- handlebars
Server Side
var tempistry = ; var templateString = tempistry; // you can send this to the browser as a string and call the functionvar clientJS = "var myTemplate = " + templateString;
You can also grab the full template data object that temper provides by passing true as the second param
var data = tempistry;
Browserify Transform
If you're using Browserify, the easiest way to plug tempistry into your pipeline is via the included transform, tempistry/transform
. You can then require your template files directly and have them automatically registered with tempistry.
# Via cli browserify -t tempistry/transform main.js
// Via apivar b = ;
// register pre-render hookvar tempistry = ; tempistry; var template = ; // *helpers* will be available in the template due to the pre-render hook abovevar html = ;
Client-Side
Tempistry runs in the browser w/ browserify and acts as a registry to hook pre/post render logic into. This is useful for mixing in common view data such as formatting helpers. It works well when combined with the server side serialize()
function, but you can register any function you want with it.
var tempistry = ; // register functions w/ the global tempistry lib, receive the template function backvar template = tempistry; // mixin pre/post render logictempistry; // wire in post-render logic, receiving the data that was rendered and the html stringtempistry; // call the template functionvar html = ; // name will be 'asher' in the html produced
License
This software is free to use under the Yahoo! Inc. BSD license. See the LICENSE file for license text and copyright information.
Third-pary open source code used are listed in our package.json file.