Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/Guille/express
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed May 14, 2010
2 parents cda1059 + 0581ae8 commit 529f785
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 3 deletions.
1 change: 1 addition & 0 deletions Readme.md
Expand Up @@ -25,6 +25,7 @@
* Route passing
* View support (ejs, haml, sass, etc)
* View partials
* View globals/helpers support
* Full test coverage
* Logger plugin with several formats
* Upload size restrictions
Expand Down
11 changes: 8 additions & 3 deletions lib/express/plugins/view.js
Expand Up @@ -19,7 +19,11 @@ var engines = {}
* View cache.
*/

var cache = { views: {}, partials: {}}
var cache = { views: {}, partials: {} }

// View globals (helpers).

var helpers = exports.helpers = {}

/**
* Cache view files where _type_ is
Expand Down Expand Up @@ -153,6 +157,8 @@ exports.View = Plugin.extend({
layout = options.layout === undefined
? 'layout'
: options.layout
options.locals = options.locals || {}
Object.merge(options.locals, helpers)
options.filename = path
if (set('cache view contents'))
options.cache = true
Expand All @@ -178,5 +184,4 @@ exports.View = Plugin.extend({
})
}
}
})

})
1 change: 1 addition & 0 deletions spec/fixtures/helpers-layout.html.haml
@@ -0,0 +1 @@
Testing
1 change: 1 addition & 0 deletions spec/fixtures/helpers.html.haml
@@ -0,0 +1 @@
%span= _('Hello world')
1 change: 1 addition & 0 deletions spec/fixtures/layout-helper.html.haml
@@ -0,0 +1 @@
%span= _(body)
22 changes: 22 additions & 0 deletions spec/spec.plugins.view.js
@@ -1,5 +1,6 @@

ejs = require('ejs')
helpers = require('express/plugins/view').helpers

describe 'Express'
before_each
Expand Down Expand Up @@ -213,6 +214,27 @@ describe 'Express'
end
end
describe 'when a global is set'
it 'should include the helper and translate the text in the view'
helpers._ = function(text){
if (text == 'Hello world') return 'Hola mundo'
}
get('/', function(){
this.render('helpers.html.haml', { layout: false })
})
get('/').body.should.include 'Hola mundo'
end
it 'should include the helper and translate the text in the layout'
helpers._ = function(text){
if (text == 'Testing') return 'Probando'
}
get('/', function(){
this.render('helpers-layout.html.haml', { layout: 'layout-helper' })
})
get('/').body.should.include 'Probando'
end
end

describe 'when engine cannot be found'
it 'should throw an error'
get('/', function(){
Expand Down

0 comments on commit 529f785

Please sign in to comment.