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.9.2 to 0.9.3

15

lib/plugins/errors.js
'use strict';
var util = require('util');
var utils = require('../utils');

@@ -14,7 +15,13 @@

proto.formatError = function(method, id, msg) {
proto.formatError = function(method, id, msg, view) {
var ctx = this.errors[method][id];
var reason = name + '#' + method + ' ' + ctx + (msg || '');
var err = new Error(reason);
err.reason = reason;
if (!view) view = {relative: ''};
if (!msg) msg = '';
var reason = name + '#' + method + ' ' + ctx;
reason = util.format(reason, msg, view.relative);
var res = utils.wrap(reason, {width: 70, indent: '', trim: true});
var err = new Error(res);
err.reason = res;
err.id = id;

@@ -21,0 +28,0 @@ err.msg = msg;

@@ -49,6 +49,23 @@ 'use strict';

/**
* Get or set an async helper. If only the name is passed, the
* helper is returned.
* Get a sync helper that was previously registered.
*
* ```js
* {%= appname %}.helper('upper', function(str) {
* return str.toUpperCase();
* });
* ```
* @name .helper
* @param {String} `name` Helper name
* @param {Function} `fn` Helper function.
* @api public
*/
app.define('getHelper', function(name, async) {
return this.get(['_.helpers', async ? 'async' : 'sync', name]);
});
/**
* Register an async helper.
*
* ```js
* {%= appname %}.asyncHelper('upper', function(str, next) {

@@ -55,0 +72,0 @@ * next(null, str.toUpperCase());

@@ -39,3 +39,3 @@ 'use strict';

callback: 'is sync and does not take a callback function',
engine: 'cannot find an engine for: ',
engine: 'cannot find engine: %s',
method: 'expects engines to have a compile method'

@@ -45,9 +45,9 @@ },

callback: 'is async and expects a callback function',
engine: 'cannot find an engine for: ',
engine: 'cannot find engine: %s',
method: 'expects engines to have a render method'
},
layouts: {
registered: 'no layouts are registered, but one is defined: '
registered: 'layout "%s" was defined on view "%s" but cannot be not found (common causes are incorrect glob patterns, renameKey function modifying the key, and typos in search pattern)'
}
});
};

@@ -74,2 +74,3 @@ 'use strict';

// emit the item, collection name, and collection instance
// `app.on('view', ...)`
this.emit(method, item, collectionName, this);

@@ -76,0 +77,0 @@ return item;

@@ -47,3 +47,3 @@ 'use strict';

if (registered === 0 || !stack.hasOwnProperty(name)) {
throw this.formatError('layouts', 'registered', name);
throw this.formatError('layouts', 'registered', name, view);
}

@@ -50,0 +50,0 @@

@@ -11,3 +11,3 @@ 'use strict';

module.exports = function(app, views, options) {
if (!views.options.hasOwnProperty('renameKey')) {
if (typeof views.options.renameKey !== 'function') {
views.option('renameKey', app.renameKey);

@@ -28,11 +28,14 @@ }

// bubble up `view` events
views.on('view', function(view, type, collection) {
views.on('view', function(view, collectionName, collection) {
utils.define(view, 'addView', views.addView.bind(views));
if (!view.options.hasOwnProperty('engine')) {
view.options.engine = views.options.engine;
if (views.options.engine) {
view.engine = views.options.engine;
}
app.extendView(view, options);
});
views.on('load', function(view, collectionName, collection) {
app.emit.bind(app, 'view').apply(app, arguments);
app.handleView('onLoad', view);
app.emit.bind(app, 'view').apply(app, arguments);
});
};

@@ -27,2 +27,3 @@ 'use strict';

require('mixin-deep', 'merge');
require('word-wrap', 'wrap');

@@ -29,0 +30,0 @@ /**

@@ -31,2 +31,3 @@ 'use strict';

}
utils.isName(this, 'View');

@@ -115,2 +116,23 @@ Item.call(this, view);

/**
* Return true if the view is the given view `type`. Since
* types are assigned by collections, views that are "collection-less"
* will not have a type, and thus will always return `false` (as
* expected).
*
* ```js
* view.isType('partial');
* ```
* @param {String} `type` (`renderable`, `partial`, `layout`)
* @api public
*/
View.prototype.isType = function(type) {
this.options = this.options || {};
if (!this.options.viewType) {
this.options.viewType = [];
}
return this.options.viewType.indexOf(type) !== -1;
};
/**
* Ensure that the `layout` property is set on a view.

@@ -117,0 +139,0 @@ */

@@ -105,5 +105,3 @@ 'use strict';

var view = this.view(key, value);
this.setType(view);
view.isType = this.isType.bind(view);

@@ -114,4 +112,5 @@ if (view.use) {

var name = this.options.inflection;
if (name) this.emit(name, view, this);
var name = this.options.inflection || 'none';
this.emit('load', view);
this.emit(name, view, this);

@@ -310,7 +309,3 @@ this.views[view.key] = view;

if (!this.options.viewType || !this.options.viewType.length) {
if (typeof this.viewType === 'function') {
this.viewType();
} else{
this.options.viewType = ['renderable'];
}
this.viewType();
}

@@ -334,2 +329,6 @@ return this.options.viewType.indexOf(type) !== -1;

var type = types[len];
if (['partial', 'layout', 'renderable'].indexOf(type) === -1) {
throw new Error('"' + type + '" is not a valid viewType. Valid viewTypes are: partial, renderable and layout.');
}
if (this.options.viewType.indexOf(type) === -1) {

@@ -336,0 +335,0 @@ this.options.viewType.push(type);

{
"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.9.2",
"version": "0.9.3",
"homepage": "https://github.com/jonschlinkert/templates",

@@ -41,8 +41,9 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)",

"layouts": "^0.10.6",
"lazy-cache": "^1.0.2",
"load-helpers": "^0.2.9",
"lazy-cache": "^1.0.3",
"load-helpers": "^0.2.10",
"mixin-deep": "^1.1.3",
"paginationator": "^0.1.2",
"paginationator": "^0.1.3",
"template-error": "^0.1.2",
"vinyl": "^1.1.0"
"vinyl": "^1.1.0",
"word-wrap": "^1.1.0"
},

@@ -58,6 +59,7 @@ "devDependencies": {

"event-stream": "^3.3.2",
"find-pkg": "^0.1.0",
"find-pkg": "^0.1.1",
"get-value": "^2.0.2",
"gulp": "^3.9.0",
"gulp-eslint": "^1.1.1",
"gulp-format-md": "^0.1.4",
"gulp-istanbul": "^0.10.3",

@@ -100,9 +102,2 @@ "gulp-mocha": "^2.2.0",

},
"use": {
"gulp-format-md": {
"method": "preWrite",
"path": "./middleware.js",
"pattern": "readme\\.md$"
}
},
"reflinks": [

@@ -113,4 +108,7 @@ "array-sort",

],
"layout": "default"
"layout": "default",
"plugins": [
"gulp-format-md"
]
}
}

@@ -26,18 +26,15 @@ # templates [![NPM version](https://img.shields.io/npm/v/templates.svg)](https://www.npmjs.com/package/templates) [![Build Status](https://img.shields.io/travis/jonschlinkert/templates.svg)](https://travis-ci.org/jonschlinkert/templates)

* [Routes and middleware](#routes-and-middleware)
- [Code coverage](#code-coverage)
- [History](#history)
- [Related projects](#related-projects)
- [Running tests](#running-tests)
- [Code coverage](#code-coverage)
- [Contributing](#contributing)
- [History](#history)
- [Related projects](#related-projects-1)
- [Running tests](#running-tests-1)
- [Contributing](#contributing-1)
- [Author](#author)
- [License](#license)
_(TOC generated by [verb](https://github.com/verbose/verb))_
_(TOC generated by [verb](https://github.com/verbose/verb) using [markdown-toc](https://github.com/jonschlinkert/markdown-toc))_
## Install
Install with [npm](https://www.npmjs.com/)
Install with [npm](https://www.npmjs.com/):

@@ -275,8 +272,25 @@ ```sh

### [.asyncHelper](lib/plugins/helpers.js#L63)
### [.helper](lib/plugins/helpers.js#L62)
Get or set an async helper. If only the name is passed, the helper is returned.
Get a sync helper that was previously registered.
**Params**
* `name` **{String}**: Helper name
* `fn` **{Function}**: Helper function.
**Example**
```js
app.helper('upper', function(str) {
return str.toUpperCase();
});
```
### [.asyncHelper](lib/plugins/helpers.js#L80)
Register an async helper.
**Params**
* `name` **{String}**: Helper name.

@@ -293,3 +307,3 @@ * `fn` **{Function}**: Helper function

### [.asyncHelpers](lib/plugins/helpers.js#L83)
### [.asyncHelpers](lib/plugins/helpers.js#L100)

@@ -312,3 +326,3 @@ Register multiple async template helpers.

### [.helperGroup](lib/plugins/helpers.js#L107)
### [.helperGroup](lib/plugins/helpers.js#L124)

@@ -358,3 +372,3 @@ Register a namespaced helper group.

### [.context](lib/view.js#L55)
### [.context](lib/view.js#L56)

@@ -374,3 +388,3 @@ Creates a context object from front-matter data, `view.locals` and the given `locals` object.

### [.compile](lib/view.js#L74)
### [.compile](lib/view.js#L75)

@@ -393,3 +407,3 @@ Synchronously compile a view.

### [.render](lib/view.js#L92)
### [.render](lib/view.js#L93)

@@ -411,2 +425,16 @@ Asynchronously render a view.

### [.isType](lib/view.js#L127)
Return true if the view is the given view `type`. Since types are assigned by collections, views that are "collection-less" will not have a type, and thus will always return `false` (as expected).
**Params**
* `type` **{String}**: (`renderable`, `partial`, `layout`)
**Example**
```js
view.isType('partial');
```
#### Data

@@ -853,3 +881,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.
Group all list `items` using the given property, properties or compare functions. See [group-array][] for the full range of available features and options.

@@ -868,3 +896,3 @@ * `returns` **{Object}**: Returns the grouped items.

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.
Sort all list `items` using the given property, properties or compare functions. See [array-sort][] for the full range of available features and options.

@@ -884,3 +912,3 @@ * `returns` **{Object}**: Returns a new `List` instance with sorted items.

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.
Paginate all `items` in the list with the given options, See [paginationator][] for the full range of available features and options.

@@ -1165,21 +1193,5 @@ * `returns` **{Object}**: Returns the paginated items.

## Related projects
* [assemble](https://www.npmjs.com/package/assemble): Static site generator for Grunt.js, Yeoman and Node.js. Used by Zurb Foundation, Zurb Ink, H5BP/Effeckt,… [more](https://www.npmjs.com/package/assemble) | [homepage](http://assemble.io)
* [en-route](https://www.npmjs.com/package/en-route): Routing for static site generators, build systems and task runners, heavily based on express.js routes… [more](https://www.npmjs.com/package/en-route) | [homepage](https://github.com/jonschlinkert/en-route)
+ [engine](https://www.npmjs.com/package/engine): Template engine based on Lo-Dash template, but adds features like the ability to register helpers… [more](https://www.npmjs.com/package/engine) | [homepage](https://github.com/jonschlinkert/engine)
+ [layouts](https://www.npmjs.com/package/layouts): Wraps templates with layouts. Layouts can use other layouts and be nested to any depth.… [more](https://www.npmjs.com/package/layouts) | [homepage](https://github.com/doowb/layouts)
* [verb](https://www.npmjs.com/package/verb): Documentation generator for GitHub projects. Verb is extremely powerful, easy to use, and is used… [more](https://www.npmjs.com/package/verb) | [homepage](https://github.com/verbose/verb)
## Running tests
Install dev dependencies:
```sh
$ npm i -d && npm test
```
## Code coverage
As of December 20, 2015, code coverage is 100%.
As of January 03, 2016, code coverage is 100%.

@@ -1193,8 +1205,2 @@ ```sh

## Contributing
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/templates/issues/new).
If this project doesn't do what you need, [please let us know](https://github.com/jonschlinkert/templates/issues).
## History

@@ -1226,4 +1232,4 @@

* [en-route](https://www.npmjs.com/package/en-route): Routing for static site generators, build systems and task runners, heavily based on express.js routes… [more](https://www.npmjs.com/package/en-route) | [homepage](https://github.com/jonschlinkert/en-route)
+ [engine](https://www.npmjs.com/package/engine): Template engine based on Lo-Dash template, but adds features like the ability to register helpers… [more](https://www.npmjs.com/package/engine) | [homepage](https://github.com/jonschlinkert/engine)
+ [layouts](https://www.npmjs.com/package/layouts): Wraps templates with layouts. Layouts can use other layouts and be nested to any depth.… [more](https://www.npmjs.com/package/layouts) | [homepage](https://github.com/doowb/layouts)
* [engine](https://www.npmjs.com/package/engine): Template engine based on Lo-Dash template, but adds features like the ability to register helpers… [more](https://www.npmjs.com/package/engine) | [homepage](https://github.com/jonschlinkert/engine)
* [layouts](https://www.npmjs.com/package/layouts): Wraps templates with layouts. Layouts can use other layouts and be nested to any depth.… [more](https://www.npmjs.com/package/layouts) | [homepage](https://github.com/doowb/layouts)
* [verb](https://www.npmjs.com/package/verb): Documentation generator for GitHub projects. Verb is extremely powerful, easy to use, and is used… [more](https://www.npmjs.com/package/verb) | [homepage](https://github.com/verbose/verb)

@@ -1252,3 +1258,3 @@

Copyright © 2015 [Jon Schlinkert](https://github.com/jonschlinkert)
Copyright © 2016 [Jon Schlinkert](https://github.com/jonschlinkert)
Released under the MIT license.

@@ -1258,2 +1264,2 @@

_This file was generated by [verb](https://github.com/verbose/verb) on December 20, 2015._
_This file was generated by [verb](https://github.com/verbose/verb) on January 03, 2016._

Sorry, the diff of this file is not supported yet

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