Added spec / refactored layout of different engine support
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by visionmedia · committed by visionmedia · parent 46bee05 · Browse files · 4 files·+17 added−13 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+17 added−13 removed
- tests:+11 added−9 removed
- other:+6 added−4 removed
Provenance
- Commit
42b28d5- Tree
16ede61- Author
visionmedia <tj@vision-media.ca>- Committer
visionmedia <tj@vision-media.ca>- Parent
46bee05
4 files changed+17 added−13 removed
modified:lib/express/plugins/view.js+6 added-4 removed
158 unmodified linesExpand all1591601611621631641651631641651661671681691701691711721731741757 unmodified lines158 unmodified linesExpand all var content = cache[type][path] || fs.readFileSync(path) options.context = options.context || this content = (engines[engine] = engines[engine] || require(engine)).render(content, options) if (type === 'views') this.contentType(contentType) if (layout) // If the layout has a content type and engine, use that instead of the main view file this.render(layout.match(/\..*\./) ? layout : [layout, contentType, engine].join('.'), Object.mergeDeep(options, { if (layout) { layout = layout.indexOf('.') !== -1 ? layout : [layout, contentType, engine].join('.') this.render(layout, Object.mergeDeep(options, { layout: false, locals: { body: content } }), callback) else if (type === 'partials') } else if (type === 'partials') return content else if (callback) callback.call(this, null, content) else7 unmodified linesadded:spec/fixtures/layout-user.html.haml+2 added
1+%title= "Viewing " + name2+%body!= bodydeleted:spec/fixtures/layout.user.html.haml-2 removed
1-%title= "Viewing " + name2-%body!= bodymodified:spec/spec.plugins.view.js+9 added-7 removed
147 unmodified lines148 get('/').body.should.include '<h2>Hello'149 end150 end151 152+ describe 'given a full layout name'152- describe 'given a layout name with a different engine'153- get('/', function(){154- this.render('hello.html.haml', { layout: 'layout.html.ejs' })155- })156- get('/').body.should.include '<h2>Hello'157- get('/').body.should.include '<p>'153+ it 'should render a layout of a different engine'154+ get('/', function(){155+ this.render('hello.html.haml', { layout: 'layout.html.ejs' })156+ })157+ get('/').body.should.include '<h2>Hello'158+ get('/').body.should.include '<p>'159+ end160 end161 162 describe 'when layout: false'163 it 'should render the view only'30 unmodified lines194 195 it 'should have direct access to locals within the layout'196 get('/user', function(){197 this.render('user.html.haml', {196- layout: 'layout.user',198+ layout: 'layout-user',199 locals: {200 name: 'tj',201 email: 'tj@vision-media.ca'202 }26 unmodified lines