mustem

1.0.1 • Public • Published

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(+ 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

Package Sidebar

Install

npm i mustem

Weekly Downloads

0

Version

1.0.1

License

MIT

Last publish

Collaborators

  • taoyuan
  • torworx