Comparing version 0.1.0 to 0.1.1
45
index.js
@@ -24,3 +24,3 @@ /*! | ||
* var Layouts = require('layouts'); | ||
* var layout = new Layouts(); | ||
* var layouts = new Layouts(); | ||
* ``` | ||
@@ -94,3 +94,3 @@ * | ||
* ```js | ||
* layout.set('a', 'b', '<h1>Foo</h1>\n{{body}}\n'); | ||
* layouts.set('a', 'b', '<h1>Foo</h1>\n{{body}}\n'); | ||
* ``` | ||
@@ -128,3 +128,3 @@ * | ||
* ```js | ||
* layout.get('a'); | ||
* layouts.get('a'); | ||
* //=> { layout: 'b', content: '<h1>Foo</h1>\n{{body}}\n' } | ||
@@ -148,5 +148,4 @@ * ``` | ||
* | ||
* Assert whether or not a layout should be used based on | ||
* the given `value`. If a layout should be used, the name of the | ||
* layout is returned, if not `null` is returned. | ||
* Extend `data` with the given `obj. A custom function can be | ||
* passed on `options.extend` to change how data is merged. | ||
* | ||
@@ -212,3 +211,3 @@ * @param {*} `value` | ||
/** | ||
* ## .wrap | ||
* ## .stack | ||
* | ||
@@ -220,4 +219,3 @@ * Flatten nested layouts. | ||
* ```js | ||
* var page = layout.wrap('base'); | ||
* var tmpl = _.template(page, context); | ||
* var layout = layouts.stack('base'); | ||
* ``` | ||
@@ -227,6 +225,6 @@ * | ||
* @return {String} Resulting flattened layout. | ||
* @api public | ||
* @api private | ||
*/ | ||
Layouts.prototype.wrap = function (name) { | ||
Layouts.prototype.stack = function (name) { | ||
var stack = this.createStack(name); | ||
@@ -245,1 +243,26 @@ var data = {}; | ||
/** | ||
* ## .inject | ||
* | ||
* Flatten nested layouts. | ||
* | ||
* **Example:** | ||
* | ||
* ```js | ||
* var page = layouts.inject(str, 'base'); | ||
* var tmpl = _.template(page, context); | ||
* ``` | ||
* | ||
* @param {String} `name` The layout to start with. | ||
* @return {String} Resulting flattened layout. | ||
* @api private | ||
*/ | ||
Layouts.prototype.inject = function (str, name) { | ||
var layout = this.stack(name); | ||
if (layout.content) { | ||
str = layout.content.replace(this.regex, str); | ||
} | ||
return {data: layout.data, content: str}; | ||
}; |
{ | ||
"name": "layouts", | ||
"description": "Wrap templates with layouts. Layouts can use/refer to other layouts, allowing them to be nested.", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"homepage": "https://github.com/jonschlinkert/layouts", | ||
@@ -81,2 +81,2 @@ "author": { | ||
} | ||
} | ||
} |
/*! | ||
* nested layouts | ||
* layouts <https://github.com/jonschlinkert/layouts> | ||
* | ||
* Copyright (c) 2014 nested layouts, contributors | ||
* Copyright (c) 2014 Jon Schlinkert, contributors | ||
* Licensed under the MIT License (MIT) | ||
*/ | ||
'use strict'; | ||
var should = require('should'); | ||
@@ -30,3 +32,3 @@ var Layouts = require('..'); | ||
// Define the name of the cached template to start with | ||
var actual = layouts.wrap('simple'); | ||
var actual = layouts.stack('simple'); | ||
var expected = [ | ||
@@ -41,3 +43,3 @@ 'base!', | ||
it('should extend the `cache`.', function () { | ||
var actual = layouts.wrap('foo'); | ||
var actual = layouts.stack('foo'); | ||
var expected = [ | ||
@@ -44,0 +46,0 @@ 'base!', |
/*! | ||
* nested layouts | ||
* layouts <https://github.com/jonschlinkert/layouts> | ||
* | ||
* Copyright (c) 2014 nested layouts, contributors | ||
* Copyright (c) 2014 Jon Schlinkert, contributors | ||
* Licensed under the MIT License (MIT) | ||
@@ -25,3 +25,3 @@ */ | ||
it('should return an extended data object from the flattened layouts.', function () { | ||
var actual = layouts.wrap('foo'); | ||
var actual = layouts.stack('foo'); | ||
var expected = [ | ||
@@ -28,0 +28,0 @@ 'base!', |
/*! | ||
* nested layouts | ||
* layouts <https://github.com/jonschlinkert/layouts> | ||
* | ||
* Copyright (c) 2014 nested layouts, contributors | ||
* Copyright (c) 2014 Jon Schlinkert, contributors | ||
* Licensed under the MIT License (MIT) | ||
@@ -35,3 +35,3 @@ */ | ||
// Define the name of the cached template to start with | ||
var actual = layouts.wrap('simple'); | ||
var actual = layouts.stack('simple'); | ||
var expected = [ | ||
@@ -49,3 +49,3 @@ 'base!', | ||
// Define the name of the cached template to start with | ||
var actual = layouts.wrap('foo'); | ||
var actual = layouts.stack('foo'); | ||
var expected = [ | ||
@@ -52,0 +52,0 @@ 'base!', |
/*! | ||
* nested layouts | ||
* layouts <https://github.com/jonschlinkert/layouts> | ||
* | ||
* Copyright (c) 2014 nested layouts, contributors | ||
* Copyright (c) 2014 Jon Schlinkert, contributors | ||
* Licensed under the MIT License (MIT) | ||
@@ -23,3 +23,3 @@ */ | ||
it('should merge the context so that the inner-most templates context wins.', function () { | ||
var actual = layouts.wrap('foo'); | ||
var actual = layouts.stack('foo'); | ||
var expected = [ | ||
@@ -47,3 +47,3 @@ 'base!', | ||
it('should change the order in which the context is merged.', function () { | ||
var actual = layouts.wrap('foo'); | ||
var actual = layouts.stack('foo'); | ||
var expected = [ | ||
@@ -50,0 +50,0 @@ 'base!', |
/*! | ||
* nested layouts | ||
* layouts <https://github.com/jonschlinkert/layouts> | ||
* | ||
* Copyright (c) 2014 nested layouts, contributors | ||
* Copyright (c) 2014 Jon Schlinkert, contributors | ||
* Licensed under the MIT License (MIT) | ||
@@ -25,3 +25,3 @@ */ | ||
it('should extend the `cache`.', function () { | ||
var actual = layouts.wrap('foo'); | ||
var actual = layouts.stack('foo'); | ||
var expected = [ | ||
@@ -59,3 +59,3 @@ 'base!', | ||
it('should extend the `cache`.', function () { | ||
var actual = layouts.wrap('foo'); | ||
var actual = layouts.stack('foo'); | ||
var expected = [ | ||
@@ -62,0 +62,0 @@ 'base!', |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
22266
519
1