Skip to content

How to create addon

Vitaly Puzrin 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 mincer-contrib 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';

// Second param is not mandatory, used only to force specific
// module version when nested dependencies cause conflict.
module.exports = function addJsxEngine(Mincer, 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 mincer-contrib to keywords
    • add peerDependency if you need it
  • add tests if possible
Clone this wiki locally