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

layouts

Package Overview
Dependencies
Maintainers
2
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

layouts - npm Package Compare versions

Comparing version 0.3.1 to 0.3.2

120

index.js

@@ -13,5 +13,7 @@ /*!

var Cache = require('config-cache');
var Delims = require('delims');
var delims = new Delims();
var _ = require('lodash');
var delims = new (require('delims'))();
/**

@@ -132,2 +134,3 @@ * Create a new instance of `Layouts`, optionally passing the default

}
this.cache[name] = {

@@ -138,3 +141,2 @@ layout: (data && data.layout) ? data.layout : data,

};
return this;

@@ -145,25 +147,2 @@ };

/**
* Define the default layout variable and delimiters to be used.
*
* @api private
*/
Layouts.prototype._defaultLayout = function (context, options) {
var opts = _.extend({}, options);
var tag = (this.makeTag(options) || this.defaultTag).replace(/\s/g, '');
var variable = options.tag || 'body';
var settings = _.extend(delims.templates(options.delims || ['{{','}}']), options);
settings.interpolate = settings.evaluate;
return {
variable: tag,
context: opts,
settings: settings
};
};
/**
* Get a cached template by `name`.

@@ -180,2 +159,3 @@ *

* @return {Object} The template object to return.
* @api public
*/

@@ -192,2 +172,23 @@

/**
* Define the default layout variable and delimiters to be used.
*
* @api private
*/
Layouts.prototype._defaultLayout = function (context, options) {
var opts = _.extend({}, options);
var tag = (this.makeTag(options) || this.defaultTag).replace(/\s/g, '');
var settings = _.extend(delims.templates(options.delims || ['{{','}}']), options);
settings.interpolate = settings.evaluate;
return {
variable: tag,
context: opts,
settings: settings
};
};
/**
* Assert whether or not a layout should be used based on

@@ -214,33 +215,2 @@ * the given `value`. If a layout should be used, the name of the

/**
* Extend `data` with the given `obj. A custom `_extendMethod` can be
* passed on `options.extend` to change how data is merged.
*
* @param {Object} `opts` Pass an options object with `data` or `locals`
* @return {Object} `file` A `file` to with `data` to be merged.
* @api private
*/
Layouts.prototype._mergeData = function (opts, file) {
var data = {};
// build up the `data` object
_.extend(data, opts, opts.locals, opts.data);
_.extend(data, file, file.data);
// Flatten nested `data` objects
this.flattenData(data);
// Extend the context
this._extendMethod(this.context, _.omit(data, [
'extend',
'content',
'delims',
'layout'
]));
return this;
};
/**
* Build a layout stack.

@@ -287,3 +257,3 @@ *

* @return {Array} The file's layout stack is returned as an array.
* @api private
* @api public
*/

@@ -342,2 +312,3 @@

* @return {String} Rendered string.
* @api public
*/

@@ -408,2 +379,37 @@

/**
* Extend `data` with the given `obj. A custom `_extendMethod` can be
* passed on `options.extend` to change how data is merged.
*
* @param {Object} `opts` Pass an options object with `data` or `locals`
* @return {Object} `file` A `file` to with `data` to be merged.
* @api private
*/
Layouts.prototype._mergeData = function (opts, file) {
var data = {};
// build up the `data` object
_.extend(data, opts, opts.locals, opts.data);
_.extend(data, file, file.data);
// Flatten nested `data` objects
this.flattenData(data);
// Extend the context
this._extendMethod(this.context, _.omit(data, [
'extend',
'content',
'delims',
'layout'
]));
return this;
};
/**
* Expose `Layouts`
*/
module.exports = Layouts;
{
"name": "layouts",
"description": "Wrap templates with layouts. Layouts can be nested and optionally use other layouts.",
"version": "0.3.1",
"version": "0.3.2",
"homepage": "https://github.com/jonschlinkert/layouts",

@@ -80,3 +80,3 @@ "author": {

"verb": ">= 0.2.6",
"verb-tag-jscomments": "^0.2.0"
"verb-tag-jscomments": "^0.2.2"
},

@@ -83,0 +83,0 @@ "dependencies": {

@@ -19,10 +19,9 @@ # layouts [![NPM version](https://badge.fury.io/js/layouts.png)](http://badge.fury.io/js/layouts)

## API
[## Layouts](index.js#L33)
### [.setLayout](index.js#L128)
Create a new instance of `Layouts`, optionally passing the default `cache` and `options` to use.
Store a template on the cache by its `name`, the `layout` to use, and the template's `content.
* `cache` **{Object}**: A template cache. See [Layouts#set](#set) for object details.
* `options` **{Object}**: Options to use.
* `options.delims` **{Array}**: Template delimiters to use formatted as an array (`['{{', '}}']`)
* `options.tag` **{String}**: The tag name to use. Default is `body` (e.g. `{{ body }}`)
* `name` **{String|Object}**: If `name` is a string, `layout` and `content` are required.
* `data` **{String|Object}**: Pass a string defining the name of layout to use for the given template, or pass an object with a `layout` property.
* `content` **{String}**: The template "content", this will not be compiled or rendered.

@@ -32,50 +31,40 @@ **Example:**

```js
var Layouts = require('layouts');
var layouts = new Layouts();
layouts.setLayout('a', 'b', '<h1>Foo</h1>\n{{body}}\n');
```
### [.getLayout](index.js#L158)
[## setLayout](index.js#L104)
Get a cached template by `name`.
Store a template on the cache by its `name`, the `layout` to use, and the template's `content.
* `name` **{String}**
* `returns` **{Object}**: The template object to return.
* `name` **{String|Object}**: If `name` is a string, `layout` and `content` are required.
* `data` **{String|Object}**: Pass a string defining the name of layout to use for the given template, or pass an object with a `layout` property.
* `content` **{String}**: The template "content", this will not be compiled or rendered.
**Example:**
```js
layouts.setLayout('a', 'b', '<h1>Foo</h1>\n{{body}}\n');
layouts.getLayout('a');
//=> { layout: 'b', content: '<h1>Foo</h1>\n{{body}}\n' }
```
### [.stack](index.js#L253)
[## _defaultLayout](index.js#L123)
Reduce a layout stack for a template into a single flattened layout. Pass the `name` of the layout defined for the template (e.g. the first layout in the stack).
* `name` **{String}**: The layout to start with.
* `options` **{Object}**
* `returns` **{Array}**: The file's layout stack is returned as an array.
Define the default layout variable and delimiters to be used.
[## getLayout](index.js#L154)
Get a cached template by `name`.
* `name` **{String}**
* returns **{Object}**: The template object to return.
**Example:**
```js
layouts.getLayout('a');
//=> { layout: 'b', content: '<h1>Foo</h1>\n{{body}}\n' }
layouts.stack('base');
```
### [.renderLayout](index.js#L307)
[## renderLayout](index.js#L312)
Render a layout using Lo-Dash, by passing content (`str`), `context` and `options`.
* `str` **{String}**: Content for the layout to render.
* `options` **{Object}**: Additional options used for building the render settings.
* returns **{String}**: Rendered string.
* `str` **{String}**: Content for the layout to render.
* `options` **{Object}**: Additional options used for building the render settings.
* `returns` **{String}**: Rendered string.

@@ -101,10 +90,9 @@ **Example:**

### [.replaceTag](index.js#L337)
[## replaceTag](index.js#L342)
Replace a `{{body}}` tag with the given `str`. Custom delimiters and/or variable may be passed on the `options`. Unlike `renderLayout`, this method does not render templates, it only peforms a basic regex replacement.
* `str` **{String}**: The string to use as a replacement value.
* `content` **{String}**: A string with a `{{body}}` tag where the `str` should be injected.
* returns **{String}**: Resulting flattened content.
* `str` **{String}**: The string to use as a replacement value.
* `content` **{String}**: A string with a `{{body}}` tag where the `str` should be injected.
* `returns` **{String}**: Resulting flattened content.

@@ -118,10 +106,9 @@ **Example:**

### [.render](index.js#L360)
[## inject](index.js#L365)
Return an object with the string (`str`) and `data` required to build a final layout. This is useful if you need to use your own template engine to handle this final step.
* `str` **{String}**: The string to be injected into the layout. Usually a page, or inner layout, etc.
* `name` **{String}**: The name of the first layout to use to build the stack.
* returns **{Object}**: Resulting flattened layout.
* `str` **{String}**: The string to be injected into the layout. Usually a page, or inner layout, etc.
* `name` **{String}**: The name of the first layout to use to build the stack.
* `returns` **{Object}**: Resulting flattened layout.

@@ -131,3 +118,3 @@ **Example:**

```js
var page = layouts.inject(str, 'base');
var page = layouts.render(str, 'base');
var tmpl = _.template(page, context);

@@ -149,2 +136,2 @@ ```

_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on August 17, 2014._
_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on August 29, 2014._
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