1.0.1 • Published 8 years ago

mustem v1.0.1

Weekly downloads
1
License
MIT
Repository
github
Last release
8 years ago

mustem NPM version Build Status Dependency Status Coverage percentage

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