templates
Advanced tools
Comparing version 0.18.1 to 0.18.2
@@ -99,3 +99,5 @@ 'use strict'; | ||
var item = this.item(key, value); | ||
if (item.use) this.run(item); | ||
if (typeof item.use === 'function') { | ||
this.run(item); | ||
} | ||
this.items[item.key] = item; | ||
@@ -102,0 +104,0 @@ return item; |
@@ -33,4 +33,3 @@ 'use strict'; | ||
item = item || {}; | ||
if (!item) item = {}; | ||
utils.syncContents(this, item.contents || item.content); | ||
@@ -62,3 +61,3 @@ this.options = item.options || {}; | ||
var val = item[key]; | ||
if (key === 'stat' && isObject(val) && val.mode) { | ||
if (key === 'stat' && utils.isObject(val) && val.mode) { | ||
this.set(key, utils.cloneStats(val)); | ||
@@ -79,4 +78,4 @@ } else if (val) { | ||
Base.extend(Item); | ||
Base.inherit(Item, Vinyl); | ||
Base.extend(Item); | ||
@@ -147,13 +146,12 @@ /** | ||
var fp = (this.path && this.base) | ||
? this.relative | ||
: (this.key || this.path); | ||
var fp = this.key || ((this.path && this.base) ? this.relative : this.path); | ||
if (fp) inspect.push('"' + fp + '"'); | ||
if (this.isBuffer()) { | ||
// if `isBuffer` isn't defined, we don't want this throwing an error, | ||
// we want the root cause to be transparent | ||
if (this.isBuffer && this.isBuffer()) { | ||
inspect.push(this.contents.inspect()); | ||
} | ||
if (this.isStream()) { | ||
if (this.isStream && this.isStream()) { | ||
inspect.push(inspectStream(this.contents)); | ||
@@ -169,2 +167,3 @@ } | ||
utils.define(Item.prototype, 'filename', { | ||
configurable: true, | ||
set: function(val) { | ||
@@ -186,2 +185,3 @@ this.stem = val; | ||
utils.define(Item.prototype, 'content', { | ||
configurable: true, | ||
set: function(val) { | ||
@@ -201,3 +201,3 @@ utils.syncContents(this, val); | ||
var name = stream.constructor.name; | ||
if (!endsWith(name, 'Stream')) { | ||
if (!utils.endsWith(name, 'Stream')) { | ||
name += 'Stream'; | ||
@@ -208,6 +208,2 @@ } | ||
function endsWith(str, sub) { | ||
return str.slice(-sub.length) === sub; | ||
} | ||
function cloneBuffer(buffer) { | ||
@@ -218,5 +214,1 @@ var res = new Buffer(buffer.length); | ||
} | ||
function isObject(val) { | ||
return val && typeof val === 'object'; | ||
} |
@@ -118,3 +118,5 @@ 'use strict'; | ||
this.keys.push(item.key); | ||
if (item.use) this.run(item); | ||
if (typeof item.use === 'function') { | ||
this.run(item); | ||
} | ||
@@ -121,0 +123,0 @@ this.emit('load', item); |
@@ -48,6 +48,12 @@ 'use strict'; | ||
if (typeof value !== 'object') { | ||
// ensure value is an object (and not a function since `isObject` allows functions) | ||
if (!utils.isObject(value) || typeof value === 'function') { | ||
throw new TypeError('expected value to be an object.'); | ||
} | ||
// set path before creating a new `Item` | ||
if (typeof key === 'string' && typeof value.path === 'undefined') { | ||
value.path = key; | ||
} | ||
var Item = this.get(CtorName); | ||
@@ -62,14 +68,16 @@ var item = !(value instanceof Item) | ||
// prime commonly needed objects on `item` | ||
item.options = item.options || value.options || {}; | ||
item.locals = item.locals || value.locals || {}; | ||
item.data = item.data || value.data || {}; | ||
// ensure commonly needed objects are set on `item`, in case | ||
// a custom `Item` or `View` constructor was used | ||
if (!item.options) item.options = value.options || {}; | ||
if (!item.locals) item.locals = value.locals || {}; | ||
if (!item.data) item.data = value.data || {}; | ||
// get renameKey fn if defined on item opts | ||
var renameKey = this.renameKey; | ||
if (item.options && typeof item.options.renameKey === 'function') { | ||
this.option('renameKey', item.options.renameKey); | ||
renameKey = item.options.renameKey; | ||
} | ||
item.path = item.path || key; | ||
item.key = this.renameKey.call(this, item.key || key, item); | ||
// item.path = item.path || key; | ||
item.key = renameKey.call(this, item.key || key, item); | ||
@@ -88,3 +96,4 @@ // get the collection name (singular form) | ||
// if `isApp`, run plugins on `item`, otherwise this is handled by collections | ||
// if the instance is a top-level instance of templates (`isApp`), run plugins | ||
// on `item`, otherwise this is handled by collections | ||
if (app.isApp) { | ||
@@ -91,0 +100,0 @@ app.run(item); |
@@ -69,3 +69,7 @@ 'use strict'; | ||
} catch (err) { | ||
this.emit('error', err); | ||
if (this.hasListeners('error')) { | ||
this.emit('error', err); | ||
} else { | ||
throw err; | ||
} | ||
} | ||
@@ -139,3 +143,5 @@ return view; | ||
} catch (err) { | ||
app.emit('error', err); | ||
if (app.hasListeners('error')) { | ||
app.emit('error', err); | ||
} | ||
cb(err); | ||
@@ -142,0 +148,0 @@ return; |
@@ -303,4 +303,6 @@ 'use strict'; | ||
var renderErr = app.rethrow('render', err, view, context); | ||
app.emit('error', renderErr || err); | ||
cb(err); | ||
if (app.hasListeners('error')) { | ||
app.emit('error', renderErr || err); | ||
} | ||
cb(renderErr || err); | ||
return; | ||
@@ -307,0 +309,0 @@ } |
@@ -27,2 +27,3 @@ 'use strict'; | ||
} | ||
if (typeof methods !== 'undefined') { | ||
@@ -60,3 +61,3 @@ this.router.method(methods); | ||
var done = this.handleError(method, view, next); | ||
var cb = this.handleError(method, view, next); | ||
view.options.method = method; | ||
@@ -68,4 +69,4 @@ view.options.handled.push(method); | ||
// just handle the route and return | ||
if (this.isCollection || !view.options.collection) { | ||
this.router.handle(view, done); | ||
if (!this.isTemplates || this.isCollection || !view.options.collection) { | ||
this.router.handle(view, cb); | ||
return; | ||
@@ -78,4 +79,4 @@ } | ||
this.router.handle(view, function(err) { | ||
if (err) return done(err); | ||
collection.handle(method, view, done); | ||
if (err) return cb(err); | ||
collection.handle(method, view, cb); | ||
}); | ||
@@ -124,17 +125,27 @@ }; | ||
proto.handleError = function(method, view, cb) { | ||
if (typeof cb !== 'function') { | ||
cb = utils.identity; | ||
proto.handleError = function(method, view, next) { | ||
var app = this; | ||
if (typeof next !== 'function') { | ||
next = utils.identity; | ||
} | ||
var app = this; | ||
return function(err) { | ||
if (err) { | ||
if (err._handled) return cb(); | ||
utils.define(err, '_handled', true); | ||
err.source = err.stack.split('\n')[1].trim(); | ||
err.reason = app._name + '#handle("' + method + '"): ' + view.path; | ||
app.emit('error', err); | ||
return cb(err); | ||
if (app.hasListeners('error')) { | ||
app.emit('error', err); | ||
} | ||
if (typeof next !== 'function') throw err; | ||
next(err); | ||
return; | ||
} | ||
cb(null, view); | ||
if (typeof next !== 'function') { | ||
throw new TypeError('expected a callback function'); | ||
} | ||
next(null, view); | ||
}; | ||
@@ -189,2 +200,3 @@ }; | ||
proto.all = function(path/*, callback*/) { | ||
this.lazyRouter(); | ||
var route = this.route(path); | ||
@@ -232,2 +244,3 @@ route.all.apply(route, [].slice.call(arguments, 1)); | ||
this.handlers(methods); | ||
return this; | ||
}; | ||
@@ -241,5 +254,11 @@ | ||
this.lazyRouter(methods); | ||
mixinHandlers(methods); | ||
return this; | ||
}; | ||
// Mix router handler methods onto the instance | ||
mixinHandlers(utils.methods); | ||
function mixinHandlers(methods) { | ||
utils.arrayify(methods).forEach(function(method) { | ||
this.define(method, function(path) { | ||
utils.define(proto, method, function(path) { | ||
var route = this.route(path); | ||
@@ -249,16 +268,6 @@ var args = [].slice.call(arguments, 1); | ||
return this; | ||
}.bind(this)); | ||
}.bind(this)); | ||
}; | ||
// Add router methods to Templates | ||
utils.methods.forEach(function(method) { | ||
proto[method] = function(path) { | ||
var route = this.route(path); | ||
var args = [].slice.call(arguments, 1); | ||
route[method].apply(route, args); | ||
return this; | ||
}; | ||
}); | ||
}); | ||
}); | ||
} | ||
}; | ||
@@ -100,2 +100,6 @@ 'use strict'; | ||
utils.endsWith = function(str, sub) { | ||
return str.slice(-sub.length) === sub; | ||
}; | ||
/** | ||
@@ -105,5 +109,5 @@ * Return true if file exists and is not a directory. | ||
utils.fileExists = function(fp) { | ||
utils.fileExists = function(filepath) { | ||
try { | ||
return fs.statSync(fp).isDirectory() === false; | ||
return fs.statSync(filepath).isDirectory() === false; | ||
} catch (err) {} | ||
@@ -110,0 +114,0 @@ return false; |
@@ -133,3 +133,5 @@ 'use strict'; | ||
// run plugins on `view` | ||
if (view.use) this.run(view); | ||
if (typeof view.use === 'function') { | ||
this.run(view); | ||
} | ||
@@ -136,0 +138,0 @@ // emit that the view has been loaded |
{ | ||
"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": "0.18.1", | ||
"version": "0.18.2", | ||
"homepage": "https://github.com/jonschlinkert/templates", | ||
@@ -6,0 +6,0 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)", |
@@ -584,3 +584,3 @@ # templates [![NPM version](https://img.shields.io/npm/v/templates.svg?style=flat)](https://www.npmjs.com/package/templates) [![NPM downloads](https://img.shields.io/npm/dm/templates.svg?style=flat)](https://npmjs.org/package/templates) [![Build Status](https://img.shields.io/travis/jonschlinkert/templates.svg?style=flat)](https://travis-ci.org/jonschlinkert/templates) | ||
### [.clone](lib/item.js#L92) | ||
### [.clone](lib/item.js#L91) | ||
@@ -697,3 +697,3 @@ Re-decorate Item methods after calling vinyl's `.clone()` method. | ||
### [.addView](lib/views.js#L161) | ||
### [.addView](lib/views.js#L163) | ||
@@ -715,3 +715,3 @@ Similar to [setView](#setView), adds a view to the collection but also fires an event and iterates over the loading `queue` for loading views from the `addView` event listener. If the given view is not already an instance of `View`, it will be converted to one before being added to the `views` object. | ||
### [.deleteView](lib/views.js#L184) | ||
### [.deleteView](lib/views.js#L186) | ||
@@ -731,3 +731,3 @@ Delete a view from collection `views`. | ||
### [.addViews](lib/views.js#L208) | ||
### [.addViews](lib/views.js#L210) | ||
@@ -751,3 +751,3 @@ Load multiple views onto the collection. | ||
### [.addList](lib/views.js#L242) | ||
### [.addList](lib/views.js#L244) | ||
@@ -771,3 +771,3 @@ Load an array of views onto the collection. | ||
### [.groupBy](lib/views.js#L279) | ||
### [.groupBy](lib/views.js#L281) | ||
@@ -786,3 +786,3 @@ Group all collection `views` by the given property, properties or compare functions. See [group-array](https://github.com/doowb/group-array) for the full range of available features and options. | ||
### [.getView](lib/views.js#L296) | ||
### [.getView](lib/views.js#L298) | ||
@@ -803,3 +803,3 @@ Get view `name` from `collection.views`. | ||
### [.extendView](lib/views.js#L331) | ||
### [.extendView](lib/views.js#L333) | ||
@@ -819,3 +819,3 @@ Load a view from the file system. | ||
### [.isType](lib/views.js#L346) | ||
### [.isType](lib/views.js#L348) | ||
@@ -834,3 +834,3 @@ Return true if the collection belongs to the given view `type`. | ||
### [.viewTypes](lib/views.js#L393) | ||
### [.viewTypes](lib/views.js#L395) | ||
@@ -998,3 +998,3 @@ Alias for `viewType` | ||
### [.addItem](lib/collection.js#L119) | ||
### [.addItem](lib/collection.js#L121) | ||
@@ -1015,3 +1015,3 @@ Similar to `setItem`, adds an item to the collection but also fires an event and iterates over the item `queue` to load items from the `addItem` event listener. An item may be an instance of `Item`, if not, the item is converted to an instance of `Item`. | ||
### [.deleteItem](lib/collection.js#L143) | ||
### [.deleteItem](lib/collection.js#L145) | ||
@@ -1031,3 +1031,3 @@ Delete an item from collection `items`. | ||
### [.addItems](lib/collection.js#L166) | ||
### [.addItems](lib/collection.js#L168) | ||
@@ -1051,3 +1051,3 @@ Load multiple items onto the collection. | ||
### [.addList](lib/collection.js#L193) | ||
### [.addList](lib/collection.js#L195) | ||
@@ -1072,3 +1072,3 @@ Load an array of items onto the collection. | ||
### [.getItem](lib/collection.js#L224) | ||
### [.getItem](lib/collection.js#L226) | ||
@@ -1185,3 +1185,3 @@ Get an item from the collection. | ||
### [.addItem](lib/list.js#L144) | ||
### [.addItem](lib/list.js#L146) | ||
@@ -1203,3 +1203,3 @@ Similar to [setItem](#setItem), adds an item to the list but also fires an event and iterates over the item `queue` to load items from the `addItem` event listener. If the given item is not already an instance of `Item`, it will be converted to one before being added to the `items` object. | ||
### [.addItems](lib/list.js#L171) | ||
### [.addItems](lib/list.js#L173) | ||
@@ -1223,3 +1223,3 @@ Load multiple items onto the collection. | ||
### [.addList](lib/list.js#L200) | ||
### [.addList](lib/list.js#L202) | ||
@@ -1242,3 +1242,3 @@ Load an array of items or the items from another instance of `List`. | ||
### [.hasItem](lib/list.js#L237) | ||
### [.hasItem](lib/list.js#L239) | ||
@@ -1260,3 +1260,3 @@ Return true if the list has the given item (name). | ||
### [.getIndex](lib/list.js#L253) | ||
### [.getIndex](lib/list.js#L255) | ||
@@ -1277,3 +1277,3 @@ Get a the index of a specific item from the list by `key`. | ||
### [.getItem](lib/list.js#L297) | ||
### [.getItem](lib/list.js#L299) | ||
@@ -1294,3 +1294,3 @@ Get a specific item from the list by `key`. | ||
### [.getView](lib/list.js#L316) | ||
### [.getView](lib/list.js#L318) | ||
@@ -1311,3 +1311,3 @@ Proxy for `getItem` | ||
### [.deleteItem](lib/list.js#L330) | ||
### [.deleteItem](lib/list.js#L332) | ||
@@ -1326,3 +1326,3 @@ Remove an item from the list. | ||
### [.extendItem](lib/list.js#L349) | ||
### [.extendItem](lib/list.js#L351) | ||
@@ -1338,3 +1338,3 @@ Decorate each item on the list with additional methods | ||
### [.groupBy](lib/list.js#L368) | ||
### [.groupBy](lib/list.js#L370) | ||
@@ -1353,3 +1353,3 @@ Group all list `items` using the given property, properties or compare functions. See [group-array](https://github.com/doowb/group-array) for the full range of available features and options. | ||
### [.sortBy](lib/list.js#L394) | ||
### [.sortBy](lib/list.js#L396) | ||
@@ -1369,3 +1369,3 @@ Sort all list `items` using the given property, properties or compare functions. See [array-sort](https://github.com/jonschlinkert/array-sort) for the full range of available features and options. | ||
### [.paginate](lib/list.js#L442) | ||
### [.paginate](lib/list.js#L444) | ||
@@ -1657,3 +1657,3 @@ Paginate all `items` in the list with the given options, See [paginationator](https://github.com/doowb/paginationator) for the full range of available features and options. | ||
### [.handle](lib/plugins/routes.js#L46) | ||
### [.handle](lib/plugins/routes.js#L47) | ||
@@ -1675,7 +1675,7 @@ Handle a middleware `method` for `view`. | ||
### [.handleView](lib/plugins/routes.js#L111) | ||
### [.handleView](lib/plugins/routes.js#L112) | ||
Deprecated, use `.handleOnce` | ||
### [.route](lib/plugins/routes.js#L161) | ||
### [.route](lib/plugins/routes.js#L172) | ||
@@ -1705,3 +1705,3 @@ Create a new Route for the given path. Each route contains a separate middleware stack. | ||
### [.all](lib/plugins/routes.js#L183) | ||
### [.all](lib/plugins/routes.js#L194) | ||
@@ -1725,3 +1725,3 @@ Special route method that works just like the `router.METHOD()` methods, except that it matches all verbs. | ||
### [.param](lib/plugins/routes.js#L212) | ||
### [.param](lib/plugins/routes.js#L224) | ||
@@ -1728,0 +1728,0 @@ Add callback triggers to route parameters, where `name` is the name of the parameter and `fn` is the callback function. |
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
173507
4116