templates
Advanced tools
Comparing version 1.2.7 to 1.2.8
12
index.js
@@ -243,10 +243,3 @@ /*! | ||
options = options || {}; | ||
var opts = {}; | ||
if (!options.isCollection && !options.isViews) { | ||
opts = utils.merge({}, this.options, options); | ||
} else { | ||
opts = utils.merge({}, this.options, options.options); | ||
} | ||
// emit the collection name and options | ||
@@ -340,4 +333,5 @@ this.emit('create', name, options); | ||
Templates.prototype.resolveLayout = function(view) { | ||
Templates.prototype.resolveLayout = function(view, options) { | ||
debug('resolving layout for "%s"', view.key); | ||
var opts = Object.assign({}, options); | ||
@@ -349,3 +343,3 @@ if (!utils.isPartial(view) && typeof view.layout === 'undefined') { | ||
if (typeof layout === 'undefined') { | ||
layout = this.option('layout'); | ||
layout = opts.layout || this.option('layout'); | ||
} | ||
@@ -352,0 +346,0 @@ return layout; |
@@ -16,3 +16,3 @@ 'use strict'; | ||
proto.applyLayout = function(view) { | ||
proto.applyLayout = function(view, locals) { | ||
debug('applying layout to view "%s"', view.path); | ||
@@ -25,11 +25,9 @@ if (view.options.layoutApplied) { | ||
this.handleOnce('preLayout', view); | ||
// get the name of the first layout | ||
var name = this.resolveLayout(view); | ||
var str = view.content; | ||
var app = this; | ||
var opts = {}; | ||
var opts = {}; | ||
utils.extend(opts, this.options); | ||
utils.extend(opts, view.options); | ||
utils.extend(opts, locals); | ||
if (typeof view.context === 'function') { | ||
@@ -39,6 +37,4 @@ utils.extend(opts, view.context()); | ||
// if no layout is defined, `app.options.layout` | ||
if (typeof name === 'undefined' && utils.isRenderable(view)) { | ||
name = this.option('layout'); | ||
} | ||
// get the name of the first layout | ||
var name = this.resolveLayout(view, opts); | ||
@@ -66,3 +62,3 @@ // if still no layout is defined, bail out | ||
// actually apply the layout | ||
var res = utils.layouts(str, name, stack, opts, handleLayout); | ||
var res = utils.layouts(view.content, name, stack, opts, handleLayout); | ||
view.enable('layoutApplied'); | ||
@@ -92,6 +88,11 @@ view.option('layoutStack', res.history); | ||
proto.applyLayoutAsync = function(view, cb) { | ||
proto.applyLayoutAsync = function(view, locals, cb) { | ||
debug('applying layout to view "%s"', view.path); | ||
var app = this; | ||
if (typeof locals === 'function') { | ||
cb = locals; | ||
locals = {}; | ||
} | ||
if (view.options.layoutApplied) { | ||
@@ -106,16 +107,14 @@ cb(null, view); | ||
// get the name of the first layout | ||
var name = app.resolveLayout(file); | ||
var str = file.content; | ||
var opts = {}; | ||
utils.extend(opts, app.options); | ||
utils.extend(opts, file.options); | ||
utils.extend(opts, file.context()); | ||
utils.extend(opts, locals); | ||
// if no layout is defined, `app.options.layout` | ||
if (typeof name === 'undefined' && utils.isRenderable(file)) { | ||
name = app.option('layout'); | ||
if (typeof file.context === 'function') { | ||
utils.extend(opts, file.context()); | ||
} | ||
// get the name of the first layout | ||
var name = app.resolveLayout(file, opts); | ||
// if still no layout is defined, bail out | ||
@@ -144,3 +143,3 @@ if (utils.isFalsey(name)) { | ||
// actually apply the layout | ||
var res = utils.layouts(str, name, stack, opts, handleLayout); | ||
var res = utils.layouts(file.content, name, stack, opts, handleLayout); | ||
file.enable('layoutApplied'); | ||
@@ -147,0 +146,0 @@ file.option('layoutStack', res.history); |
@@ -231,3 +231,3 @@ 'use strict'; | ||
// apply layout | ||
app.applyLayoutAsync(file, function(err, view) { | ||
app.applyLayoutAsync(file, locals, function(err, view) { | ||
if (err) return cb(err); | ||
@@ -234,0 +234,0 @@ |
{ | ||
"name": "templates", | ||
"description": "System for creating and managing template collections, and rendering templates with any node.js template engine. Can be used as the basis for creating a static site generator or blog framework.", | ||
"version": "1.2.7", | ||
"version": "1.2.8", | ||
"homepage": "https://github.com/jonschlinkert/templates", | ||
@@ -6,0 +6,0 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)", |
@@ -221,3 +221,3 @@ # templates [![NPM version](https://img.shields.io/npm/v/templates.svg?style=flat)](https://www.npmjs.com/package/templates) [![NPM monthly downloads](https://img.shields.io/npm/dm/templates.svg?style=flat)](https://npmjs.org/package/templates) [![NPM total downloads](https://img.shields.io/npm/dt/templates.svg?style=flat)](https://npmjs.org/package/templates) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/templates.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/templates) | ||
### [.setup](index.js#L372) | ||
### [.setup](index.js#L373) | ||
@@ -2301,3 +2301,3 @@ Expose static `setup` method for providing access to an instance before any other code is run. | ||
| --- | --- | | ||
| 747 | [jonschlinkert](https://github.com/jonschlinkert) | | ||
| 750 | [jonschlinkert](https://github.com/jonschlinkert) | | ||
| 105 | [doowb](https://github.com/doowb) | | ||
@@ -2338,2 +2338,2 @@ | 1 | [chronzerg](https://github.com/chronzerg) | | ||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.4.2, on February 14, 2017._ | ||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.4.2, on February 20, 2017._ |
175972
3402