Socket
Socket
Sign inDemoInstall

consolidate

Package Overview
Dependencies
Maintainers
2
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

consolidate - npm Package Compare versions

Comparing version 0.10.0 to 0.11.0

.travis.yml

34

History.md

@@ -0,2 +1,14 @@

0.11.0 / 2015-02-07
==================
* fix aptl tests
* update jade caching
* add HTMLing support
* add hamlet support
* readme updates
* add tinyliquid support
* pass `options` to ECT.js
* update ractive
* update travis-ci to test 0.10, 0.12, and iojs
0.10.0 / 2013-11-23

@@ -8,3 +20,3 @@ ==================

0.9.1 / 2013-04-29
0.9.1 / 2013-04-29
==================

@@ -16,3 +28,3 @@

0.9.0 / 2013-03-28
0.9.0 / 2013-03-28
==================

@@ -24,3 +36,3 @@

0.8.0 / 2013-01-23
0.8.0 / 2013-01-23
==================

@@ -31,3 +43,3 @@

0.7.0 / 2012-12-28
0.7.0 / 2012-12-28
==================

@@ -37,3 +49,3 @@

0.6.0 2012-12-22
0.6.0 2012-12-22
==================

@@ -45,3 +57,3 @@

0.5.0 / 2012-10-29
0.5.0 / 2012-10-29
==================

@@ -56,3 +68,3 @@

0.4.0 / 2012-07-30
0.4.0 / 2012-07-30
==================

@@ -64,3 +76,3 @@

0.3.1 / 2012-06-28
0.3.1 / 2012-06-28
==================

@@ -74,3 +86,3 @@

0.3.0 / 2012-04-18
0.3.0 / 2012-04-18
==================

@@ -81,3 +93,3 @@

0.2.0 / 2012-04-04
0.2.0 / 2012-04-04
==================

@@ -88,3 +100,3 @@

0.1.0 / 2012-01-03
0.1.0 / 2012-01-03
==================

@@ -91,0 +103,0 @@

@@ -154,2 +154,116 @@ /*!

/**
* Liquid support.
*/
exports.liquid = fromStringRenderer('liquid');
/**
* Liquid string support.
*/
/**
* Note that in order to get filters and custom tags we've had to push
* all user-defined locals down into @locals. However, just to make things
* backwards-compatible, any property of `options` that is left after
* processing and removing `locals`, `meta`, `filters`, `customTags` and
* `includeDir` will also become a local.
*/
exports.liquid.render = function(str, options, fn){
var engine = requires.liquid || (requires.liquid = require('tinyliquid'));
try {
var context = engine.newContext();
var k;
/**
* Note that there's a bug in the library that doesn't allow us to pass
* the locals to newContext(), hence looping through the keys:
*/
if (options.locals){
for (k in options.locals){
context.setLocals(k, options.locals[k]);
}
delete options.locals;
}
if (options.meta){
context.setLocals('page', options.meta);
delete options.meta;
}
/**
* Add any defined filters:
*/
if (options.filters){
for (k in options.filters){
context.setFilter(k, options.filters[k]);
}
delete options.filters;
}
/**
* Set up a callback for the include directory:
*/
var includeDir = options.includeDir || process.cwd();
context.onInclude(function (name, callback) {
var basename = path.basename(name);
var extname = path.extname(name) || '.liquid';
var filename = path.join(includeDir, basename + extname);
fs.readFile(filename, {encoding: 'utf8'}, function (err, data){
if (err) return callback(err);
callback(null, engine.parse(data));
});
});
delete options.includeDir;
/**
* The custom tag functions need to have their results pushed back
* through the parser, so set up a shim before calling the provided
* callback:
*/
var compileOptions = {
customTags: {}
};
if (options.customTags){
var tagFunctions = options.customTags;
for (k in options.customTags){
/*Tell jshint there's no problem with having this function in the loop */
/*jshint -W083 */
compileOptions.customTags[k] = function (context, name, body){
var tpl = tagFunctions[name](body.trim());
context.astStack.push(engine.parse(tpl));
};
/*jshint +W083 */
}
delete options.customTags;
}
/**
* Now anything left in `options` becomes a local:
*/
for (k in options){
context.setLocals(k, options[k]);
}
/**
* Finally, execute the template:
*/
var tmpl = cache(context) || cache(context, engine.compile(str, compileOptions));
tmpl(context, fn);
} catch (err) {
fn(err);
}
};
/**
* Jade support.

@@ -164,6 +278,16 @@ */

} catch (err) {
engine = requires.jade = require('then-jade');
try {
engine = requires.jade = require('then-jade');
} catch (otherError) {
throw err;
}
}
}
engine.renderFile(path, options, fn);
try {
var tmpl = cache(options) || cache(options, engine.compileFile(path, options));
fn(null, tmpl(options));
} catch (err) {
fn(err);
}
};

@@ -181,6 +305,16 @@

} catch (err) {
engine = requires.jade = require('then-jade');
try {
engine = requires.jade = require('then-jade');
} catch (otherError) {
throw err;
}
}
}
engine.render(str, options, fn);
try {
var tmpl = cache(options) || cache(options, engine.compile(str, options));
fn(null, tmpl(options));
} catch (err) {
fn(err);
}
};

@@ -248,3 +382,6 @@

var engine = requires.swig || (requires.swig = require('swig'));
try {
if(options.cache === true) options.cache = 'memory';
engine.setDefaults({ cache: options.cache });
var tmpl = cache(options) || cache(options, engine.compile(str, options));

@@ -400,2 +537,22 @@ fn(null, tmpl(options));

/**
* Hamlet support.
*/
exports.hamlet = fromStringRenderer('hamlet');
/**
* Hamlet string support.
*/
exports.hamlet.render = function(str, options, fn){
var engine = requires.hamlet || (requires.hamlet = require('hamlet'));
try {
options.locals = options;
fn(null, engine.render(str, options).trimLeft());
} catch (err) {
fn(err);
}
};
/**
* Whiskers support.

@@ -554,10 +711,3 @@ */

exports.qejs = function (path, options, fn) {
try {
var engine = requires.qejs || (requires.qejs = require('qejs'));
engine.renderFile(path, options).nodeify(fn);
} catch (err) {
fn(err);
}
};
exports.qejs = fromStringRenderer('qejs');

@@ -575,3 +725,3 @@ /**

fn(err);
}).end();
}).done();
} catch (err) {

@@ -654,3 +804,3 @@ fn(err);

var ECT = require('ect');
engine = requires.ect = new ECT();
engine = requires.ect = new ECT(options);
}

@@ -746,10 +896,23 @@ engine.configure({ cache: options.cache });

options.template = str;
var template = cache(options) || cache(options, engine.parse(str));
options.template = template;
if (options.data === null || options.data === undefined)
{
options.data = options;
var extend = (requires.extend || (requires.extend = require('util')._extend));
// Shallow clone the options object
options.data = extend({}, options);
// Remove consolidate-specific properties from the clone
var i, length;
var properties = ["template", "filename", "cache", "partials"];
for (i = 0, length = properties.length; i < length; i++) {
var property = properties[i];
delete options.data[property];
}
}
try {
fn(null, new engine(options).renderHTML());
fn(null, new engine(options).toHTML());
} catch (err) {

@@ -771,4 +934,35 @@ fn(err);

exports.nunjucks.render = function(str, options, fn) {
var engine = requires.nunjucks || (requires.nunjucks = require('nunjucks'));
engine.renderString(str, options, fn);
try {
var engine = requires.nunjucks || (requires.nunjucks = require('nunjucks'));
var loader = options.loader;
if (loader) {
var env = new engine.Environment(new loader(options));
env.renderString(str, options, fn);
} else {
engine.renderString(str, options, fn);
}
} catch (err) {
throw fn(err);
}
};
/**
* HTMLing support.
*/
exports.htmling = fromStringRenderer('htmling');
/**
* HTMLing string support.
*/
exports.htmling.render = function(str, options, fn) {
var engine = requires.htmling || (requires.htmling = require('htmling'));
try {
var tmpl = cache(options) || cache(options, engine.string(str));
fn(null, tmpl.render(options));
} catch (err) {
fn(err);
}
};
{
"name": "consolidate",
"version": "0.10.0",
"version": "0.11.0",
"description": "Template engine consolidation library",

@@ -14,6 +14,6 @@ "keywords": [

"should": "*",
"jade": "0.26.0",
"jade": "1.9.1",
"ejs": "0.7.1",
"eco": "1.1.0-rc-3",
"swig": "0.12.0",
"swig": "1.4.1",
"jazz": "0.0.18",

@@ -23,2 +23,3 @@ "jqtpl": "1.1.0",

"lodash": "1.2.0",
"hamlet": "0.3.3",
"hamljs": "0.6.1",

@@ -33,3 +34,3 @@ "whiskers": "0.2.2",

"underscore": "1.3.3",
"qejs": "0.0.1",
"qejs": "3.0.5",
"walrus": "0.9.0",

@@ -41,6 +42,8 @@ "mustache": "0.4.0",

"toffee": "0.0.52",
"atpl": ">=0.5.5",
"atpl": ">=0.7.6",
"templayed": ">=0.2.3",
"tinyliquid": "~0.2.22",
"dot": "1.0.1",
"ractive": "0.3.7",
"htmling": "0.0.3",
"ractive": "^0.6.1",
"nunjucks": "~1.0.0"

@@ -47,0 +50,0 @@ },

@@ -12,3 +12,5 @@ # Consolidate.js

- [atpl](https://github.com/soywiz/atpl.js)
- [dust](https://github.com/akdubya/dustjs) [(website)](http://akdubya.github.com/dustjs/)
- [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)

@@ -19,4 +21,6 @@ - [ect](https://github.com/baryshev/ect) [(website)](http://ectjs.com/)

- [haml-coffee](https://github.com/9elements/haml-coffee) [(website)](http://haml-lang.com/)
- [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/)

@@ -28,3 +32,5 @@ - [jazz](https://github.com/shinetech/jazz)

- [lodash](https://github.com/bestiejs/lodash) [(website)](http://lodash.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)
- [QEJS](https://github.com/jepso/QEJS)

@@ -34,6 +40,7 @@ - [ractive](https://github.com/Rich-Harris/Ractive)

- [templayed](http://archan937.github.com/templayed.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://documentcloud.github.com/underscore/)
- [walrus](https://github.com/jeremyruppel/walrus) [(website)](http://documentup.com/jeremyruppel/walrus/)
- [whiskers](https://github.com/gsf/whiskers.js/tree/)
- [whiskers](https://github.com/gsf/whiskers.js)

@@ -80,7 +87,7 @@ __NOTE__: you must still install the engines you wish to use, add them to your package.json dependencies.

To enable caching simply pass `{ cache: true }`. Engines _may_ use this option to cache things reading the file contents, compiled `Function`s etc. Engines which do _not_ support this may simply ignore it. All engines that consolidate.js implements I/O for will cache the file contents, ideal for production environments.
To enable or disable caching simply pass `{ cache: true/false }`. Engines _may_ use this option to cache things reading the file contents, compiled `Function`s etc. Engines which do _not_ support this may simply ignore it. All engines that consolidate.js implements I/O for will cache the file contents, ideal for production environments.
```js
var cons = require('consolidate');
cons.swig('views/page.html', { user: 'tobi' }, function(err, html){
cons.swig('views/page.html', { cache: false, user: 'tobi' }, function(err, html){
if (err) throw err;

@@ -101,3 +108,3 @@ console.log(html);

// set .html as the default extension
// set .html as the default extension
app.set('view engine', 'html');

@@ -128,6 +135,15 @@ app.set('views', __dirname + '/views');

## Notes
* You can pass **partials** with `options.partials`
* For using **template inheritance** with nunjucks, you can pass a loader
with `options.loader`.
* To use **filters** with tinyliquid, use `options.filters` and specify an array of properties, each of which is a named filter function. A filter function takes a string as a parameter and returns a modified version of it.
* To use **custom tags** with tinyliquid, use `options.customTags` to specify an array of tag functions that follow the tinyliquid [custom tag](https://github.com/leizongmin/tinyliquid/wiki/Custom-Tag) definition.
* The default directory used with the **include** tag with tinyliquid is the current working directory. To override this, use `options.includeDir`.
## Running tests
Install dev deps:
$ npm install -d

@@ -139,3 +155,3 @@

## License
## License

@@ -142,0 +158,0 @@ (The MIT License)

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc