consolidate
Advanced tools
Comparing version 0.15.1 to 0.16.0
@@ -117,9 +117,9 @@ 'use strict'; | ||
if (!options.partials) return cb(); | ||
var partials = options.partials; | ||
var keys = Object.keys(partials); | ||
var keys = Object.keys(options.partials); | ||
var partials = {}; | ||
function next(index) { | ||
if (index === keys.length) return cb(null); | ||
if (index === keys.length) return cb(null, partials); | ||
var key = keys[index]; | ||
var partialPath = partials[key]; | ||
var partialPath = options.partials[key]; | ||
@@ -143,3 +143,3 @@ if (partialPath === undefined || partialPath === null || partialPath === false) { | ||
if (err) return cb(err); | ||
options.partials[key] = str; | ||
partials[key] = str; | ||
next(++index); | ||
@@ -176,10 +176,13 @@ }); | ||
return promisify(cb, function(cb) { | ||
readPartials(path, options, function(err) { | ||
readPartials(path, options, function(err, partials) { | ||
var extend = (requires.extend || (requires.extend = require('util')._extend)); | ||
var opts = extend({}, options); | ||
opts.partials = partials; | ||
if (err) return cb(err); | ||
if (cache(options)) { | ||
exports[name].render('', options, cb); | ||
if (cache(opts)) { | ||
exports[name].render('', opts, cb); | ||
} else { | ||
read(path, options, function(err, str) { | ||
read(path, opts, function(err, str) { | ||
if (err) return cb(err); | ||
exports[name].render(str, options, cb); | ||
exports[name].render(str, opts, cb); | ||
}); | ||
@@ -565,2 +568,55 @@ } | ||
/** | ||
* Razor support. | ||
*/ | ||
exports.razor = function(path, options, cb) { | ||
return promisify(cb, function(cb) { | ||
var engine = requires.razor; | ||
if (!engine) { | ||
try { | ||
engine = requires.razor = require('razor-tmpl'); | ||
} catch (err) { | ||
throw err; | ||
} | ||
} | ||
try { | ||
var tmpl = cache(options) || cache(options, (locals) => { | ||
console.log('Rendering razor file', path); | ||
return engine.renderFileSync(path, locals); | ||
}); | ||
cb(null, tmpl(options)); | ||
} catch (err) { | ||
cb(err); | ||
} | ||
}); | ||
}; | ||
/** | ||
* razor string support. | ||
*/ | ||
exports.razor.render = function(str, options, cb) { | ||
return promisify(cb, function(cb) { | ||
try { | ||
var engine = requires.razor = require('razor-tmpl'); | ||
} catch (err) { | ||
throw err; | ||
} | ||
try { | ||
var tf = engine.compile(str); | ||
var tmpl = cache(options) || cache(options, tf); | ||
cb(null, tmpl(options)); | ||
} catch (err) { | ||
cb(err); | ||
} | ||
}); | ||
}; | ||
/** | ||
* Atpl support. | ||
@@ -623,3 +679,6 @@ */ | ||
var templateData = { | ||
data: str | ||
data: str, | ||
allowInlineIncludes: options.allowInlineIncludes, | ||
namespaces: options.namespaces, | ||
path: options.path | ||
}; | ||
@@ -902,5 +961,7 @@ try { | ||
try { | ||
const partials = {}; | ||
for (var partial in options.partials) { | ||
options.partials[partial] = engine.template(options.partials[partial]); | ||
partials[partial] = engine.template(options.partials[partial]); | ||
} | ||
options.partials = partials; | ||
var tmpl = cache(options) || cache(options, engine.template(str, null, options)); | ||
@@ -1053,3 +1114,3 @@ cb(null, tmpl(options).replace(/\n$/, '')); | ||
try { | ||
cb(null, engine.to_html(str, options, options.partials)); | ||
cb(null, engine.render(str, options, options.partials)); | ||
} catch (err) { | ||
@@ -1684,4 +1745,56 @@ cb(err); | ||
/** | ||
* Squirrelly support. | ||
*/ | ||
exports.squirrelly = fromStringRenderer('squirrelly'); | ||
/** | ||
* Squirrelly string support. | ||
*/ | ||
exports.squirrelly.render = function(str, options, cb) { | ||
return promisify(cb, function(cb) { | ||
var engine = requires.squirrelly || (requires.squirrelly = require('squirrelly')); | ||
try { | ||
for (var partial in options.partials) { | ||
engine.definePartial(partial, options.partials[partial]); | ||
} | ||
for (var helper in options.helpers) { | ||
engine.defineHelper(helper, options.helpers[helper]); | ||
} | ||
var tmpl = cache(options) || cache(options, engine.Compile(str, options)); | ||
cb(null, tmpl(options, engine)); | ||
} catch (err) { | ||
cb(err); | ||
} | ||
}); | ||
}; | ||
/** | ||
* Twing support. | ||
*/ | ||
exports.twing = fromStringRenderer('twing'); | ||
/** | ||
* Twing string support. | ||
*/ | ||
exports.twing.render = function(str, options, cb) { | ||
return promisify(cb, function(cb) { | ||
var engine = requires.twing || (requires.twing = require('twing')); | ||
try { | ||
new engine.TwingEnvironment(new engine.TwingLoaderNull()).createTemplate(str).then((twingTemplate) => { | ||
twingTemplate.render(options).then((rendTmpl) => { | ||
var tmpl = cache(options) || cache(options, rendTmpl); | ||
cb(null, tmpl); | ||
}); | ||
}); | ||
} catch (err) { | ||
cb(err); | ||
} | ||
}); | ||
}; | ||
/** | ||
* expose the instance of the engine | ||
*/ | ||
exports.requires = requires; |
{ | ||
"name": "consolidate", | ||
"description": "Template engine consolidation library", | ||
"version": "0.15.1", | ||
"version": "0.16.0", | ||
"homepage": "https://github.com/tj/consolidate.js", | ||
@@ -26,60 +26,64 @@ "author": "TJ Holowaychuk <tj@vision-media.ca>", | ||
"dependencies": { | ||
"bluebird": "^3.1.1" | ||
"bluebird": "^3.7.2" | ||
}, | ||
"devDependencies": { | ||
"arc-templates": "^0.5.1", | ||
"arc-templates": "^0.5.3", | ||
"atpl": ">=0.7.6", | ||
"babel-core": "^6.7.6", | ||
"babel-preset-react": "^6.5.0", | ||
"bracket-template": "^1.1.4", | ||
"coffee-script": "^1.11.1", | ||
"dot": "^1.0.1", | ||
"babel-core": "^6.26.3", | ||
"babel-preset-react": "^6.24.1", | ||
"bracket-template": "^1.1.5", | ||
"coffee-script": "^1.12.7", | ||
"dot": "^1.1.3", | ||
"dust": "^0.3.0", | ||
"dustjs-helpers": "^1.1.1", | ||
"dustjs-linkedin": "^2.7.2", | ||
"dustjs-helpers": "^1.7.4", | ||
"dustjs-linkedin": "^2.7.5", | ||
"eco": "^1.1.0-rc-3", | ||
"ect": "^0.5.9", | ||
"ejs": "^2.3.4", | ||
"eslint": "^3.7.1", | ||
"eslint-config-standard": "^6.2.0", | ||
"eslint-plugin-promise": "^3.3.1", | ||
"eslint-plugin-standard": "^2.0.1", | ||
"haml-coffee": "^1.4.0", | ||
"ejs": "^3.1.5", | ||
"eslint": "^7.8.1", | ||
"eslint-config-standard": "^14.1.1", | ||
"eslint-plugin-promise": "^4.2.1", | ||
"eslint-plugin-standard": "^4.0.1", | ||
"haml-coffee": "^1.14.1", | ||
"hamlet": "^0.3.3", | ||
"hamljs": "^0.6.1", | ||
"handlebars": "^4.0.5", | ||
"hamljs": "^0.6.2", | ||
"handlebars": "^4.7.6", | ||
"hogan.js": "^3.0.2", | ||
"htmling": "^0.0.7", | ||
"jade": "^1.9.1", | ||
"htmling": "^0.0.8", | ||
"jade": "^1.11.0", | ||
"jazz": "^0.0.18", | ||
"jqtpl": "~1.1.0", | ||
"just": "^0.1.8", | ||
"liquid-node": "^2.6.1", | ||
"liquid-node": "^3.0.1", | ||
"liquor": "^0.0.5", | ||
"lodash": "^4.0.0", | ||
"marko": "^3.12.0", | ||
"mocha": "^3.1.2", | ||
"lodash": "^4.17.20", | ||
"marko": "^3.14.4", | ||
"mocha": "^3.5.3", | ||
"mote": "^0.2.0", | ||
"mustache": "^2.2.1", | ||
"nunjucks": "^3.0.0", | ||
"plates": "~0.4.8", | ||
"pug": "^2.0.0-beta6", | ||
"mustache": "^4.0.1", | ||
"nunjucks": "^3.2.2", | ||
"plates": "~0.4.11", | ||
"pug": "^3.0.0", | ||
"qejs": "^3.0.5", | ||
"ractive": "^0.8.4", | ||
"react": "^15.3.2", | ||
"react-dom": "^15.3.2", | ||
"ractive": "^1.3.12", | ||
"razor-tmpl": "^1.3.1", | ||
"react": "^16.13.1", | ||
"react-dom": "^16.13.1", | ||
"semver": "^7.3.2", | ||
"should": "*", | ||
"slm": "^0.5.0", | ||
"swig-templates": "^2.0.2", | ||
"swig": "^1.4.1", | ||
"slm": "^2.0.0", | ||
"squirrelly": "^5.1.0", | ||
"swig": "^1.4.2", | ||
"swig-templates": "^2.0.3", | ||
"teacup": "^2.0.0", | ||
"templayed": ">=0.2.3", | ||
"tinyliquid": "^0.2.30", | ||
"toffee": "^0.1.12", | ||
"twig": "^0.10.0", | ||
"underscore": "^1.3.3", | ||
"vash": "^0.12.2", | ||
"tinyliquid": "^0.2.34", | ||
"toffee": "^0.3.6", | ||
"twig": "^1.15.2", | ||
"twing": "^5.0.2", | ||
"underscore": "^1.11.0", | ||
"vash": "^0.13.0", | ||
"velocityjs": "^2.0.1", | ||
"walrus": "^0.10.1", | ||
"whiskers": "^0.4.0", | ||
"velocityjs": "^0.8.2" | ||
"whiskers": "^0.4.0" | ||
}, | ||
@@ -86,0 +90,0 @@ "keywords": [ |
101
Readme.md
@@ -8,47 +8,60 @@ # Consolidate.js | ||
$ npm install consolidate | ||
## Supported Express versions | ||
- [Express 4.x](https://expressjs.com/fr/4x/api.html) | ||
- [Express 3.x](https://expressjs.com/fr/3x/api.html) | ||
## Supported template engines | ||
- [atpl](https://github.com/soywiz/atpl.js) | ||
- [bracket](https://github.com/danlevan/bracket-template) | ||
- [doT.js](https://github.com/olado/doT) [(website)](http://olado.github.io/doT/) | ||
- [dust (unmaintained)](https://github.com/akdubya/dustjs) [(website)](http://akdubya.github.com/dustjs/) | ||
- [dustjs-linkedin (maintained fork of dust)](https://github.com/linkedin/dustjs) [(website)](http://linkedin.github.io/dustjs/) | ||
- [eco](https://github.com/sstephenson/eco) | ||
- [ect](https://github.com/baryshev/ect) [(website)](http://ectjs.com/) | ||
- [ejs](https://github.com/mde/ejs) [(website)](http://ejs.co/) | ||
- [haml](https://github.com/visionmedia/haml.js) | ||
- [haml-coffee](https://github.com/9elements/haml-coffee) | ||
- [hamlet](https://github.com/gregwebs/hamlet.js) | ||
- [handlebars](https://github.com/wycats/handlebars.js/) [(website)](http://handlebarsjs.com/) | ||
- [hogan](https://github.com/twitter/hogan.js) [(website)](http://twitter.github.com/hogan.js/) | ||
- [htmling](https://github.com/codemix/htmling) | ||
- [jade](https://github.com/visionmedia/jade) [(website)](http://jade-lang.com/) | ||
- [jazz](https://github.com/shinetech/jazz) | ||
- [jqtpl](https://github.com/kof/jqtpl) | ||
- [JUST](https://github.com/baryshev/just) | ||
- [liquor](https://github.com/chjj/liquor) | ||
- [lodash](https://github.com/bestiejs/lodash) [(website)](http://lodash.com/) | ||
- [marko](https://github.com/marko-js/marko) [(website)](http://markojs.com) | ||
- [mote](https://github.com/satchmorun/mote) [(website)](http://satchmorun.github.io/mote/) | ||
- [mustache](https://github.com/janl/mustache.js) | ||
- [nunjucks](https://github.com/mozilla/nunjucks) [(website)](https://mozilla.github.io/nunjucks) | ||
- [plates](https://github.com/flatiron/plates) | ||
- [pug (formerly jade)](https://github.com/pugjs/pug) [(website)](http://jade-lang.com/) | ||
- [QEJS](https://github.com/jepso/QEJS) | ||
- [ractive](https://github.com/Rich-Harris/Ractive) | ||
- [react](https://github.com/facebook/react) | ||
- [slm](https://github.com/slm-lang/slm) | ||
- [swig (unmaintained)](https://github.com/paularmstrong/swig) | ||
- [swig (maintained fork)](https://github.com/node-swig/swig-templates) | ||
- [teacup](https://github.com/goodeggs/teacup) | ||
- [templayed](http://archan937.github.com/templayed.js/) | ||
- [twig](https://github.com/justjohn/twig.js) | ||
- [liquid](https://github.com/leizongmin/tinyliquid) [(website)](http://liquidmarkup.org/) | ||
- [toffee](https://github.com/malgorithms/toffee) | ||
- [underscore](https://github.com/documentcloud/underscore) [(website)](http://underscorejs.org/#template) | ||
- [vash](https://github.com/kirbysayshi/vash) | ||
- [walrus](https://github.com/jeremyruppel/walrus) [(website)](http://documentup.com/jeremyruppel/walrus/) | ||
- [whiskers](https://github.com/gsf/whiskers.js) | ||
Some package has the same key name, consolidate will load them according to the order number. By example for dust, consolidate will try to use in this order: `dust`, `dustjs-helpers` and `dustjs-linkedin`. If `dust` is installed, `dustjs-linkedin` will not be used by consolidate. | ||
| Name `cons.*` | Package Name / Order | Website / State | | ||
| - | - | - | | ||
| [atpl](https://github.com/soywiz/atpl.js) | [`npm install atpl`](https://www.npmjs.com/package/atpl) | - | | ||
| [bracket](https://github.com/danlevan/bracket-template) | [`npm install bracket-template`](https://www.npmjs.com/package/bracket-template) | - | | ||
| [dot](https://github.com/olado/doT) | [`npm install dot`](https://www.npmjs.com/package/dot) | [(website)](http://olado.github.io/doT/) | | ||
| ~~[dust](https://github.com/akdubya/dustjs)~~ | [`npm install dust`](https://www.npmjs.com/package/dust) (1) | [(website)](http://akdubya.github.com/dustjs/) / **(unmaintained)**<br>See: dustjs-linkedin | | ||
| [dust](https://github.com/linkedin/dustjs) | [`npm install dustjs-helpers`](https://www.npmjs.com/package/dustjs-helpers) (2) or<br>[`npm install dustjs-linkedin`](https://www.npmjs.com/package/dustjs-linkedin) (3) | [(website)](http://linkedin.github.io/dustjs/) | | ||
| ~~[eco](https://github.com/sstephenson/eco)~~ | [`npm install eco`](https://www.npmjs.com/package/eco) | **/!\ [Security issue](https://github.com/sstephenson/eco/pull/67)** | | ||
| [ect](https://github.com/baryshev/ect) | [`npm install ect`](https://www.npmjs.com/package/ect) | [(website)](http://ectjs.com/) | | ||
| [ejs](https://github.com/mde/ejs) | [`npm install ejs`](https://www.npmjs.com/package/ejs) | [(website)](http://ejs.co/) | | ||
| [hamlet](https://github.com/gregwebs/hamlet.js) | [`npm install hamlet`](https://www.npmjs.com/package/hamlet) | - | | ||
| [hamljs](https://github.com/visionmedia/haml.js) | [`npm install hamljs`](https://www.npmjs.com/package/hamljs) | - | | ||
| [haml-coffee](https://github.com/netzpirat/haml-coffee) | [`npm install haml-coffee`](https://www.npmjs.com/package/haml-coffee) | - | | ||
| [handlebars](https://github.com/wycats/handlebars.js/) | [`npm install handlebars`](https://www.npmjs.com/package/handlebars) | [(website)](http://handlebarsjs.com/) | | ||
| [hogan](https://github.com/twitter/hogan.js) | [`npm install hogan.js`](https://www.npmjs.com/package/hogan.js) | [(website)](http://twitter.github.com/hogan.js/) | | ||
| [htmling](https://github.com/codemix/htmling) | [`npm install htmling`](https://www.npmjs.com/package/htmling) | - | | ||
| ~~[jade](https://github.com/visionmedia/jade)~~ | [`npm install jade`](https://www.npmjs.com/package/jade) | [(website)](http://jade-lang.com/) / **(renamed `pug`)** | | ||
| [jazz](https://github.com/shinetech/jazz) | [`npm install jazz`](https://www.npmjs.com/package/jazz) | - | | ||
| ~~[jqtpl](https://github.com/kof/jqtpl)~~ | [`npm install jqtpl`](https://www.npmjs.com/package/jqtpl) | **(deprecated)** | | ||
| [just](https://github.com/baryshev/just) | [`npm install just`](https://www.npmjs.com/package/just) | - | | ||
| [liquid](https://github.com/leizongmin/tinyliquid) | [`npm install tinyliquid`](https://www.npmjs.com/package/tinyliquid) | [(website)](http://liquidmarkup.org/)<br>**will never add any new features** | | ||
| [liquor](https://github.com/chjj/liquor) | [`npm install liquor`](https://www.npmjs.com/package/liquor) | - | | ||
| [lodash](https://github.com/bestiejs/lodash) | [`npm install lodash`](https://www.npmjs.com/package/lodash) | [(website)](http://lodash.com/) | | ||
| [marko](https://github.com/marko-js/marko) | [`npm install marko`](https://www.npmjs.com/package/marko) | [(website)](http://markojs.com) | | ||
| [mote](https://github.com/satchmorun/mote) | [`npm install mote`](https://www.npmjs.com/package/mote) | [(website)](http://satchmorun.github.io/mote/) | | ||
| [mustache](https://github.com/janl/mustache.js) | [`npm install mustache`](https://www.npmjs.com/package/mustache) | - | | ||
| [nunjucks](https://github.com/mozilla/nunjucks) | [`npm install nunjucks`](https://www.npmjs.com/package/nunjucks) | [(website)](https://mozilla.github.io/nunjucks) | | ||
| [plates](https://github.com/flatiron/plates) | [`npm install plates`](https://www.npmjs.com/package/plates) | - | | ||
| [pug](https://github.com/pugjs/pug) | [`npm install pug`](https://www.npmjs.com/package/pug) | [(website)](http://jade-lang.com/) / **(formerly jade)** | | ||
| [qejs](https://github.com/jepso/QEJS) | [`npm install qejs`](https://www.npmjs.com/package/qejs) | - | | ||
| [ractive](https://github.com/ractivejs/ractive) | [`npm install ractive`](https://www.npmjs.com/package/ractive) | - | | ||
| [razor](https://github.com/kinogam/kino.razor) | [`npm install razor`](https://www.npmjs.com/package/razor) | - | | ||
| [react](https://github.com/facebook/react) | [`npm install react`](https://www.npmjs.com/package/react) | - | | ||
| [slm](https://github.com/slm-lang/slm) | [`npm install slm`](https://www.npmjs.com/package/slm) | - | | ||
| [squirrelly](https://github.com/squirrellyjs/squirrelly) | [`npm install squirrelly`](https://www.npmjs.com/package/squirrelly) | [(website)](https://squirrelly.js.org) | | ||
| ~~[swig](https://github.com/paularmstrong/swig)~~ | [`npm install swig`](https://www.npmjs.com/package/swig) (1) | **(unmaintained)**<br>See: swig-templates | | ||
| [swig](https://github.com/node-swig/swig-templates) | [`npm install swig-templates`](https://www.npmjs.com/package/swig-templates) (2) | - | | ||
| [teacup](https://github.com/goodeggs/teacup) | [`npm install teacup`](https://www.npmjs.com/package/teacup) | - | | ||
| [templayed](https://github.com/archan937/templayed.js/) | [`npm install templayed`](https://www.npmjs.com/package/templayed) | [(website)](http://archan937.github.com/templayed.js/) | | ||
| [toffee](https://github.com/malgorithms/toffee) | [`npm install toffee`](https://www.npmjs.com/package/toffee) | - | | ||
| [twig](https://github.com/justjohn/twig.js) | [`npm install twig`](https://www.npmjs.com/package/twig) | [(wiki)](https://github.com/twigjs/twig.js/wiki/Implementation-Notes) | | ||
| [twing](https://github.com/NightlyCommit/twing) | [`npm install twing`](https://www.npmjs.com/package/twing) | [(website)](https://nightlycommit.github.io/twing/) | | ||
| [underscore](https://github.com/documentcloud/underscore) | [`npm install underscore`](https://www.npmjs.com/package/underscore) | [(website)](http://underscorejs.org/#template) | | ||
| [vash](https://github.com/kirbysayshi/vash) | [`npm install vash`](https://www.npmjs.com/package/vash) | - | | ||
| [velocityjs](https://github.com/julianshapiro/velocity) | [BETA](https://www.npmjs.com/package/velocity-animate) | [(website)](http://velocityjs.org/) | | ||
| [walrus](https://github.com/jeremyruppel/walrus) | [`npm install walrus`](https://www.npmjs.com/package/walrus) | [(website)](http://documentup.com/jeremyruppel/walrus/) | | ||
| [whiskers](https://github.com/gsf/whiskers.js) | [`npm install whiskers`](https://www.npmjs.com/package/whiskers) | - | | ||
__NOTE__: you must still install the engines you wish to use, add them to your package.json dependencies. | ||
@@ -58,3 +71,3 @@ | ||
All templates supported by this library may be rendered using the signature `(path[, locals], callback)` as shown below, which happens to be the signature that Express 3.x supports so any of these engines may be used within Express. | ||
All templates supported by this library may be rendered using the signature `(path[, locals], callback)` as shown below, which happens to be the signature that Express supports so any of these engines may be used within Express. | ||
@@ -113,5 +126,5 @@ __NOTE__: All this example code uses cons.swig for the swig template engine. Replace swig with whatever templating you are using. For example, use cons.hogan for hogan.js, cons.jade for jade, etc. `console.log(cons)` for the full list of identifiers. | ||
When using consolidate directly: `cons.swig('views/page.html', { user: 'tobi', cache:true }, callback);` | ||
Using Express 3 or higher: `app.locals.cache = true` or set NODE_ENV to 'production' and Express will do this for you. | ||
Using supported Express versions: `app.locals.cache = true` or set NODE_ENV to 'production' and Express will do this for you. | ||
## Express 3.x example | ||
## Express example | ||
@@ -118,0 +131,0 @@ ```js |
58835
1488
224
59
Updatedbluebird@^3.7.2