templates
Advanced tools
Comparing version 0.1.14 to 0.1.15
43
index.js
@@ -53,2 +53,5 @@ /*! | ||
// decorate `view` method onto instance | ||
utils.createView(this); | ||
for (var key in this.options.mixins) { | ||
@@ -123,5 +126,5 @@ this.mixin(key, this.options.mixins[key]); | ||
* var app = assemble() | ||
* .use(require('assemble-foo')) | ||
* .use(require('assemble-bar')) | ||
* .use(require('assemble-baz')) | ||
* .use(require('foo')) | ||
* .use(require('bar')) | ||
* .use(require('baz')) | ||
* ``` | ||
@@ -141,2 +144,18 @@ * | ||
/** | ||
* Returns a new view, using the `View` class | ||
* currently defined on the instance. | ||
* | ||
* ```js | ||
* var view = app.view('foo', {conetent: '...'}); | ||
* // or | ||
* var view = app.view({path: 'foo', conetent: '...'}); | ||
* ``` | ||
* @name .view | ||
* @param {String|Object} `key` View key or object | ||
* @param {Object} `value` If key is a string, value is the view object. | ||
* @return {Object} returns the `view` object | ||
* @api public | ||
*/ | ||
/** | ||
* Set, get and load data to be passed to templates as | ||
@@ -213,3 +232,2 @@ * context at render-time. | ||
} | ||
// pass the `View` constructor from `App` to the collection | ||
@@ -288,6 +306,10 @@ return this.extendViews(collection, opts); | ||
extendView: function (view) { | ||
extendView: function (view, options) { | ||
var opts = utils.merge({}, this.options, options); | ||
var app = this; | ||
// decorate `option` method onto `view` | ||
utils.option(view); | ||
// decorate `compile` method onto `view` | ||
view.compile = function () { | ||
@@ -298,2 +320,4 @@ var args = [this].concat([].slice.call(arguments)); | ||
}; | ||
// decorate `render` method onto `view` | ||
view.render = function () { | ||
@@ -304,5 +328,12 @@ var args = [this].concat([].slice.call(arguments)); | ||
}; | ||
// decorate `context` method onto `view` | ||
view.context = function(locals) { | ||
return utils.merge({}, this.locals, this.data, locals); | ||
}; | ||
// support custom `extendView` function on options | ||
if (typeof opts.extendView === 'function') { | ||
opts.extendView(view); | ||
} | ||
return view; | ||
@@ -329,3 +360,3 @@ }, | ||
var view = extendView.apply(this, arguments); | ||
return app.extendView(view); | ||
return app.extendView(view, options); | ||
}); | ||
@@ -332,0 +363,0 @@ |
@@ -380,2 +380,32 @@ 'use strict'; | ||
utils.createView = function (app) { | ||
app.define('view', function(key, value) { | ||
if (typeof value !== 'object' && typeof key === 'string') { | ||
return this.view(this.renameKey(key), {path: key}); | ||
} | ||
if (utils.isObject(key) && key.path) { | ||
return this.view(key.path, key); | ||
} | ||
if (typeof value !== 'object') { | ||
throw new TypeError('expected value to be an object.'); | ||
} | ||
var View = this.get('View'); | ||
var view = !(value instanceof View) | ||
? new View(value) | ||
: value; | ||
// get renameKey fn if defined on view opts | ||
if (view.options && view.options.renameKey) { | ||
this.option('renameKey', view.options.renameKey); | ||
} | ||
view.path = view.path || key; | ||
view.key = this.renameKey(view.key || key); | ||
return this.extendView(view); | ||
}); | ||
}; | ||
/** | ||
@@ -382,0 +412,0 @@ * Set or get an option value. This is a factory for |
@@ -55,4 +55,16 @@ 'use strict'; | ||
/** | ||
* Run a plugin on the `view` instance. | ||
* | ||
* ``` | ||
* var view = new View({path: 'abc', contents: '...'}) | ||
* .use(require('foo')) | ||
* .use(require('bar')) | ||
* .use(require('baz')) | ||
* ``` | ||
* @name .use | ||
* @param {Function} fn | ||
* @return {Object} | ||
* @api public | ||
*/ | ||
@@ -59,0 +71,0 @@ |
@@ -9,2 +9,3 @@ 'use strict'; | ||
options = options || {}; | ||
utils.createView(this); | ||
utils.renameKey(this); | ||
@@ -33,30 +34,28 @@ utils.option(this); | ||
view: function (key, value) { | ||
if (typeof value !== 'object' && typeof key === 'string') { | ||
return this.view(this.renameKey(key), {path: key}); | ||
} | ||
/** | ||
* Returns a new view, using the `View` class | ||
* currently defined on the instance. | ||
* | ||
* ```js | ||
* var view = app.view('foo', {conetent: '...'}); | ||
* // or | ||
* var view = app.view({path: 'foo', conetent: '...'}); | ||
* ``` | ||
* @name .view | ||
* @param {String|Object} `key` View key or object | ||
* @param {Object} `value` If key is a string, value is the view object. | ||
* @return {Object} returns the `view` object | ||
* @api public | ||
*/ | ||
if (utils.isObject(key) && key.path) { | ||
return this.view(key.path, key); | ||
} | ||
/** | ||
* Uses the `view` method to a view to the instance (collection). | ||
* | ||
* @name .addView | ||
* @param {String|Object} `key` View key or object | ||
* @param {Object} `value` If key is a string, value is the view object. | ||
* @return {Object} returns the `view` object | ||
* @api public | ||
*/ | ||
if (typeof value !== 'object') { | ||
throw new TypeError('expected value to be an object.'); | ||
} | ||
var View = this.get('View'); | ||
var view = !(value instanceof View) | ||
? new View(value) | ||
: value; | ||
// get renameKey fn if defined on view opts | ||
if (view.options && view.options.renameKey) { | ||
this.option('renameKey', view.options.renameKey); | ||
} | ||
view.path = view.path || key; | ||
view.key = this.renameKey(view.key || key); | ||
return this.extendView(view); | ||
}, | ||
addView: function(key, value) { | ||
@@ -63,0 +62,0 @@ var view = this.view(key, value); |
{ | ||
"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.1.14", | ||
"version": "0.1.15", | ||
"homepage": "https://github.com/jonschlinkert/templates", | ||
@@ -6,0 +6,0 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)", |
@@ -36,3 +36,3 @@ # templates [![NPM version](https://badge.fury.io/js/templates.svg)](http://badge.fury.io/js/templates) | ||
### [.use](index.js#L133) | ||
### [.use](index.js#L136) | ||
@@ -50,9 +50,27 @@ Run a plugin on the instance. | ||
var app = assemble() | ||
.use(require('assemble-foo')) | ||
.use(require('assemble-bar')) | ||
.use(require('assemble-baz')) | ||
.use(require('foo')) | ||
.use(require('bar')) | ||
.use(require('baz')) | ||
``` | ||
### [.data](index.js#L155) | ||
### [.view](index.js#L157) | ||
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: '...'}); | ||
``` | ||
### [.data](index.js#L174) | ||
Set, get and load data to be passed to templates as context at render-time. | ||
@@ -73,3 +91,3 @@ | ||
### [.collection](index.js#L197) | ||
### [.collection](index.js#L216) | ||
@@ -97,3 +115,3 @@ 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. | ||
### [.create](index.js#L240) | ||
### [.create](index.js#L258) | ||
@@ -123,3 +141,3 @@ Create a new view collection that is stored on the `app.views` object. For example, if you create a collection named `posts`, then all `posts` will be stored on `app.views.posts`, and a `posts` method will be added to `app`, allowing you to add posts to the collection using `app.posts()`. | ||
### [.find](index.js#L371) | ||
### [.find](index.js#L402) | ||
@@ -143,3 +161,3 @@ Find a view by `name`, optionally passing a `collection` to limit the search. If no collection is passed all `renderable` collections will be searched. | ||
### [.getView](index.js#L409) | ||
### [.getView](index.js#L440) | ||
@@ -166,3 +184,3 @@ Get view `key` from the specified `collection`. | ||
### [.getViews](index.js#L448) | ||
### [.getViews](index.js#L479) | ||
@@ -186,3 +204,3 @@ Get all views from a `collection` using the collection's singular or plural name. | ||
### [.matchView](index.js#L480) | ||
### [.matchView](index.js#L511) | ||
@@ -208,3 +226,3 @@ Returns the first view from `collection` with a key that matches the given glob pattern. | ||
### [.matchViews](index.js#L508) | ||
### [.matchViews](index.js#L539) | ||
@@ -230,3 +248,3 @@ Returns any views from the specified collection with keys that match the given glob pattern. | ||
### [.handle](index.js#L550) | ||
### [.handle](index.js#L581) | ||
@@ -269,3 +287,3 @@ Handle a middleware `method` for `view`. | ||
### [.all](index.js#L660) | ||
### [.all](index.js#L691) | ||
@@ -289,3 +307,3 @@ Special route method that works just like the `router.METHOD()` methods, except that it matches all verbs. | ||
### [.param](index.js#L689) | ||
### [.param](index.js#L720) | ||
@@ -334,3 +352,3 @@ Add callback triggers to route parameters, where `name` is the name of the parameter and `fn` is the callback function. | ||
### [.compile](index.js#L851) | ||
### [.compile](index.js#L882) | ||
@@ -360,3 +378,3 @@ Compile `content` with the given `locals`. | ||
### [.render](index.js#L914) | ||
### [.render](index.js#L945) | ||
@@ -415,2 +433,2 @@ Render a view with the given `locals` and `callback`. | ||
_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on September 12, 2015._ | ||
_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on September 12, 2015._ |
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
73454
2072
420