Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

How to create addon

Matt Winchester edited this page · 12 revisions
Clone this wiki locally

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

Integration

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*/) {
     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>


     // If your source can have dependencies, and engine can return
     // dependencies list, add pass path for automatic tracking.

     // context.dependOn(file1);
     // context.dependOn(file2);
  };

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

};

You just need to create node.js package. See complete result.

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
Something went wrong with that request. Please try again.