Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

templates

Package Overview
Dependencies
Maintainers
3
Versions
154
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

templates - npm Package Compare versions

Comparing version 0.2.7 to 0.2.8

lib/base.js

63

index.js

@@ -10,6 +10,6 @@ /*!

var Base = require('base-methods');
var helpers = require('./lib/helpers/');
var plugin = require('./lib/plugins/');
var utils = require('./lib/utils/');
var Base = require('./lib/base');
var lib = require('./lib/');

@@ -51,4 +51,2 @@

Base.call(this);
this.use(require('base-plugins'));
this.use(require('base-options'));
this.options = options || {};

@@ -80,10 +78,10 @@ this.defaultConfig();

Templates.prototype.defaultConfig = function () {
this.define('isApp', true);
this.is('App');
this.use(plugin.init);
this.use(plugin.renameKey());
this.use(plugin.context);
this.use(plugin.helpers);
this.use(plugin.item('item', 'Item'));
this.use(plugin.item('view', 'View'));
this.use(plugin.context);
this.use(plugin.helpers);

@@ -93,22 +91,26 @@ this.inflections = {};

this.views = {};
for (var key in this.options.mixins) {
this.mixin(key, this.options.mixins[key]);
}
this.initialize(this.options);
// listen for options events
this.listen(this);
// expose constructors on the instance
this.expose('Base');
this.expose('Item');
this.expose('List');
this.expose('View');
this.expose('Collection');
this.expose('Group');
this.expose('Views');
};
/**
* Initialize defaults. Exposes constructors on
* app instance.
* Expose constructors on app instance.
*/
Templates.prototype.initialize = function () {
this.define('Base', Base);
this.define('Item', this.options.Item || Item);
this.define('List', this.options.List || List);
this.define('View', this.options.View || View);
this.define('Collection', this.options.Collection || Collection);
this.define('Group', this.options.Group || Group);
this.define('Views', this.options.Views || Views);
Templates.prototype.expose = function (name) {
this.define(name, this.options[name] || lib[name.toLowerCase()]);
};

@@ -137,29 +139,2 @@

/**
* Run a plugin on the instance. Plugins are invoked
* immediately upon creating the collection in the order
* in which they were defined.
*
* ```js
* var {%= type %} = {%= ctor %}()
* .use(require('foo'))
* .use(require('bar'))
* .use(require('baz'))
* ```
*
* @name .use
* @param {Function} `fn` Plugin function. If the plugin returns a function it will be passed to the `use` method of each collection created on the instance.
* @return {Object} Returns the instance for chaining.
* @api public
*/
Templates.prototype.use = function (fn) {
var plugin = fn.call(this, this, this.options);
if (typeof plugin === 'function') {
this.plugins.push(plugin);
}
this.emit('use');
return this;
};
/**
* Create a new collection. Collections are decorated with

@@ -166,0 +141,0 @@ * special methods for getting and setting items from the

'use strict';
var Base = require('base-methods');
var Base = require('./base');
var plugin = require('./plugins');

@@ -8,2 +8,8 @@ var utils = require('./utils');

/**
* Expose `Collection`
*/
module.exports = Collection;
/**
* Create an instance of `Collection` with the given `options`.

@@ -19,3 +25,3 @@ *

var Collection = module.exports = function Collection(options) {
function Collection(options) {
if (!(this instanceof Collection)) {

@@ -26,6 +32,4 @@ return new Collection(options);

Base.call(this);
this.use(require('base-plugins'));
this.use(require('base-options'));
this.init(options || {});
};
}

@@ -39,8 +43,2 @@ /**

/**
* Mixin prototype methods
*/
plugin.option(Collection.prototype);
/**
* Initialize `Collection` defaults

@@ -50,6 +48,7 @@ */

Collection.prototype.init = function(opts) {
this.is('Collection');
this.define('List', opts.List || require('./list'));
this.define('Item', opts.Item || require('./item'));
this.define('loaded', false);
this.define('plugins', []);

@@ -59,3 +58,2 @@ this.use(plugin.renameKey());

this.isCollection = true;
this.queue = [];

@@ -79,34 +77,2 @@ this.items = {};

/**
* Run a plugin on the collection instance. Plugins
* are invoked immediately upon creating the collection
* in the order in which they were defined.
*
* ```js
* collection.use(function(items) {
* // `items` is the instance, as is `this`
*
* // optionally return a function to be passed to
* // the `.use` method of each item created on the
* // instance
* return function(item) {
* // do stuff to each `item`
* };
* });
* ```
*
* @param {Function} `fn` Plugin function. If the plugin returns a function it will be passed to the `use` method of each item created on the instance.
* @return {Object} Returns the instance for chaining.
* @api public
*/
Collection.prototype.use = function(fn) {
var plugin = fn.call(this, this, this.options);
if (typeof plugin === 'function') {
this.plugins.push(plugin);
}
this.emit('use');
return this;
};
/**
* Set an item on the collection. This is identical to [addItem](#addItem)

@@ -113,0 +79,0 @@ * except `setItem` does not emit an event for each item and does not

'use strict';
var Base = require('base-methods');
var Base = require('./base');
var utils = require('./utils');
/**
* Expose `Group`
*/
module.exports = Group;
/**
* Create an instance of `Group` with the given `options`.

@@ -20,4 +26,4 @@ *

Base.call(this, options);
this.is('Group');
this.define('List', this.List || require('./list'));
this.use(require('base-plugins'));
}

@@ -73,7 +79,1 @@

}
/**
* Expose `Group`
*/
module.exports = Group;

@@ -5,8 +5,13 @@ 'use strict';

var Stream = require('stream');
var Base = require('base-methods');
var cloneStats = require('clone-stats');
var plugin = require('./plugins');
var utils = require('./utils/');
var Base = require('./base');
/**
* Expose `Item`
*/
module.exports = Item;
/**
* Create an instance of `Item`. Optionally pass a default object

@@ -26,8 +31,10 @@ * to use.

function Item(item) {
this.isItem = true;
if (!(this instanceof Item)) {
return new Item(item);
}
this.is('Item');
item = item || {};
utils.syncContents(this, item.contents || item.content);
this.use(require('base-plugins'));
this.use(require('base-options'));
this.options = item.options || {};

@@ -72,28 +79,2 @@ this.locals = item.locals || {};

/**
* Mixin prototype methods
*/
plugin.option(Item.prototype);
/**
* Run a plugin on the `item` instance.
*
* ```js
* var item = new Item({path: 'abc', content: '...'})
* .use(require('foo'))
* .use(require('bar'))
* .use(require('baz'))
* ```
* @param {Function} `fn` plugin function to call
* @return {Object} Returns the item instance for chaining.
* @api public
*/
Item.prototype.use = function(fn) {
fn.call(this, this);
this.emit('use');
return this;
};
/**
* Re-decorate Item methods after calling

@@ -211,7 +192,1 @@ * vinyl's `.clone()` method.

}
/**
* Expose `Item`
*/
module.exports = Item;
'use strict';
var Base = require('base-methods');
var plugin = require('./plugins');
var utils = require('./utils');
var Group = require('./group');
var Base = require('./base');
/**
* Expose `List`
*/
module.exports = List;
/**
* Create an instance of `List` with the given `options`.

@@ -22,3 +28,3 @@ * Lists differ from collections in that items are stored

var List = module.exports = function List(options) {
function List(options) {
if (!(this instanceof List)) {

@@ -28,6 +34,4 @@ return new List(options);

Base.call(this);
this.use(require('base-plugins'));
this.use(require('base-options'));
this.init(options || {});
};
}

@@ -56,8 +60,10 @@ /**

List.prototype.init = function(opts) {
this.is('List');
// decorate the instance
this.use(plugin.init);
this.use(plugin.renameKey());
this.use(plugin.item('item', 'Item'));
this.use(plugin.context);
this.use(plugin.helpers);
this.use(plugin.item('item', 'Item'));

@@ -67,5 +73,3 @@ // add constructors to the instance

this.define('Views', opts.Views || require('./views'));
this.define('plugins', []);
this.isList = true;
this.queue = [];

@@ -90,34 +94,2 @@ this.items = [];

/**
* Run a plugin on the list instance. Plugins are invoked
* immediately upon creating the list in the order in which
* they were defined.
*
* ```js
* list.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`
* };
* });
* ```
*
* @param {Function} `fn` Plugin function. If the plugin returns a function it will be passed to the `use` method of each view created on the instance.
* @return {Object} Returns the instance for chaining.
* @api public
*/
List.prototype.use = function(fn) {
var plugin = fn.call(this, this, this.options);
if (typeof plugin === 'function') {
this.plugins.push(plugin);
}
this.emit('use');
return this;
};
/**
* Set an item on the collection. This is identical to [addItem](#addItem)

@@ -124,0 +96,0 @@ * except `setItem` does not emit an event for each item and does not

@@ -7,2 +7,8 @@ 'use strict';

/**
* Expose `View`
*/
module.exports = View;
/**
* Create an instance of `View`. Optionally pass a default object

@@ -23,5 +29,5 @@ * to use.

Item.call(this, view);
this.is('View');
this.define('_name', 'View');
delete this.isItem;
this.define('_name', 'View');
this.isView = true;
}

@@ -102,7 +108,1 @@

});
/**
* Expose `View`
*/
module.exports = View;
'use strict';
var path = require('path');
var Base = require('base-methods');
var plugin = require('./plugins');
var utils = require('./utils');
var Base = require('./base');
/**
* Expose `Views`
*/
module.exports = Views;
/**
* Create an instance of `Views` with the given `options`.

@@ -24,4 +30,2 @@ *

Base.call(this);
this.use(require('base-plugins'));
this.use(require('base-options'));
this.init(options || {});

@@ -52,8 +56,10 @@ }

Views.prototype.init = function(opts) {
this.is('Collection');
// decorate the instance
this.use(plugin.init);
this.use(plugin.renameKey());
this.use(plugin.item('view', 'View'));
this.use(plugin.context);
this.use(plugin.helpers);
this.use(plugin.item('view', 'View'));

@@ -64,5 +70,3 @@ // add constructors

this.define('loaded', false);
this.define('plugins', []);
this.isCollection = true;
this.queue = [];

@@ -86,34 +90,2 @@ this.views = {};

/**
* Run a plugin on the collection instance. Plugins
* are invoked immediately upon creating the collection
* in the order in which they were defined.
*
* ```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`
* };
* });
* ```
*
* @param {Function} `fn` Plugin function. If the plugin returns a function it will be passed to the `use` method of each view created on the instance.
* @return {Object} Returns the instance for chaining.
* @api public
*/
Views.prototype.use = function(fn) {
var plugin = fn.call(this, this, this.options);
if (typeof plugin === 'function') {
this.plugins.push(plugin);
}
this.emit('use');
return this;
};
/**
* Set a view on the collection. This is identical to [addView](#addView)

@@ -304,7 +276,1 @@ * except `setView` does not emit an event for each view.

};
/**
* Expose `Views`
*/
module.exports = Views;
{
"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.7",
"version": "0.2.8",
"homepage": "https://github.com/jonschlinkert/templates",

@@ -6,0 +6,0 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)",

@@ -42,2 +42,7 @@ # 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)

* [API](#api)
- [Common](#common)
+ [.option](#option)
+ [.use](#use)
- [Application](#application)
- [Settings](#settings)

@@ -94,9 +99,15 @@ - [Engines](#engines)

### [Templates](index.js#L45)
### Common
This function is the main export of the templates module. Initialize an instance of `templates` to create your application.
This section describes API features that are shared by all Templates classes.
#### .option
Set or get an option value.
**Params**
* `options` **{Object}**
* `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 the instance for chaining.

@@ -106,25 +117,64 @@ **Example**

```js
var templates = require('templates');
var app = templates();
app.option('a', 'b');
app.option({c: 'd'});
console.log(app.options);
//=> {a: 'b', c: 'd'}
```
### [.use](index.js#L150)
#### .use
Run a plugin on the instance. Plugins are invoked immediately upon creating the collection in the order in which they were defined.
Run a plugin on the given instance. Plugins are invoked immediately upon instantiating in the order in which they were defined.
**Example**
The simplest plugin looks something like the following:
```js
app.use(function(inst) {
// do something to `inst`
});
```
Note that `inst` is the instance of the class you're instantiating. So if you create an instance of `Collection`, inst is the collection instance.
**Params**
* `fn` **{Function}**: Plugin function. If the plugin returns a function it will be passed to the `use` method of each collection created on the instance.
* `fn` **{Function}**: Plugin function. If the plugin returns a function it will be passed to the `use` method of each item created on the instance.
* `returns` **{Object}**: Returns the instance for chaining.
**Usage**
```js
collection.use(function(items) {
// `items` is the instance, as is `this`
// optionally return a function to be passed to
// the `.use` method of each item created on the
// instance
return function(item) {
// do stuff to each `item`
};
});
```
### Application
This section describes the methods and features available on the main `Templates` class.
### [Templates](index.js#L45)
This function is the main export of the templates module. Initialize an instance of `templates` to create your application.
**Params**
* `options` **{Object}**
**Example**
```js
var app = templates()
.use(require('foo'))
.use(require('bar'))
.use(require('baz'))
var templates = require('templates');
var app = templates();
```
### [.collection](index.js#L174)
### [.collection](index.js#L149)

@@ -141,3 +191,3 @@ Create a new collection. Collections are decorated with special methods for getting and setting items from the collection. Note that, unlike the [create](#create) method, collections created with `.collection()` are not cached.

### [.create](index.js#L213)
### [.create](index.js#L188)

@@ -302,4 +352,6 @@ Create a new view collection to be stored on the `app.views` object. See

### [View](lib/view.js#L20)
API for the `View` class.
### [View](lib/view.js#L26)
Create an instance of `View`. Optionally pass a default object to use.

@@ -320,3 +372,3 @@

### [.compile](lib/view.js#L48)
### [.compile](lib/view.js#L54)

@@ -339,3 +391,3 @@ Synchronously compile a view.

### [.render](lib/view.js#L66)
### [.render](lib/view.js#L72)

@@ -399,3 +451,3 @@ Asynchronously render a view.

### [.mergePartials](lib/plugins/context.js#L104)
### [.mergePartials](lib/plugins/context.js#L100)

@@ -415,4 +467,6 @@ Merge "partials" view types. This is necessary for template

### [Item](lib/item.js#L24)
API for the `Item` class.
### [Item](lib/item.js#L29)
Create an instance of `Item`. Optionally pass a default object to use.

@@ -433,22 +487,4 @@

### [.use](lib/item.js#L87)
### [.clone](lib/item.js#L88)
Run a plugin on the `item` instance.
**Params**
* `fn` **{Function}**: plugin function to call
* `returns` **{Object}**: Returns the item instance for chaining.
**Example**
```js
var item = new Item({path: 'abc', content: '...'})
.use(require('foo'))
.use(require('bar'))
.use(require('baz'))
```
### [.clone](lib/item.js#L105)
Re-decorate Item methods after calling vinyl's `.clone()` method.

@@ -509,3 +545,3 @@

### [.mergePartials](lib/plugins/context.js#L104)
### [.mergePartials](lib/plugins/context.js#L100)

@@ -525,4 +561,6 @@ Merge "partials" view types. This is necessary for template

### [Collection](lib/collection.js#L18)
API for the `Collections` class.
### [Collection](lib/collection.js#L24)
Create an instance of `Collection` with the given `options`.

@@ -541,28 +579,4 @@

### [.use](lib/collection.js#L94)
### [.setItem](lib/collection.js#L86)
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 item created on the instance.
* `returns` **{Object}**: Returns the instance for chaining.
**Example**
```js
collection.use(function(items) {
// `items` is the instance, as is `this`
// optionally return a function to be passed to
// the `.use` method of each item created on the
// instance
return function(item) {
// do stuff to each `item`
};
});
```
### [.setItem](lib/collection.js#L119)
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`.

@@ -582,3 +596,3 @@

### [.addItem](lib/collection.js#L140)
### [.addItem](lib/collection.js#L107)

@@ -599,3 +613,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`.

### [.addItems](lib/collection.js#L166)
### [.addItems](lib/collection.js#L133)

@@ -619,3 +633,3 @@ Load multiple items onto the collection.

### [.addList](lib/collection.js#L193)
### [.addList](lib/collection.js#L160)

@@ -640,3 +654,3 @@ Load an array of items onto the collection.

### [.getItem](lib/collection.js#L224)
### [.getItem](lib/collection.js#L191)

@@ -698,3 +712,3 @@ Get an item from the collection.

### [.mergePartials](lib/plugins/context.js#L104)
### [.mergePartials](lib/plugins/context.js#L100)

@@ -714,4 +728,6 @@ Merge "partials" view types. This is necessary for template

### [List](lib/list.js#L22)
API for the `List` class.
### [List](lib/list.js#L28)
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.

@@ -730,28 +746,4 @@

### [.use](lib/list.js#L107)
### [.setItem](lib/list.js#L105)
Run a plugin on the list instance. Plugins are invoked immediately upon creating the list 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
list.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`
};
});
```
### [.setItem](lib/list.js#L132)
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`.

@@ -771,3 +763,3 @@

### [.addItem](lib/list.js#L161)
### [.addItem](lib/list.js#L134)

@@ -789,3 +781,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#L188)
### [.addItems](lib/list.js#L161)

@@ -809,3 +801,3 @@ Load multiple items onto the collection.

### [.addList](lib/list.js#L217)
### [.addList](lib/list.js#L190)

@@ -828,3 +820,3 @@ Load an array of items or the items from another instance of `List`.

### [.getIndex](lib/list.js#L253)
### [.getIndex](lib/list.js#L226)

@@ -845,3 +837,3 @@ Get a the index of a specific item from the list by `key`.

### [.getItem](lib/list.js#L269)
### [.getItem](lib/list.js#L242)

@@ -862,3 +854,3 @@ Get a specific item from the list by `key`.

### [.removeItem](lib/list.js#L286)
### [.removeItem](lib/list.js#L259)

@@ -880,3 +872,3 @@ Remove an item from the list.

### [.extendItem](lib/list.js#L306)
### [.extendItem](lib/list.js#L279)

@@ -892,3 +884,3 @@ Decorate each item on the list with additional methods

### [.groupBy](lib/list.js#L324)
### [.groupBy](lib/list.js#L297)

@@ -907,3 +899,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#L350)
### [.sortBy](lib/list.js#L323)

@@ -923,3 +915,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#L384)
### [.paginate](lib/list.js#L357)

@@ -962,4 +954,6 @@ 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.

### [Group](lib/group.js#L18)
API for the `Group` class.
### [Group](lib/group.js#L24)
Create an instance of `Group` with the given `options`.

@@ -979,19 +973,2 @@

### [.use](lib/group.js#L46)
Run a plugin on the group instance. Plugins are invoked immediately upon creating the group in the order in which they were defined.
**Params**
* `fn` **{Function}**: Plugin function.
* `returns` **{Object}**: Returns the instance for chaining.
**Example**
```js
group.use(function(group) {
// `group` is the instance, as is `this`
});
```
***

@@ -1132,3 +1109,3 @@

### [.mergePartials](lib/plugins/context.js#L104)
### [.mergePartials](lib/plugins/context.js#L100)

@@ -1253,3 +1230,3 @@ Merge "partials" view types. This is necessary for template

As of October 04, 2015, code coverage is 100%.
As of October 08, 2015, code coverage is 100%.

@@ -1283,2 +1260,2 @@ ```sh

_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on October 04, 2015._
_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on October 08, 2015._
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc