mustem
v1.0.1
Published
A template engine based on mustache and bluebird used for rendering a buffer
Downloads
3
Readme
mustem
A template engine based on mustache and bluebird used for rendering a buffer
Installation
$ npm install --save mustem
Usage
Most usage could refer to mustache.js
Promise support
var P = require('bluebird');
var mustem = require('../');
mustem.render('3+5={{#add}}[3,5]{{/add}}', {
add: function (a, b) {
return new P(function (resolve) {
setTimeout(function () {
resolve(a + b);
}, 100);
})
}
}).then(function (result) {
console.log(result); // 3+5=8
});
Custom view for writing result to a custom buffer
We can write binary buffer by writing result to a custom buffer.
var mustem = require('../');
function CustomView() {
this.buffer = [];
this.text = function (text) {
this.buffer.push(text);
};
this.write = function (i) {
this.buffer.push(i);
};
}
var view = new CustomView();
mustem.render('The number is:{{#write}}1{{/write}}', view).then(function (result) {
console.log(view.buffer);
});
ATTENTION: Functions is not supported!!!
License
MIT © taoyuan