motors v0.2.1
Motors
Powerful chaining of pre- and post-processors, with dynamic dependency downloading.
Installation
$ npm install motors
Examples
var motors = new Motors();
// Simple engines (extension, name)
motors.addEngine("jade");
motors.addEngine("coffee");
motors.addEngine("js", "dust");
// Chained engines (extension, chain)
motors.addEngine("css", "css>clean-css");
motors.addEngine("js", "javascript>uglify-js");
motors.addEngine("jbs", "jade>handlebars");
function next(err, compiled) { console.log(compiled); }
// Compile
motors.compile("coffee", "console.log 'Hello'", next);
motors.compile("handlebars", "Hello {{ name }}", { name : "Donald" }, next);
motors.compileFile("./path-to/file.coffee", next);
API
Motors ⇒ Motors
.addEngine(ext, [chain]) ⇒ function
.compile(ext, str, [options], next)
.compileFile(filename, [options], next)
.createEngine(chain) ⇒ function
.getEngine(chain) ⇒ function
.hasEngine(ext) ⇒ Boolean
.removeEngine(ext)
Motors ⇒ Motors
Constructor for Motors class. Automatically installs packages by default.
Returns: Motors - Instance of class.
Param | Type | Description |
---|---|---|
mappings | Object | Keys correspond to extensions, values to engine names. |
options | Object | Install directory dir , and whether to fetch if missing. |
Example
var motors = new Motors({ dir : process.cwd() });
motors.compile(ext, str, options, next)
compiles a string using engine associated with ext
Param | Type | Default | Description |
---|---|---|---|
ext | String | The extension associated with string (e.g. "coffee"). | |
str | String | The string to be compiled. | |
options | Object | {} | Options to be passed to rendering engine. |
next | function | Callback of type fn(err, compiled). |
Example
motors.compile("coffee", "console.log 'Hello'", function(err, compiled) {
console.log(compiled);
// => console.log('Hello');
});
motors.compileFile(filename, options, next)
compiles a file using engine associated with file's extension
Param | Type | Default | Description |
---|---|---|---|
filename | String | Name of file. | |
options | Object | {} | Options to be passed to rendering engine. |
next | function | Callback of type fn(err, compiled). |
Example
motors.compileFile("app.coffee", function(err, compiled) {
// Compiled version of app.coffee
});
motors.createEngine(chain) ⇒ function
Returns a compilation function based on input chain.
Returns: function - Compilation function fn(str, options, next).
Param | Type | Description |
---|---|---|
chain | String | String containing names of engines to use. |
Example
motors.createEngine("jade");
motors.createEngine("jade>handlebars");
motors.createEngine("js>uglify-js");
motors.getEngine(chain) ⇒ function
Gets an engine based on chain, creating engine if necessary.
Returns: function - Compilation function fn(str, options, next).
Param | Type | Description |
---|---|---|
chain | String | Chain of engines. |
Example
motors.getEngine("jade>handlebars");
motors.addEngine(ext, chain) ⇒ function
Adds an engine for an extension, creating engine if necessary.
Returns: function - Compilation function fn(str, options, next).
Param | Type | Description |
---|---|---|
ext | String | File extension to be associated with engine. |
chain | String | Optional chain for creating engine. |
motors.removeEngine(ext)
Removes an engine by extension.
Kind: instance method of Motors
Param | Type | Description |
---|---|---|
ext | String | File extension to for removal. |
motors.hasEngine(ext) ⇒ Boolean
Determines if an engine currently exists for an extension.
Returns: Boolean - Whether engine exists.
Param | Type | Description |
---|---|---|
ext | String | File extension to check. |
License
MIT