0.2.1 • Published 8 years ago

motors v0.2.1

Weekly downloads
1
License
ISC
Repository
github
Last release
8 years ago

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

MotorsMotors
.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.

ParamTypeDescription
mappingsObjectKeys correspond to extensions, values to engine names.
optionsObjectInstall 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

ParamTypeDefaultDescription
extStringThe extension associated with string (e.g. "coffee").
strStringThe string to be compiled.
optionsObject{}Options to be passed to rendering engine.
nextfunctionCallback 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

ParamTypeDefaultDescription
filenameStringName of file.
optionsObject{}Options to be passed to rendering engine.
nextfunctionCallback 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).

ParamTypeDescription
chainStringString 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).

ParamTypeDescription
chainStringChain 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).

ParamTypeDescription
extStringFile extension to be associated with engine.
chainStringOptional chain for creating engine.

motors.removeEngine(ext)

Removes an engine by extension.

Kind: instance method of Motors

ParamTypeDescription
extStringFile extension to for removal.

motors.hasEngine(ext) ⇒ Boolean

Determines if an engine currently exists for an extension.

Returns: Boolean - Whether engine exists.

ParamTypeDescription
extStringFile extension to check.

License

MIT

0.2.2

8 years ago

0.2.1

8 years ago

0.2.0

8 years ago

0.1.4

8 years ago

0.1.3

8 years ago

0.1.2

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago