Comparing version 0.2.1 to 0.2.2
25
index.js
@@ -33,15 +33,10 @@ /*! | ||
var Layouts = module.exports = function Layouts(options) { | ||
var opts = _.defaults({}, options, { | ||
delims: ['{{', '}}'], | ||
tag: 'body' | ||
}); | ||
function Layouts(options) { | ||
this.options = _.extend({}, options); | ||
this.defaultTag = this.makeTag(this.options); | ||
this.extend = this.options.extend || _.extend; | ||
this.cache = this.options.cache || {}; | ||
} | ||
this.cache = opts.cache || {}; | ||
this.extend = opts.extend || _.extend; | ||
this.defaultTag = this.makeTag(opts) | ||
this.options = opts; | ||
}; | ||
/** | ||
@@ -59,3 +54,6 @@ * ## .makeTag | ||
Layouts.prototype.makeTag = function (options) { | ||
var opts = _.defaults({}, options, this.options); | ||
var opts = _.extend({}, this.options, options); | ||
opts.delims = opts.delims || ['{{', '}}']; | ||
opts.tag = opts.tag || 'body'; | ||
return [ | ||
@@ -294,1 +292,4 @@ opts.delims[0], | ||
}; | ||
module.exports = Layouts; |
{ | ||
"name": "layouts", | ||
"description": "Wrap templates with layouts. Layouts can be nested and optionally use other layouts.", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"homepage": "https://github.com/jonschlinkert/layouts", | ||
@@ -6,0 +6,0 @@ "author": { |
@@ -15,2 +15,4 @@ /*! | ||
describe('when layouts are defined as objects:', function () { | ||
var layouts = new Layouts(); | ||
layouts.set({a: { layout: 'b', content: 'A above\n{{body}}\nA below' }}); | ||
@@ -49,2 +51,4 @@ layouts.set({b: { layout: 'c', content: 'B above\n{{body}}\nB below' }}); | ||
describe('when layouts are defined with string values:', function () { | ||
var layouts = new Layouts(); | ||
layouts.set('first', 'a', 'I\'m a <%= title %>'); | ||
@@ -84,2 +88,4 @@ layouts.set('a', 'b', 'A above\n{{body}}\nA below'); | ||
describe('when a `layout` propery is defined:', function () { | ||
var layouts = new Layouts(); | ||
layouts.set('first', {layout: 'a'}, 'I\'m a <%= title %>'); | ||
@@ -118,2 +124,4 @@ layouts.set('a', {layout: 'b'}, 'A above\n{{body}}\nA below'); | ||
describe('when a `content` propery is defined:', function () { | ||
var layouts = new Layouts(); | ||
layouts.set('first', {layout: 'a', content: 'I\'m a <%= title %>'}); | ||
@@ -150,3 +158,40 @@ layouts.set('a', {layout: 'b', content: 'A above\n{{body}}\nA below'}); | ||
}); | ||
describe('when multiple layouts are defined', function () { | ||
var layouts = new Layouts(); | ||
layouts.set({ | ||
a: { layout: 'b', content: 'A above\n{{body}}\nA below' }, | ||
b: { layout: 'c', content: 'B above\n{{body}}\nB below' }, | ||
c: { layout: 'd', content: 'C above\n{{body}}\nC below' }, | ||
d: { layout: 'e', content: 'D above\n{{body}}\nD below' }, | ||
last: { layout: undefined, content: 'last!\n{{body}}\nlast!' }, | ||
e: { layout: 'f', content: 'E above\n{{body}}\nE below' }, | ||
f: { layout: 'last', content: 'F above\n{{body}}\nF below' }, | ||
first: { layout: 'a', content: 'I\'m a <%= title %>' } | ||
}); | ||
it('should extend the `cache` with the layout', function () { | ||
var actual = layouts.stack('first'); | ||
var expected = [ | ||
'last!', | ||
'F above', | ||
'E above', | ||
'D above', | ||
'C above', | ||
'B above', | ||
'A above', | ||
'I\'m a <%= title %>', // should not be compiled | ||
'A below', | ||
'B below', | ||
'C below', | ||
'D below', | ||
'E below', | ||
'F below', | ||
'last!' | ||
].join('\n'); | ||
actual.content.should.eql(expected); | ||
}); | ||
}); | ||
}); | ||
}); |
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
35033
841