consolidate
Advanced tools
Comparing version 0.5.0 to 0.6.0
0.6.0 2012-12-22 | ||
================== | ||
* add partials support | ||
* add support for toffee templates | ||
* remove dot it still leaks and the author has not fixed it | ||
0.5.0 / 2012-10-29 | ||
@@ -3,0 +10,0 @@ ================== |
@@ -61,8 +61,14 @@ /*! | ||
function cache(options, compiled) { | ||
// cachable | ||
if (compiled && options.filename && options.cache) { | ||
delete readCache[options.filename]; | ||
cacheStore[options.filename] = compiled; | ||
} else if (options.filename && options.cache) { | ||
return compiled; | ||
} | ||
// check cache | ||
if (options.filename && options.cache) { | ||
return cacheStore[options.filename]; | ||
} | ||
return compiled; | ||
@@ -83,5 +89,6 @@ } | ||
var str = readCache[path]; | ||
var cached = options.cache && str && 'string' == typeof str; | ||
// cached (only if cached is a string and not a compiled template function) | ||
if (options.cache && str && typeof str === 'string') return fn(null, str); | ||
if (cached) return fn(null, str); | ||
@@ -97,2 +104,31 @@ // read | ||
/** | ||
* Read `path` with `options` with | ||
* callback `(err, str)`. When `options.cache` | ||
* is true the partial string will be cached. | ||
* | ||
* @param {String} options | ||
* @param {Function} fn | ||
* @api private | ||
*/ | ||
function readPartials(path, options, fn) { | ||
if (!options.partials) return fn(); | ||
var partials = options.partials; | ||
var keys = Object.keys(partials); | ||
function next(index) { | ||
if (index == keys.length) return fn(null); | ||
var key = keys[index]; | ||
var file = join(dirname(path), partials[key] + extname(path)); | ||
read(file, options, function(err, str){ | ||
if (err) return fn(err); | ||
options.partials[key] = str; | ||
next(++index); | ||
}); | ||
} | ||
next(0); | ||
} | ||
/** | ||
* fromStringRenderer | ||
@@ -104,10 +140,13 @@ */ | ||
options.filename = path; | ||
if (cache(options)) { | ||
exports[name].render('', options, fn); | ||
} else { | ||
read(path, options, function(err, str){ | ||
if (err) return fn(err); | ||
exports[name].render(str, options, fn); | ||
}); | ||
} | ||
readPartials(path, options, function (err) { | ||
if (err) return fn(err); | ||
if (cache(options)) { | ||
exports[name].render('', options, fn); | ||
} else { | ||
read(path, options, function(err, str){ | ||
if (err) return fn(err); | ||
exports[name].render(str, options, fn); | ||
}); | ||
} | ||
}); | ||
}; | ||
@@ -162,2 +201,3 @@ } | ||
} | ||
engine.onLoad = function(path, callback){ | ||
@@ -375,3 +415,3 @@ if ('' == extname(path)) path += '.' + ext; | ||
var tmpl = cache(options) || cache(options, engine.compile(str, options)); | ||
fn(null, tmpl.render(options)); | ||
fn(null, tmpl.render(options, options.partials)); | ||
} catch (err) { | ||
@@ -395,2 +435,5 @@ fn(err); | ||
try { | ||
for (var partial in options.partials) { | ||
engine.registerPartial(partial, options.partials[partial]); | ||
} | ||
var tmpl = cache(options) || cache(options, engine.compile(str, options)); | ||
@@ -492,3 +535,3 @@ fn(null, tmpl(options)); | ||
try { | ||
fn(null, engine.to_html(str, options)); | ||
fn(null, engine.to_html(str, options, options.partials)); | ||
} catch (err) { | ||
@@ -500,22 +543,2 @@ fn(err); | ||
/** | ||
* doT support. | ||
*/ | ||
exports.dot = fromStringRenderer('dot'); | ||
/** | ||
* doT string support. | ||
*/ | ||
exports.dot.render = function(str, options, fn) { | ||
var engine = requires.dot || (requires.dot = require('dot')); | ||
try { | ||
var tmpl = cache(options) || cache(options, engine.template(str)); | ||
fn(null, tmpl(options)); | ||
} catch (err) { | ||
fn(err); | ||
} | ||
}; | ||
/** | ||
* Just support. | ||
@@ -586,2 +609,24 @@ */ | ||
} | ||
}; | ||
}; | ||
/** | ||
* Toffee support. | ||
*/ | ||
exports.toffee = function(path, options, fn){ | ||
var toffee = requires.toffee || (requires.toffee = require('toffee')); | ||
toffee.__consolidate_engine_render(path, options, fn); | ||
}; | ||
/** | ||
* Toffee string support. | ||
*/ | ||
exports.toffee.render = function(str, options, fn) { | ||
var engine = requires.toffee || (requires.toffee = require('toffee')); | ||
try { | ||
engine.str_render(str, options,fn); | ||
} catch (err) { | ||
fn(err); | ||
} | ||
} |
{ | ||
"name": "consolidate", | ||
"version": "0.5.0", | ||
"version": "0.6.0", | ||
"description": "Template engine consolidation library", | ||
@@ -27,3 +27,3 @@ "keywords": [ | ||
"dustjs-linkedin": "0.4.0", | ||
"handlebars": "1.0.5beta", | ||
"handlebars": "1.0.7", | ||
"underscore": "1.3.3", | ||
@@ -33,6 +33,6 @@ "qejs": "0.0.1", | ||
"mustache": "0.4.0", | ||
"dot": "0.2.6", | ||
"just": "0.1.8", | ||
"ect": "0.2.10", | ||
"mote": "0.2.0" | ||
"mote": "0.2.0", | ||
"toffee": "0.0.52" | ||
}, | ||
@@ -39,0 +39,0 @@ "main": "index", |
@@ -27,2 +27,3 @@ # Consolidate.js | ||
- [swig](https://github.com/paularmstrong/swig) [(website)](http://paularmstrong.github.com/swig/) | ||
- [toffee](https://github.com/malgorithms/toffee) | ||
- [underscore](https://github.com/documentcloud/underscore) [(website)](http://documentcloud.github.com/underscore/) | ||
@@ -29,0 +30,0 @@ - [walrus](https://github.com/jeremyruppel/walrus) [(website)](http://documentup.com/jeremyruppel/walrus/) |
20044
508
152