templates
Advanced tools
Comparing version 0.2.0 to 0.2.1
33
index.js
@@ -213,3 +213,3 @@ /*! | ||
var Collection = opts.Collection || this.get('Views'); | ||
var Collection = opts.Collection || opts.Views || this.get('Views'); | ||
var collection = {}; | ||
@@ -219,4 +219,8 @@ | ||
collection = opts; | ||
if (typeof created === 'object') { | ||
collection.option(created); | ||
} | ||
} else { | ||
opts.Item = opts.Item || this.get('View'); | ||
opts.Item = opts.Item || opts.View || this.get('View'); | ||
collection = new Collection(opts); | ||
@@ -248,3 +252,4 @@ } | ||
opts = opts || {}; | ||
if (!opts.views && !opts.items && !opts.options) { | ||
if (!opts.isCollection) { | ||
utils.defaults(opts, this.options); | ||
@@ -292,3 +297,3 @@ } | ||
collection.use(fn, opts); | ||
}.bind(this)); | ||
}); | ||
@@ -330,18 +335,18 @@ // emit create | ||
/** | ||
* Expose `Templates` | ||
* Expose constructors as static methods. | ||
*/ | ||
module.exports = Templates; | ||
Templates.Base = Base; | ||
Templates.Item = Item; | ||
Templates.View = View; | ||
Templates.List = List; | ||
Templates.Collection = Collection; | ||
Templates.Views = Views; | ||
Templates.Group = Group; | ||
/** | ||
* Expose constructors | ||
* Expose `Templates` | ||
*/ | ||
module.exports.Base = Base; | ||
module.exports.Item = Item; | ||
module.exports.View = View; | ||
module.exports.Collection = Collection; | ||
module.exports.Views = Views; | ||
module.exports.List = List; | ||
module.exports.Group = Group; | ||
module.exports = Templates; | ||
@@ -348,0 +353,0 @@ /** |
@@ -137,4 +137,7 @@ 'use strict'; | ||
var item = this.item(key, value); | ||
addPager(item, this.items); | ||
if (this.options.pager !== false) { | ||
addPager(item, this.items); | ||
} | ||
this.keys.push(item.key); | ||
@@ -141,0 +144,0 @@ this.items.push(item); |
{ | ||
"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.0", | ||
"version": "0.2.1", | ||
"homepage": "https://github.com/jonschlinkert/templates", | ||
@@ -31,3 +31,3 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)", | ||
"engine-base": "^0.1.2", | ||
"engine-cache": "^0.15.0", | ||
"engine-cache": "^0.16.1", | ||
"export-files": "^2.1.0", | ||
@@ -71,5 +71,3 @@ "extend-shallow": "^2.0.1", | ||
"should": "*", | ||
"swig": "^1.4.2", | ||
"template-helpers": "^0.3.4", | ||
"time-require": "jonschlinkert/time-require" | ||
"swig": "^1.4.2" | ||
}, | ||
@@ -76,0 +74,0 @@ "keywords": [ |
411
README.md
@@ -48,14 +48,14 @@ # templates [![NPM version](https://badge.fury.io/js/templates.svg)](http://badge.fury.io/js/templates) | ||
+ [Data](#data) | ||
- [Item](#item) | ||
+ [Settings](#settings) | ||
+ [Data](#data) | ||
- [Collections](#collections) | ||
+ [Settings](#settings) | ||
+ [Data](#data) | ||
- [View collections](#view-collections) | ||
- [Helpers](#helpers) | ||
+ [Settings](#settings) | ||
+ [Data](#data) | ||
- [List](#list) | ||
+ [Settings](#settings) | ||
- [Group](#group) | ||
@@ -139,5 +139,5 @@ - [Lookups](#lookups) | ||
```js | ||
var view = app.view('foo', {conetent: '...'}); | ||
var view = app.view('foo', {content: '...'}); | ||
// or | ||
var view = app.view({path: 'foo', conetent: '...'}); | ||
var view = app.view({path: 'foo', content: '...'}); | ||
``` | ||
@@ -175,16 +175,4 @@ | ||
### [.viewCollection](index.js#L245) | ||
### [.create](index.js#L248) | ||
Create a new view collection. View collections are decorated with special methods for getting, setting and rendering views from that collection. Collections created with this method are not stored on `app.views` as with the [create](#create) method. | ||
See the [collection docs](docs/collections.md#view-collections) for more | ||
information about view collections. | ||
**Params** | ||
* `opts` **{Object}**: View collection options. | ||
* `returns` **{Object}**: Returns the view collection instance for chaining. | ||
### [.create](index.js#L283) | ||
Create a new view collection to be stored on the `app.views` object. See | ||
@@ -201,3 +189,3 @@ the [create docs](docs/collections.md#create) for more details. | ||
### [.option](lib/decorate/config.js#L24) | ||
### [.option](lib/decorate/option.js#L22) | ||
@@ -401,3 +389,3 @@ Set or get an option value. | ||
### [.option](lib/decorate/config.js#L24) | ||
### [.option](lib/decorate/option.js#L22) | ||
@@ -480,4 +468,4 @@ Set or get an option value. | ||
* `fn` **{Function}** | ||
* `returns` **{Object}** | ||
* `fn` **{Function}**: plugin function to call | ||
* `returns` **{Object}**: Returns the item instance for chaining. | ||
@@ -487,3 +475,3 @@ **Example** | ||
```js | ||
var item = new Item({path: 'abc', contents: '...'}) | ||
var item = new Item({path: 'abc', content: '...'}) | ||
.use(require('foo')) | ||
@@ -511,3 +499,3 @@ .use(require('bar')) | ||
### [.option](lib/decorate/config.js#L24) | ||
### [.option](lib/decorate/option.js#L22) | ||
@@ -582,3 +570,3 @@ Set or get an option value. | ||
### [.use](lib/collection.js#L77) | ||
### [.use](lib/collection.js#L88) | ||
@@ -607,5 +595,5 @@ Run a plugin on the collection instance. Plugins are invoked immediately upon creating the collection in the order in which they were defined. | ||
### [.item](lib/collection.js#L102) | ||
### [.item](lib/collection.js#L120) | ||
Returns a new item, using the `Item` class currently defined on the instance. | ||
Returns a new item, using the `Item` class currently defined on the instance. Items created using this method are not cached on the instance. To cache an item, use [setItem](#setItem) | ||
@@ -621,10 +609,10 @@ **Params** | ||
```js | ||
var item = app.item('foo', {conetent: '...'}); | ||
var item = app.item('foo', {content: '...'}); | ||
// or | ||
var item = app.item({path: 'foo', conetent: '...'}); | ||
var item = app.item({path: 'foo', content: '...'}); | ||
``` | ||
### [.setItem](lib/collection.js#L119) | ||
### [.setItem](lib/collection.js#L138) | ||
Set an item on the collection. This is identical to [addItem](#addItem) except `setItem` does not emit an event for each item. | ||
Set an item on the collection. This is identical to [addItem](#addItem) except `setItem` does not emit an event for each item and does not iterate over the item `queue`. | ||
@@ -643,3 +631,3 @@ **Params** | ||
### [.addItem](lib/collection.js#L133) | ||
### [.addItem](lib/collection.js#L152) | ||
@@ -653,3 +641,3 @@ Adds event emitting and custom loading to [setItem](#setItem). | ||
### [.addItems](lib/collection.js#L159) | ||
### [.addItems](lib/collection.js#L178) | ||
@@ -673,3 +661,3 @@ Load multiple items onto the collection. | ||
### [.addList](lib/collection.js#L185) | ||
### [.addList](lib/collection.js#L204) | ||
@@ -693,3 +681,3 @@ Load an array of items onto the collection. | ||
### [.getItem](lib/collection.js#L212) | ||
### [.getItem](lib/collection.js#L231) | ||
@@ -711,3 +699,3 @@ Get an item from the collection. | ||
### [.option](lib/decorate/config.js#L24) | ||
### [.option](lib/decorate/option.js#L22) | ||
@@ -765,7 +753,7 @@ Set or get an option value. | ||
### View collections | ||
### List | ||
### [Views](lib/views.js#L20) | ||
### [List](lib/list.js#L22) | ||
Create an instance of `Views` with the given `options`. | ||
Create an instance of `List` with the given options. Lists differ from collections in that items are stored as an array, allowing items to be paginated, sorted, and grouped. | ||
@@ -779,300 +767,8 @@ **Params** | ||
```js | ||
var collection = new Views(); | ||
collection.addView('foo', {content: 'bar'}); | ||
var list = new List(); | ||
list.addItem('foo', {content: 'bar'}); | ||
``` | ||
### [.use](lib/views.js#L87) | ||
### [.use](lib/list.js#L93) | ||
Run a plugin on the collection instance. Plugins are invoked immediately upon creating the collection in the order in which they were defined. | ||
**Params** | ||
* `fn` **{Function}**: Plugin function. If the plugin returns a function it will be passed to the `use` method of each view created on the instance. | ||
* `returns` **{Object}**: Returns the instance for chaining. | ||
**Example** | ||
```js | ||
collection.use(function(views) { | ||
// `views` is the instance, as is `this` | ||
// optionally return a function to be passed to | ||
// the `.use` method of each view created on the | ||
// instance | ||
return function(view) { | ||
// do stuff to each `view` | ||
}; | ||
}); | ||
``` | ||
### [.view](lib/views.js#L112) | ||
Returns a new view, using the `View` class currently defined on the instance. | ||
**Params** | ||
* `key` **{String|Object}**: View key or object | ||
* `value` **{Object}**: If key is a string, value is the view object. | ||
* `returns` **{Object}**: returns the `view` object | ||
**Example** | ||
```js | ||
var view = app.view('foo', {conetent: '...'}); | ||
// or | ||
var view = app.view({path: 'foo', conetent: '...'}); | ||
``` | ||
### [.setView](lib/views.js#L129) | ||
Set a view on the collection. This is identical to [addView](#addView) except `setView` does not emit an event for each view. | ||
**Params** | ||
* `key` **{String|Object}**: View key or object | ||
* `value` **{Object}**: If key is a string, value is the view object. | ||
* `returns` **{Object}**: returns the `view` instance. | ||
**Example** | ||
```js | ||
collection.setView('foo', {content: 'bar'}); | ||
``` | ||
### [.addView](lib/views.js#L143) | ||
Adds event emitting and custom loading to [setView](#setView). | ||
**Params** | ||
* `key` **{String}** | ||
* `value` **{Object}** | ||
### [.addViews](lib/views.js#L171) | ||
Load multiple views onto the collection. | ||
**Params** | ||
* `views` **{Object|Array}** | ||
* `returns` **{Object}**: returns the `collection` object | ||
**Example** | ||
```js | ||
collection.addViews({ | ||
'a.html': {content: '...'}, | ||
'b.html': {content: '...'}, | ||
'c.html': {content: '...'} | ||
}); | ||
``` | ||
### [.addList](lib/views.js#L201) | ||
Load an array of views onto the collection. | ||
**Params** | ||
* `list` **{Array}** | ||
* `returns` **{Object}**: returns the `views` instance | ||
**Example** | ||
```js | ||
collection.addList([ | ||
{path: 'a.html', content: '...'}, | ||
{path: 'b.html', content: '...'}, | ||
{path: 'c.html', content: '...'} | ||
]); | ||
``` | ||
### [.loadView](lib/views.js#L226) | ||
Loads and create a new `View` from the file system. | ||
**Params** | ||
* `filename` **{String}** | ||
* `options` **{Object}** | ||
* `returns` **{Object}**: Returns view object | ||
### [.getView](lib/views.js#L257) | ||
Get a view from the collection. | ||
**Params** | ||
* `key` **{String}**: Key of the view to get. | ||
* `returns` **{Object}** | ||
**Example** | ||
```js | ||
collection.getView('a.html'); | ||
``` | ||
### [.extendView](lib/views.js#L271) | ||
Decorate each view on the collection with additional methods | ||
and properties. This provides a way of easily overriding | ||
defaults. | ||
**Params** | ||
* `view` **{Object}** | ||
* `returns` **{Object}** | ||
### Helpers | ||
The following methods are available on view collections as well as the main application instance. Note that when helpers are registered on a specific view collection, they will only be available to views in that collection. | ||
### [.helper](lib/decorate/helpers.js#L33) | ||
Register a template helper. | ||
**Params** | ||
* `name` **{String}**: Helper name | ||
* `fn` **{Function}**: Helper function. | ||
**Example** | ||
```js | ||
pages.helper('upper', function(str) { | ||
return str.toUpperCase(); | ||
}); | ||
``` | ||
### [.helpers](lib/decorate/helpers.js#L53) | ||
Register multiple template helpers. | ||
**Params** | ||
* `helpers` **{Object|Array}**: Object, array of objects, or glob patterns. | ||
**Example** | ||
```js | ||
pages.helpers({ | ||
foo: function() {}, | ||
bar: function() {}, | ||
baz: function() {} | ||
}); | ||
``` | ||
### [.asyncHelper](lib/decorate/helpers.js#L79) | ||
Get or set an async helper. If only the name is passed, the helper is returned. | ||
**Params** | ||
* `name` **{String}**: Helper name. | ||
* `fn` **{Function}**: Helper function | ||
**Example** | ||
```js | ||
pages.asyncHelper('upper', function(str, next) { | ||
next(null, str.toUpperCase()); | ||
}); | ||
``` | ||
### [.asyncHelper](lib/decorate/helpers.js#L99) | ||
Register multiple async template helpers. | ||
**Params** | ||
* `helpers` **{Object|Array}**: Object, array of objects, or glob patterns. | ||
**Example** | ||
```js | ||
pages.asyncHelpers({ | ||
foo: function() {}, | ||
bar: function() {}, | ||
baz: function() {} | ||
}); | ||
``` | ||
### [.helperGroup](lib/decorate/helpers.js#L127) | ||
Register a namespaced helper group. | ||
**Params** | ||
* `helpers` **{Object|Array}**: Object, array of objects, or glob patterns. | ||
**Example** | ||
```js | ||
// markdown-utils | ||
pages.helperGroup('mdu', { | ||
reflink: function() {}, | ||
link: function() {}, | ||
}); | ||
//=> <%%= mdu.link() %> | ||
``` | ||
#### Settings | ||
### [.option](lib/decorate/config.js#L24) | ||
Set or get an option value. | ||
**Params** | ||
* `key` **{String|Object}**: Pass a key-value pair or an object to set. | ||
* `val` **{any}**: Any value when a key-value pair is passed. This can also be options if a glob pattern is passed as the first value. | ||
* `returns` **{Object}**: Returns an instance of `Templates` for chaining. | ||
**Example** | ||
```js | ||
viewCollection.option('a', 'b'); | ||
viewCollection.option({c: 'd'}); | ||
console.log(viewCollection.options); | ||
//=> {a: 'b', c: 'd'} | ||
``` | ||
#### Data | ||
### [.data](lib/decorate/context.js#L25) | ||
Set, get and load data to be passed to templates as context at render-time. | ||
**Params** | ||
* `key` **{String|Object}**: Pass a key-value pair or an object to set. | ||
* `val` **{any}**: Any value when a key-value pair is passed. This can also be options if a glob pattern is passed as the first value. | ||
* `returns` **{Object}**: Returns an instance of `Templates` for chaining. | ||
**Example** | ||
```js | ||
viewCollection.data('a', 'b'); | ||
viewCollection.data({c: 'd'}); | ||
console.log(viewCollection.cache.data); | ||
//=> {a: 'b', c: 'd'} | ||
``` | ||
### [.mergePartials](lib/decorate/context.js#L121) | ||
Merge "partials" view types. This is necessary for template | ||
engines have no support for partials or only support one | ||
type of partials. | ||
**Params** | ||
* `options` **{Object}**: Optionally pass an array of `viewTypes` to include on `options.viewTypes` | ||
* `returns` **{Object}**: Merged partials | ||
*** | ||
### List | ||
### [.use](lib/list.js#L85) | ||
Run a plugin on the list instance. Plugins are invoked immediately upon creating the list in the order in which they were defined. | ||
@@ -1100,3 +796,3 @@ | ||
### [.item](lib/list.js#L110) | ||
### [.item](lib/list.js#L118) | ||
@@ -1114,8 +810,8 @@ Returns a new item, using the `Item` class currently defined on the instance. | ||
```js | ||
var item = app.item('foo', {conetent: '...'}); | ||
var item = app.item('foo', {content: '...'}); | ||
// or | ||
var item = app.item({path: 'foo', conetent: '...'}); | ||
var item = app.item({path: 'foo', content: '...'}); | ||
``` | ||
### [.setItem](lib/list.js#L127) | ||
### [.setItem](lib/list.js#L135) | ||
@@ -1136,11 +832,4 @@ Set an item on the collection. This is identical to [addItem](#addItem) except `setItem` does not emit an event for each item. | ||
Adds event emitting and custom loading to [setItem](#setItem). | ||
### [.addItem](lib/list.js#L160) | ||
**Params** | ||
* `key` **{String}** | ||
* `value` **{Object}** | ||
### [.addItem](lib/list.js#L156) | ||
Add an item to the list. An item may be an instance of `Item`, and if not the item is converted to an instance of `Item`. | ||
@@ -1159,3 +848,3 @@ | ||
### [.addItems](lib/list.js#L180) | ||
### [.addItems](lib/list.js#L184) | ||
@@ -1177,3 +866,3 @@ Add an object of `views` to the list. | ||
### [.addList](lib/list.js#L198) | ||
### [.addList](lib/list.js#L202) | ||
@@ -1195,3 +884,3 @@ Add the items from another instance of `List`. | ||
### [.getIndex](lib/list.js#L223) | ||
### [.getIndex](lib/list.js#L227) | ||
@@ -1212,3 +901,3 @@ Get a the index of a specific item from the list by `key`. | ||
### [.getItem](lib/list.js#L239) | ||
### [.getItem](lib/list.js#L243) | ||
@@ -1229,3 +918,3 @@ Get a specific item from the list by `key`. | ||
### [.removeItem](lib/list.js#L256) | ||
### [.removeItem](lib/list.js#L260) | ||
@@ -1247,3 +936,3 @@ Remove an item from the list. | ||
### [.groupBy](lib/list.js#L280) | ||
### [.groupBy](lib/list.js#L284) | ||
@@ -1262,3 +951,3 @@ Group all list `items` using the given property, properties or compare functions. See [group-array][] for the full range of available features and options. | ||
### [.sortBy](lib/list.js#L306) | ||
### [.sortBy](lib/list.js#L310) | ||
@@ -1278,3 +967,3 @@ Sort all list `items` using the given property, properties or compare functions. See [array-sort][] for the full range of available features and options. | ||
### [.paginate](lib/list.js#L340) | ||
### [.paginate](lib/list.js#L344) | ||
@@ -1294,3 +983,3 @@ Paginate all `items` in the list with the given options, See [paginationator][] for the full range of available features and options. | ||
### [.option](lib/decorate/config.js#L24) | ||
### [.option](lib/decorate/option.js#L22) | ||
@@ -1318,3 +1007,3 @@ Set or get an option value. | ||
### [Group](lib/group.js#L20) | ||
### [Group](lib/group.js#L18) | ||
@@ -1331,9 +1020,7 @@ Create an instance of `Group` with the given `options`. | ||
var group = new Group({ | ||
'foo': { | ||
items: [1,2,3] | ||
} | ||
'foo': { items: [1,2,3] } | ||
}); | ||
``` | ||
### [.use](lib/group.js#L48) | ||
### [.use](lib/group.js#L46) | ||
@@ -1624,4 +1311,4 @@ Run a plugin on the group instance. Plugins are invoked immediately upon creating the group in the order in which they were defined. | ||
_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on September 22, 2015._ | ||
_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on September 30, 2015._ | ||
{%= reflinks(verb.related.list.concat(['micromatch', 'group-array', 'array-sort', 'paginationator'])) %} |
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
21
3154
116821
1281
+ Addedengine-cache@0.16.2(transitive)
- Removedengine-cache@0.15.0(transitive)
Updatedengine-cache@^0.16.1