Skip to content

Commit

Permalink
Make locals available in layouts. Fixes #3
Browse files Browse the repository at this point in the history
  • Loading branch information
Soarez committed Sep 6, 2012
1 parent c083787 commit 1dbff32
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -7,4 +7,4 @@ test:
.PHONY: test

watch:
./node_modules/.bin/mocha --reporter min -w
./node_modules/.bin/mocha --reporter min -w --growl
6 changes: 6 additions & 0 deletions lib/express-layouts.js
Expand Up @@ -78,6 +78,12 @@ module.exports = exports = function(req, res, next) {
}

var locals = { body: str }
for (var l in options) {
if (options.hasOwnProperty(l)
&& l != 'layout'
&& l != 'contentFor')
locals[l] = options[l];
}

if (options.extractScripts === true
|| (options.extractScripts === undefined && app.get('layout extractScripts') === true))
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -3,7 +3,7 @@
"name": "express-ejs-layouts",
"description": "Layout support for ejs in express.",
"keywords": ["express", "layout", "ejs"],
"version": "0.1.0",
"version": "0.2.0",
"main": "lib/express-layouts.js",
"dependencies": {},
"devDependencies": {
Expand Down
11 changes: 11 additions & 0 deletions test/ejs.js
Expand Up @@ -137,5 +137,16 @@ describe('rendering contentFor', function() {
done()
})
})

it ('should provide the locals to the layout aswell', function(done) {
app.use(function(req, res){
res.render(__dirname + '/fixtures/view.ejs',
{ layout: 'layoutWithMultipleContent', foo: 'oof', bar: 'rab' })
})
req(function(body){
body.should.equal('rab\\/oof\nhi')
done()
})
})
})

0 comments on commit 1dbff32

Please sign in to comment.