Comparing version 0.2.6 to 0.2.7
34
index.js
@@ -14,4 +14,4 @@ /*! | ||
var _ = require('lodash'); | ||
var delims = new (require('delims'))(); | ||
/** | ||
@@ -247,3 +247,3 @@ * ## Layouts | ||
content = content.replace(this.regex, tmpl.content); | ||
content = _.template(content, this.context); | ||
content = this.renderLayout(content, opts); | ||
@@ -261,2 +261,32 @@ return { | ||
/** | ||
* ## .renderLayout | ||
* | ||
* Render an individual layout layer with it's current context. | ||
* | ||
* **Example:** | ||
* | ||
* ```js | ||
* content = this.renderLayout(content, options); | ||
* ``` | ||
* @param {String} `content` content for the layout to render | ||
* @param {Object} `options` additional options used for building the render settings | ||
* @return {String} rendered content | ||
*/ | ||
Layouts.prototype.renderLayout = function (content, options) { | ||
var tag = (this.makeTag(options) || this.defaultTag).replace(/\s/g, ''); | ||
var body = options.tag || 'body'; | ||
var settings = delims.templates(options.delims || ['{{','}}']); | ||
settings.interpolate = settings.evaluate; | ||
this.context[body] = tag; | ||
content = _.template(content, this.context, settings); | ||
delete this.context[body]; | ||
return content | ||
}; | ||
/** | ||
* ## .replaceTag | ||
@@ -263,0 +293,0 @@ * |
{ | ||
"name": "layouts", | ||
"description": "Wrap templates with layouts. Layouts can be nested and optionally use other layouts.", | ||
"version": "0.2.6", | ||
"version": "0.2.7", | ||
"homepage": "https://github.com/jonschlinkert/layouts", | ||
@@ -85,2 +85,3 @@ "author": { | ||
"debug": "^1.0.4", | ||
"delims": "^0.3.0", | ||
"falsey": "^0.1.0", | ||
@@ -87,0 +88,0 @@ "lodash": "^2.4.1" |
@@ -18,3 +18,3 @@ /*! | ||
cache: { | ||
first: { layout: 'a', content: 'I\'m a <%= title %>' }, | ||
first: { layout: 'a', content: 'I\'m a {{ title }}' }, | ||
a: { layout: 'b', content: 'A above\n{{body}}\nA below' }, | ||
@@ -35,3 +35,3 @@ b: { layout: 'c', content: 'B above\n{{body}}\nB below' }, | ||
layouts.setLayout('first', 'a', 'I\'m a <%= title %>'); | ||
layouts.setLayout('first', 'a', 'I\'m a {{ title }}'); | ||
layouts.setLayout('a', 'b', 'A above\n{{body}}\nA below'); | ||
@@ -38,0 +38,0 @@ layouts.setLayout('b', 'c', 'B above\n{{body}}\nB below'); |
@@ -24,3 +24,3 @@ /*! | ||
layouts.setLayout({f: { layout: 'last', content: 'F above\n{{body}}\nF below' }}); | ||
layouts.setLayout({first: { title: 'first', layout: 'a', content: 'I\'m a <%= title %>' }}); | ||
layouts.setLayout({first: { title: 'first', layout: 'a', content: 'I\'m a {{ title }}' }}); | ||
@@ -89,3 +89,3 @@ it('should extend the `cache`.', function () { | ||
layouts.setLayout('first', {title: 'first', layout: 'a'}, 'I\'m a <%= title %>'); | ||
layouts.setLayout('first', {title: 'first', layout: 'a'}, 'I\'m a {{ title }}'); | ||
layouts.setLayout('a', {layout: 'b'}, 'A above\n{{body}}\nA below'); | ||
@@ -125,3 +125,3 @@ layouts.setLayout('b', {layout: 'c'}, 'B above\n{{body}}\nB below'); | ||
layouts.setLayout('first', {title: 'first', layout: 'a', content: 'I\'m a <%= title %>'}); | ||
layouts.setLayout('first', {title: 'first', layout: 'a', content: 'I\'m a {{ title }}'}); | ||
layouts.setLayout('a', {layout: 'b', content: 'A above\n{{body}}\nA below'}); | ||
@@ -169,3 +169,3 @@ layouts.setLayout('b', {layout: 'c', content: 'B above\n{{body}}\nB below'}); | ||
f: { layout: 'last', content: 'F above\n{{body}}\nF below' }, | ||
first: { title: 'first', layout: 'a', content: 'I\'m a <%= title %>' } | ||
first: { title: 'first', layout: 'a', content: 'I\'m a {{ title }}' } | ||
}); | ||
@@ -172,0 +172,0 @@ |
@@ -19,8 +19,8 @@ /*! | ||
layouts.set({first: { layout: 'a', content: '{{body}}' }}); | ||
layouts.set({a: { layout: 'b', a: 'b', title: 'A', content: '<%= title %> above\n{{body}}\n<%= title %> below' }}); | ||
layouts.set({b: { layout: 'c', c: 'd', title: 'B', content: '<%= title %> above\n{{body}}\n<%= title %> below' }}); | ||
layouts.set({c: { layout: 'd', e: 'f', title: 'C', content: '<%= title %> above\n{{body}}\n<%= title %> below' }}); | ||
layouts.set({d: { layout: 'e', g: 'h', title: 'D', content: '<%= title %> above\n{{body}}\n<%= title %> below' }}); | ||
layouts.set({e: { layout: 'f', i: 'j', title: 'E', content: '<%= title %> above\n{{body}}\n<%= title %> below' }}); | ||
layouts.set({f: { layout: 'last', data: {one: 'two'}, title: 'F', content: '<%= title %> above\n{{body}}\n<%= title %> below' }}); | ||
layouts.set({a: { layout: 'b', a: 'b', title: 'A', content: '{{ title }} above\n{{body}}\n{{ title }} below' }}); | ||
layouts.set({b: { layout: 'c', c: 'd', title: 'B', content: '{{ title }} above\n{{body}}\n{{ title }} below' }}); | ||
layouts.set({c: { layout: 'd', e: 'f', title: 'C', content: '{{ title }} above\n{{body}}\n{{ title }} below' }}); | ||
layouts.set({d: { layout: 'e', g: 'h', title: 'D', content: '{{ title }} above\n{{body}}\n{{ title }} below' }}); | ||
layouts.set({e: { layout: 'f', i: 'j', title: 'E', content: '{{ title }} above\n{{body}}\n{{ title }} below' }}); | ||
layouts.set({f: { layout: 'last', data: {one: 'two'}, title: 'F', content: '{{ title }} above\n{{body}}\n{{ title }} below' }}); | ||
layouts.set({last: { layout: undefined, content: 'last!\n{{body}}\nlast!' }}); | ||
@@ -27,0 +27,0 @@ |
Sorry, the diff of this file is not supported yet
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
40457
966
5
+ Addeddelims@^0.3.0
+ Addeddelims@0.3.0(transitive)
+ Addedxtend@3.0.0(transitive)