Skip to content

How to create addon

Aleksey V. Zapparov edited this page Mar 23, 2014 · 12 revisions

Addons are often used to add specific engines support. See instructions below to create your own.

Intergation

If you create addon package with standard interface, please add mincerplugin to keywords of you package.json. That will help to search.

We strongly reccommend to provide this interface for init:

var Mincer = require('mincer');
require('my-super-addon')(Mincer);

Code example

Here is example of code, that adds JSX engine support:

'use strict';

var jsx;

module.exports = function addJsxEngine(Mincer) {
  var jsx;

  var JsxEngine = Mincer.JsxEngine = function JsxEngine() {
    Mincer.Template.apply(this, arguments);
    jsx = jsx || Mincer.Template.libs.jsx || require('react-tools')
  };

  require('util').inherits(JsxEngine, Mincer.Template);

  JsxEngine.prototype.evaluate = function evaluate(/*context, locals*/) {
     return jsx.transform(this.data);
  };

  Mincer.registerEngine('.jsx', Mincer.JsxEngine);

};

You just need to create node.js package.

Memo

  • don't forget to add README.md with usage examples
  • for package.json
    • add mincerplugin to keywords
    • add peerDependency if you need it
  • add tests if possible
Clone this wiki locally