-
Notifications
You must be signed in to change notification settings - Fork 84
How to create addon
Vitaly Puzrin edited this page Apr 2, 2014
·
12 revisions
Addons are often used to add specific engines support. See instructions below to create your own.
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);
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*/) {
this.data = jsx.transform(this.data);
// If your engine provides source map, put it here
// 1. If internal paths exists on source map, those must be RELATIVE to
// current asset folder. Usually, that's ok.
// 2. Map propetry `sourceContent` must be filled. If not - fill manually.
// this.map = <your_sourcemap>
};
Mincer.registerEngine('.jsx', Mincer.JsxEngine);
};
You just need to create node.js
package. See complete result.
- 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
- add tests if possible