Permalink
Browse files

conflict merged

  • Loading branch information...
2 parents 062046b + 2511724 commit f59d7e5b24e6292b8dc88366aaffbc8ece635b3e @seriousManual seriousManual committed Feb 11, 2013
View
@@ -1,4 +1,22 @@
+0.8.0 / 2013-01-23
+==================
+
+ * add templayed support
+ * add `then-jade` as an alternative to `jade`
+
+0.7.0 / 2012-12-28
+==================
+
+ * add atpl support
+
+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
==================
View
@@ -8,6 +8,7 @@
## Supported template engines
+ - [atpl](https://github.com/soywiz/atpl.js)
- [dust](https://github.com/akdubya/dustjs) [(website)](http://akdubya.github.com/dustjs/)
- [eco](https://github.com/sstephenson/eco)
- [ect](https://github.com/baryshev/ect) [(website)](http://ectjs.com/)
@@ -24,6 +25,7 @@
- [mustache](https://github.com/janl/mustache.js)
- [QEJS](https://github.com/jepso/QEJS)
- [swig](https://github.com/paularmstrong/swig) [(website)](http://paularmstrong.github.com/swig/)
+ - [templayed](http://archan937.github.com/templayed.js/)
- [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/)
View
@@ -1,4 +1,3 @@
-
// npm install express
var express = require('../../express')
View
@@ -1,2 +1 @@
-
module.exports = require('./lib/consolidate');
View
@@ -58,12 +58,18 @@ exports.clearCache = function(){
*/
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;
}
@@ -79,9 +85,10 @@ function cache(options, compiled) {
function read(path, options, fn) {
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);
// read
fs.readFile(path, 'utf8', function(err, str){
@@ -91,21 +98,53 @@ function read(path, options, fn) {
});
}
+/**
+ * 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
*/
function fromStringRenderer(name) {
return function(path, options, fn){
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);
+ });
+ }
+ });
};
}
@@ -114,7 +153,14 @@ function fromStringRenderer(name) {
*/
exports.jade = function(path, options, fn){
- var engine = requires.jade || (requires.jade = require('jade'));
+ var engine = requires.jade;
+ if (!engine) {
+ try {
+ engine = requires.jade = require('jade');
+ } catch (err) {
+ engine = requires.jade = require('then-jade');
+ }
+ }
engine.renderFile(path, options, fn);
};
@@ -123,7 +169,14 @@ exports.jade = function(path, options, fn){
*/
exports.jade.render = function(str, options, fn){
- var engine = requires.jade || (requires.jade = require('jade'));
+ var engine = requires.jade;
+ if (!engine) {
+ try {
+ engine = requires.jade = require('jade');
+ } catch (err) {
+ engine = requires.jade = require('then-jade');
+ }
+ }
engine.render(str, options, fn);
};
@@ -159,6 +212,7 @@ exports.dust.render = function(str, options, fn){
if (options.views) views = options.views;
if (options.settings && options.settings.views) views = options.settings.views;
}
+
engine.onLoad = function(path, callback){
if ('' == extname(path)) path += '.' + ext;
if ('/' !== path[0]) path = views + '/' + path;
@@ -193,6 +247,26 @@ exports.swig.render = function(str, options, fn){
}
};
+/**
+ * Atpl support.
+ */
+
+exports.atpl = fromStringRenderer('atpl');
+
+/**
+ * Atpl string support.
+ */
+
+exports.atpl.render = function(str, options, fn){
+ var engine = requires.atpl || (requires.atpl = require('atpl'));
+ try {
+ var tmpl = cache(options) || cache(options, engine.compile(str, options));
+ fn(null, tmpl(options));
+ } catch (err) {
+ fn(err);
+ }
+};
+
/**
* Liquor support,
*/
@@ -371,7 +445,27 @@ exports.hogan.render = function(str, options, fn){
var engine = requires.hogan || (requires.hogan = require('hogan.js'));
try {
var tmpl = cache(options) || cache(options, engine.compile(str, options));
- fn(null, tmpl.render(options));
+ fn(null, tmpl.render(options, options.partials));
+ } catch (err) {
+ fn(err);
+ }
+};
+
+/**
+ * templayed.js support.
+ */
+
+exports.templayed = fromStringRenderer('templayed');
+
+/**
+ * templayed.js string support.
+ */
+
+exports.templayed.render = function(str, options, fn){
+ var engine = requires.templayed || (requires.templayed = require('templayed'));
+ try {
+ var tmpl = cache(options) || cache(options, engine(str));
+ fn(null, tmpl(options));
} catch (err) {
fn(err);
}
@@ -390,6 +484,9 @@ exports.handlebars = fromStringRenderer('handlebars');
exports.handlebars.render = function(str, options, fn) {
var engine = requires.handlebars || (requires.handlebars = require('handlebars'));
try {
+ for (var partial in options.partials) {
+ engine.registerPartial(partial, options.partials[partial]);
+ }
var tmpl = cache(options) || cache(options, engine.compile(str, options));
fn(null, tmpl(options));
} catch (err) {
@@ -486,7 +583,7 @@ exports.mustache = fromStringRenderer('mustache');
exports.mustache.render = function(str, options, fn) {
var engine = requires.mustache || (requires.mustache = require('mustache'));
try {
- fn(null, engine.to_html(str, options));
+ fn(null, engine.to_html(str, options, options.partials));
} catch (err) {
fn(err);
}
View
@@ -1,6 +1,6 @@
{
"name": "consolidate",
- "version": "0.5.0",
+ "version": "0.8.0",
"description": "Template engine consolidation library",
"keywords": [
"template",
@@ -25,15 +25,17 @@
"dust": "0.3.0",
"dustjs-linkedin": "1.2",
"dustjs-helpers":"1.1.1",
- "handlebars": "1.0.5beta",
+ "handlebars": "1.0.7",
"underscore": "1.3.3",
"qejs": "0.0.1",
"walrus": "0.9.0",
"mustache": "0.4.0",
"just": "0.1.8",
"ect": "0.2.10",
"mote": "0.2.0",
- "toffee": "0.0.52"
+ "toffee": "0.0.52",
+ "atpl": ">=0.5.5",
+ "templayed": ">=0.2.3"
},
"main": "index",
"scripts": {
View
@@ -10,14 +10,19 @@ require('./shared').test('eco');
require('./shared').test('whiskers');
require('./shared').test('haml-coffee');
require('./shared').test('hogan');
+require('./shared/partials').test('hogan');
require('./shared').test('dust');
require('./shared/partials').test('dust');
require('./shared').test('handlebars');
+require('./shared/partials').test('handlebars');
require('./shared').test('underscore');
require('./shared').test('qejs');
require('./shared').test('walrus');
require('./shared').test('mustache');
+require('./shared/partials').test('mustache');
require('./shared').test('just');
require('./shared').test('ect');
require('./shared').test('mote');
-require('./shared').test('toffee');
+require('./shared').test('toffee');
+require('./shared').test('atpl');
+require('./shared').test('templayed');
@@ -0,0 +1 @@
+<p>{{user.name}}</p>
@@ -0,0 +1 @@
+{{>partial}}
@@ -0,0 +1 @@
+{{>partial}}
@@ -0,0 +1 @@
+{{>partial}}
@@ -0,0 +1 @@
+<p>{{user.name}}</p>
View
@@ -13,17 +13,30 @@ exports.test = function(name) {
fs.readFileSync = readFileSync;
});
- it('should support rendering a partial', function(done){
- var str = fs.readFileSync('test/fixtures/' + name + '/user_partial.' + name).toString();
- var locals = {
- user: user,
- views: "./test/fixtures/" + name
- };
- cons[name].render(str, locals, function(err, html){
- if (err) return done(err);
- html.should.equal('<p>Tobi from partial!</p><p>Tobi</p>');
- done();
+ if (name == 'hogan' || name == 'mustache' || name == 'handlebars') {
+ it('should support partials', function(done){
+ var path = 'test/fixtures/' + name + '/partials.' + name;
+ var locals = { user: user, partials: { partial: 'user' } };
+ cons[name](path, locals, function(err, html){
+ if (err) return done(err);
+ html.should.equal('<p>Tobi</p>');
+ done();
+ });
});
- });
+ }
+ else {
+ it('should support rendering a partial', function(done){
+ var str = fs.readFileSync('test/fixtures/' + name + '/user_partial.' + name).toString();
+ var locals = {
+ user: user,
+ views: "./test/fixtures/" + name
+ };
+ cons[name].render(str, locals, function(err, html){
+ if (err) return done(err);
+ html.should.equal('<p>Tobi from partial!</p><p>Tobi</p>');
+ done();
+ });
+ });
+ }
});
};

0 comments on commit f59d7e5

Please sign in to comment.