Motors
Powerful chaining of pre- and post-processors, with dynamic dependency downloading.
Installation
$ npm install motors
Examples
var motors = ; // Simple engines (extension, name)motors;motors;motors; // Chained engines (extension, chain)motors;motors;motors; { console; } // Compilemotors;motors;motors;
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 = dir : process ;
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;
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;
function
motors.createEngine(chain) ⇒ 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; motors; motors;
function
motors.getEngine(chain) ⇒ 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;
function
motors.addEngine(ext, [chain]) ⇒ 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. |
Boolean
motors.hasEngine(ext) ⇒ 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