co-nested-hbs
Advanced tools
Comparing version 0.1.1 to 0.2.0
26
index.js
@@ -76,9 +76,21 @@ var fs = require('fs'); | ||
hbs.render = function* () { | ||
var buffer=null, templates, locals, i, len, tmpl; | ||
var buffer=null, lastArg, secondToLastArg, renderViewPath, | ||
renderOpts, locals, templates, i, len, tmpl; | ||
locals = arguments[arguments.length - 1]; | ||
lastArg = arguments[arguments.length - 1]; | ||
secondToLastArg = arguments[arguments.length - 2]; | ||
if (typeof locals === 'object') { | ||
if (typeof secondToLastArg === 'object') { | ||
// both renderOpts and locals given | ||
renderOpts = lastArg; | ||
locals = secondToLastArg; | ||
templates = Array.prototype.slice.call(arguments, 0, -2); | ||
} else if (typeof lastArg === 'object') { | ||
// just locals given | ||
renderOpts = {}; | ||
locals = lastArg; | ||
templates = Array.prototype.slice.call(arguments, 0, -1); | ||
} else { | ||
// neither renderOpts nor locals given | ||
renderOpts = {}; | ||
locals = {}; | ||
@@ -88,4 +100,8 @@ templates = Array.prototype.slice.call(arguments); | ||
templates = templates.concat(hbs.layouts); | ||
if (renderOpts.layout !== false) { | ||
templates = templates.concat(hbs.layouts); | ||
} | ||
renderViewPath = renderOpts.viewPath || viewPath; | ||
for(i = 0, len = templates.length; i < len; i++) { | ||
@@ -96,3 +112,3 @@ tmpl = templates[i]; | ||
buffer = yield renderTemplate(viewPath, opts.partialsPath, tmpl, locals); | ||
buffer = yield renderTemplate(renderViewPath, opts.partialsPath, tmpl, locals); | ||
} | ||
@@ -99,0 +115,0 @@ |
{ | ||
"name": "co-nested-hbs", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"repository": "speedmanly/co-nested-hbs", | ||
@@ -5,0 +5,0 @@ "description": "Generator-based Handlebars templates for nested layouts.", |
@@ -45,2 +45,11 @@ var assert = require('assert'); | ||
it('accepts locals and render options', function(done) { | ||
co(function *() { | ||
var view = require('..')('test'), | ||
html = yield view.render('locals', {world: 'world'}, {layout: false}); | ||
assert.equal(html, 'hello world\n'); | ||
})(done); | ||
}); | ||
it('finds and renders partials', function(done) { | ||
@@ -69,2 +78,20 @@ co(function *() { | ||
}); | ||
it('takes a last argument to disable the global layouts', function(done) { | ||
co(function *() { | ||
var view = require('..')('test', {layout: 'a'}), | ||
html = yield view.render('c', {}, {layout: false}); | ||
assert.equal(html, 'c\n'); | ||
})(done); | ||
}); | ||
it('takes a last argument to replace the default viewPath', function(done) { | ||
co(function *() { | ||
var view = require('..')('madeuppath'), | ||
html = yield view.render('c', {}, {viewPath: 'test'}); | ||
assert.equal(html, 'c\n'); | ||
})(done); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8528
163