templates
Advanced tools
Comparing version 0.2.4 to 0.2.5
@@ -186,5 +186,2 @@ /*! | ||
collection = opts; | ||
if (typeof created === 'object') { | ||
collection.option(created); | ||
} | ||
@@ -256,5 +253,2 @@ } else { | ||
collection.define(single, this[single]); | ||
collection.define('app', function () { | ||
return self; | ||
}); | ||
@@ -261,0 +255,0 @@ // run collection plugins |
@@ -207,4 +207,3 @@ 'use strict'; | ||
while (++i < len) { | ||
var item = list[i]; | ||
fn(item); | ||
var item = fn(list[i]); | ||
this.addItem(item.path, item); | ||
@@ -211,0 +210,0 @@ } |
@@ -186,6 +186,13 @@ 'use strict'; | ||
function inspectStream(stream) { | ||
var type = stream.constructor.name; | ||
return '<' + (type !== 'Stream' ? type + 'Stream>' : ''); | ||
var name = stream.constructor.name; | ||
if (!endsWith(name, 'Stream')) { | ||
name += 'Stream'; | ||
} | ||
return '<' + name + '>'; | ||
} | ||
function endsWith(str, sub) { | ||
return str.slice(-sub.length) === sub; | ||
} | ||
function cloneBuffer(buffer) { | ||
@@ -192,0 +199,0 @@ var res = new Buffer(buffer.length); |
@@ -192,4 +192,8 @@ 'use strict'; | ||
} | ||
this.emit('addItems', items); | ||
if (this.loaded) return this; | ||
if (this.loaded) { | ||
this.loaded = false; | ||
return this; | ||
} | ||
@@ -215,4 +219,7 @@ this.visit('addItem', items); | ||
List.prototype.addList = function(list, fn) { | ||
this.emit('addList', list); | ||
if (this.loaded) return this; | ||
this.emit.call(this, 'addList', list); | ||
if (this.loaded) { | ||
this.loaded = false; | ||
return this; | ||
} | ||
@@ -219,0 +226,0 @@ if (!Array.isArray(list)) { |
@@ -68,6 +68,2 @@ 'use strict'; | ||
var types = Object.keys(obj).filter(function (key) { | ||
return key !== 'sync' && key !== 'async'; | ||
}); | ||
utils.extend(helpers, locals.helpers); | ||
@@ -89,10 +85,6 @@ | ||
thisArg.options = utils.extend({}, this.options, options, locals); | ||
thisArg.context = context || {}; | ||
thisArg.context = context; | ||
thisArg.context.view = view; | ||
thisArg.app = this; | ||
types.forEach(function (key) { | ||
helpers[key] = obj[key]; | ||
}); | ||
// bind template helpers to the instance | ||
@@ -99,0 +91,0 @@ locals.helpers = utils.bindAll(helpers, thisArg); |
@@ -8,19 +8,5 @@ 'use strict'; | ||
var Helpers = utils.Helpers; | ||
var async = utils.loader(app._.helpers.async, {async: true}); | ||
var sync = utils.loader(app._.helpers.sync); | ||
if (!app.hasOwnProperty('_')) { | ||
app.use(init); | ||
} | ||
function create(inst, name, isAsync) { | ||
var key = ['_.helpers', name].join('.'); | ||
var val = inst.get(key); | ||
if (val) return val; | ||
inst.set(key, new Helpers({ | ||
isAsync: isAsync === true, | ||
bind: false | ||
})); | ||
return inst.get(key); | ||
} | ||
/** | ||
@@ -40,4 +26,4 @@ * Register a template helper. | ||
app.mixin('helper', function() { | ||
this.helpers.apply(this, arguments); | ||
app.mixin('helper', function(key, fn) { | ||
sync.apply(sync, arguments); | ||
return this; | ||
@@ -62,9 +48,3 @@ }); | ||
app.mixin('helpers', function() { | ||
var sync = create(this, 'sync'); | ||
var cache = {}; | ||
var loader = utils.loader(cache); | ||
loader.apply(loader, arguments); | ||
for (var key in cache) { | ||
sync.addHelper(key, cache[key]); | ||
} | ||
sync.apply(sync, arguments); | ||
return this; | ||
@@ -88,4 +68,4 @@ }); | ||
app.mixin('asyncHelper', function() { | ||
this.asyncHelpers.apply(this, arguments); | ||
app.mixin('asyncHelper', function(key, fn) { | ||
async.apply(async, arguments); | ||
return this; | ||
@@ -109,10 +89,4 @@ }); | ||
app.mixin('asyncHelpers', function() { | ||
var async = create(this, 'async', true); | ||
var cache = {}; | ||
var loader = utils.loader(cache); | ||
loader.apply(loader, arguments); | ||
for (var key in cache) { | ||
async.addAsyncHelper(key, cache[key]); | ||
} | ||
app.mixin('asyncHelpers', function(helpers) { | ||
async.apply(async, arguments); | ||
return this; | ||
@@ -138,20 +112,10 @@ }); | ||
app.mixin('helperGroup', function(name, isAsync) { | ||
var args = [].slice.call(arguments, 1); | ||
var last = args[args.length - 1]; | ||
if (typeof last === 'boolean') { | ||
isAsync = args.pop(); | ||
} else { | ||
isAsync = false; | ||
} | ||
var key = [isAsync ? 'async' : 'sync', name].join('.'); | ||
var helpers = create(this, key, isAsync); | ||
var cache = {}; | ||
var loader = utils.loader(cache); | ||
loader.apply(loader, args); | ||
for (var prop in cache) { | ||
helpers.addHelper(prop, cache[prop]); | ||
} | ||
app.mixin('helperGroup', function(name, helpers, isAsync) { | ||
helpers = utils.arrayify(helpers); | ||
var type = isAsync ? 'async' : 'sync'; | ||
var cache = this._.helpers[type][name] = {}; | ||
var loader = utils.loader(cache, {async: isAsync}); | ||
loader.call(loader, helpers); | ||
return this; | ||
}); | ||
}; |
@@ -25,8 +25,11 @@ 'use strict'; | ||
app._.engines = new utils.Engines(app.engines); | ||
app._.helpers = {}; | ||
app._.helpers = { | ||
async: {}, | ||
sync: {} | ||
}; | ||
app.viewTypes = { | ||
layout: [], | ||
renderable: [], | ||
partial: [] | ||
partial: [], | ||
renderable: [] | ||
}; | ||
@@ -33,0 +36,0 @@ |
@@ -77,6 +77,3 @@ 'use strict'; | ||
fn = this.option('renameKey'); | ||
var name; | ||
if (typeof fn === 'function') { | ||
name = fn.call(this, key); | ||
} | ||
var name = fn.call(this, key); | ||
if (name && name !== key && views.hasOwnProperty(name)) { | ||
@@ -83,0 +80,0 @@ return views[name]; |
@@ -82,3 +82,3 @@ 'use strict'; | ||
if (typeof engine === 'undefined') { | ||
throw this.error('compile', 'engine', ext || 'undefined'); | ||
throw this.error('compile', 'engine', ext); | ||
} | ||
@@ -85,0 +85,0 @@ |
@@ -76,3 +76,2 @@ 'use strict'; | ||
proto.handleView = function (method, view, locals/*, cb*/) { | ||
view.options = view.options || {}; | ||
if (!view.options.handled) { | ||
@@ -203,3 +202,4 @@ view.options.handled = []; | ||
this.lazyRouter(methods); | ||
methods.forEach(function (method) { | ||
utils.arrayify(methods).forEach(function (method) { | ||
this.define(method, function(path) { | ||
@@ -206,0 +206,0 @@ var route = this.route(path); |
'use strict'; | ||
var fs = require('fs'); | ||
var keys = require('./keys'); | ||
@@ -24,8 +25,2 @@ | ||
/** | ||
* No-op, do nothing | ||
*/ | ||
utils.noop = function() {}; | ||
/** | ||
* Return the given value as-is. | ||
@@ -68,2 +63,13 @@ */ | ||
/** | ||
* Try to read a file, fail gracefully | ||
*/ | ||
utils.tryRead = function(fp) { | ||
try { | ||
return fs.readFileSync(fp); | ||
} catch(err) {} | ||
return null; | ||
}; | ||
/** | ||
* Return true if the given value is a stream. | ||
@@ -84,4 +90,2 @@ */ | ||
utils.defaults = function(target) { | ||
target = target || {}; | ||
var args = [].slice.call(arguments, 1); | ||
@@ -88,0 +92,0 @@ var len = args.length; |
@@ -22,3 +22,3 @@ 'use strict'; | ||
target[key] = utils.bindAll(fn, thisArg); | ||
} else if (typeof fn === 'function') { | ||
} else { | ||
target[key] = fn.bind(thisArg); | ||
@@ -25,0 +25,0 @@ // get `async` flag or any other helper options on `fn` |
@@ -9,16 +9,6 @@ 'use strict'; | ||
if (key === 'lazy') continue; | ||
var val = common[key]; | ||
if (common.hasOwnProperty(key)) { | ||
var val = common[key]; | ||
for (var prop in val) { | ||
if (val.hasOwnProperty(prop)) { | ||
if (!seen.hasOwnProperty(prop)) { | ||
seen[prop] = true; | ||
} else { | ||
throw new Error('duplicate util: ' + prop); | ||
} | ||
utils[prop] = val[prop]; | ||
} | ||
} | ||
for (var prop in val) { | ||
utils[prop] = val[prop]; | ||
} | ||
@@ -25,0 +15,0 @@ } |
@@ -40,3 +40,2 @@ 'use strict'; | ||
require('engine-cache', 'Engines'); | ||
require('helper-cache', 'Helpers'); | ||
require('template-error', 'rethrow'); | ||
@@ -43,0 +42,0 @@ require('inflection', 'inflect'); |
@@ -34,17 +34,2 @@ 'use strict'; | ||
/** | ||
* Allow a custom function to be used for renaming the | ||
* key property. | ||
* | ||
* @param {String} `key` | ||
* @return {String} | ||
*/ | ||
View.prototype.renameKey = function(key) { | ||
if (typeof this.options.renameKey === 'function') { | ||
return this.options.renameKey(key, this); | ||
} | ||
return key; | ||
}; | ||
/** | ||
* Synchronously compile a view. | ||
@@ -51,0 +36,0 @@ * |
@@ -220,4 +220,3 @@ 'use strict'; | ||
while (++i < len) { | ||
var view = list[i]; | ||
fn(view); | ||
var view = fn(list[i]); | ||
this.addView(view.path, view); | ||
@@ -238,3 +237,3 @@ } | ||
Views.prototype.loadView = function(filename, options) { | ||
var opts = utils.merge({}, this.options, options); | ||
var opts = utils.merge({cwd: ''}, this.options, options); | ||
var View = this.get('View'); | ||
@@ -241,0 +240,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": "0.2.4", | ||
"version": "0.2.5", | ||
"homepage": "https://github.com/jonschlinkert/templates", | ||
@@ -38,3 +38,2 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)", | ||
"group-array": "^0.3.0", | ||
"helper-cache": "^0.7.2", | ||
"inflection": "^1.7.1", | ||
@@ -44,3 +43,3 @@ "is-buffer": "^1.1.0", | ||
"lazy-cache": "^0.2.3", | ||
"load-helpers": "^0.2.7", | ||
"load-helpers": "^0.2.8", | ||
"mixin-deep": "^1.1.3", | ||
@@ -47,0 +46,0 @@ "paginationator": "^0.1.2", |
@@ -67,2 +67,3 @@ # templates [![NPM version](https://badge.fury.io/js/templates.svg)](http://badge.fury.io/js/templates) [![Build Status](https://travis-ci.org/jonschlinkert/templates.svg)](https://travis-ci.org/jonschlinkert/templates) [![Coverage Status](https://img.shields.io/coveralls/jonschlinkert/templates.svg)](https://coveralls.io/r/jonschlinkert/templates) | ||
* [Running tests](#running-tests) | ||
* [Code coverage](#code-coverage) | ||
* [Contributing](#contributing) | ||
@@ -138,3 +139,3 @@ * [Author](#author) | ||
### [.create](index.js#L216) | ||
### [.create](index.js#L213) | ||
@@ -203,3 +204,3 @@ Create a new view collection to be stored on the `app.views` object. See | ||
### [.helper](lib/plugins/helpers.js#L39) | ||
### [.helper](lib/plugins/helpers.js#L25) | ||
@@ -221,3 +222,3 @@ Register a template helper. | ||
### [.helpers](lib/plugins/helpers.js#L59) | ||
### [.helpers](lib/plugins/helpers.js#L45) | ||
@@ -240,3 +241,3 @@ Register multiple template helpers. | ||
### [.asyncHelper](lib/plugins/helpers.js#L85) | ||
### [.asyncHelper](lib/plugins/helpers.js#L65) | ||
@@ -258,3 +259,3 @@ Get or set an async helper. If only the name is passed, the helper is returned. | ||
### [.asyncHelper](lib/plugins/helpers.js#L105) | ||
### [.asyncHelper](lib/plugins/helpers.js#L85) | ||
@@ -277,3 +278,3 @@ Register multiple async template helpers. | ||
### [.helperGroup](lib/plugins/helpers.js#L133) | ||
### [.helperGroup](lib/plugins/helpers.js#L107) | ||
@@ -319,3 +320,3 @@ Register a namespaced helper group. | ||
### [.compile](lib/view.js#L63) | ||
### [.compile](lib/view.js#L48) | ||
@@ -338,3 +339,3 @@ Synchronously compile a view. | ||
### [.render](lib/view.js#L81) | ||
### [.render](lib/view.js#L66) | ||
@@ -398,3 +399,3 @@ Asynchronously render a view. | ||
### [.mergePartials](lib/plugins/context.js#L112) | ||
### [.mergePartials](lib/plugins/context.js#L104) | ||
@@ -506,3 +507,3 @@ Merge "partials" view types. This is necessary for template | ||
### [.mergePartials](lib/plugins/context.js#L112) | ||
### [.mergePartials](lib/plugins/context.js#L104) | ||
@@ -632,3 +633,3 @@ Merge "partials" view types. This is necessary for template | ||
### [.getItem](lib/collection.js#L225) | ||
### [.getItem](lib/collection.js#L224) | ||
@@ -690,3 +691,3 @@ Get an item from the collection. | ||
### [.mergePartials](lib/plugins/context.js#L112) | ||
### [.mergePartials](lib/plugins/context.js#L104) | ||
@@ -797,3 +798,3 @@ Merge "partials" view types. This is necessary for template | ||
### [.addList](lib/list.js#L213) | ||
### [.addList](lib/list.js#L217) | ||
@@ -816,3 +817,3 @@ Load an array of items or the items from another instance of `List`. | ||
### [.getIndex](lib/list.js#L246) | ||
### [.getIndex](lib/list.js#L253) | ||
@@ -833,3 +834,3 @@ Get a the index of a specific item from the list by `key`. | ||
### [.getItem](lib/list.js#L262) | ||
### [.getItem](lib/list.js#L269) | ||
@@ -850,3 +851,3 @@ Get a specific item from the list by `key`. | ||
### [.removeItem](lib/list.js#L279) | ||
### [.removeItem](lib/list.js#L286) | ||
@@ -868,3 +869,3 @@ Remove an item from the list. | ||
### [.extendItem](lib/list.js#L299) | ||
### [.extendItem](lib/list.js#L306) | ||
@@ -880,3 +881,3 @@ Decorate each item on the list with additional methods | ||
### [.groupBy](lib/list.js#L317) | ||
### [.groupBy](lib/list.js#L324) | ||
@@ -895,3 +896,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#L343) | ||
### [.sortBy](lib/list.js#L350) | ||
@@ -911,3 +912,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#L377) | ||
### [.paginate](lib/list.js#L384) | ||
@@ -1028,3 +1029,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. | ||
### [.getViews](lib/plugins/lookup.js#L105) | ||
### [.getViews](lib/plugins/lookup.js#L102) | ||
@@ -1119,3 +1120,3 @@ Get all views from a `collection` using the collection's singular or plural name. | ||
### [.mergePartials](lib/plugins/context.js#L112) | ||
### [.mergePartials](lib/plugins/context.js#L104) | ||
@@ -1152,3 +1153,3 @@ Merge "partials" view types. This is necessary for template | ||
### [.route](lib/plugins/routes.js#L129) | ||
### [.route](lib/plugins/routes.js#L128) | ||
@@ -1178,3 +1179,3 @@ Create a new Route for the given path. Each route contains a separate middleware stack. | ||
### [.all](lib/plugins/routes.js#L151) | ||
### [.all](lib/plugins/routes.js#L150) | ||
@@ -1198,3 +1199,3 @@ Special route method that works just like the `router.METHOD()` methods, except that it matches all verbs. | ||
### [.param](lib/plugins/routes.js#L180) | ||
### [.param](lib/plugins/routes.js#L179) | ||
@@ -1241,2 +1242,13 @@ Add callback triggers to route parameters, where `name` is the name of the parameter and `fn` is the callback function. | ||
## Code coverage | ||
As of October 02, 2015, code coverage is 100%. | ||
```sh | ||
Statements : 100% (1162/1162) | ||
Branches : 100% (475/475) | ||
Functions : 100% (160/160) | ||
Lines : 100% (1141/1141) | ||
``` | ||
## Contributing | ||
@@ -1243,0 +1255,0 @@ |
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
23
1247
113777
2973
4
- Removedhelper-cache@^0.7.2
Updatedload-helpers@^0.2.8