Merge branch 'master' of git://github.com/Guille/express
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by visionmedia · committed by visionmedia · parents cda1059, 0581ae8 · Browse files · 6 files·+34 added−3 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
6 files+34 added−3 removed
- tests:+25 added−0 removed
- other:+9 added−3 removed
Provenance
- Commit
529f785- Tree
3973bf2- Author
visionmedia <tj@vision-media.ca>- Committer
visionmedia <tj@vision-media.ca>- Parent 1
cda1059- Parent 2
0581ae8
6 files changed+34 added−3 removed
modified:lib/express/plugins/view.js+8 added-3 removed
17 unmodified lines181920212222232425262728293031124 unmodified linesExpand all15615715815916016116216316416517 unmodified lines18318418518618118218717 unmodified lines/** * View cache. */ var cache = { views: {}, partials: {}}var cache = { views: {}, partials: {} }
// View globals (helpers).
var helpers = exports.helpers = {}
/** * Cache view files where _type_ is * "partials" or "views". *124 unmodified linesExpand all contentType = parts.slice(-2)[0], 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 var content = cache[type][path] || fs.readFileSync(path)17 unmodified lines } }) } }})
})No newline at end of fileadded:spec/fixtures/helpers-layout.html.haml+1 added
1+Testingadded:spec/fixtures/helpers.html.haml+1 added
1+%span= _('Hello world')added:spec/fixtures/layout-helper.html.haml+1 added
1+%span= _(body)modified:spec/spec.plugins.view.js+22 added
1 2 ejs = require('ejs')3+helpers = require('express/plugins/view').helpers4 5 describe 'Express'6 before_each7 reset()205 unmodified lines213 get('/').body.should.include '<h2>Hello'214 end215 end216 217+ describe 'when a global is set'218+ it 'should include the helper and translate the text in the view'219+ helpers._ = function(text){220+ if (text == 'Hello world') return 'Hola mundo'221+ }222+ get('/', function(){223+ this.render('helpers.html.haml', { layout: false })224+ })225+ get('/').body.should.include 'Hola mundo'226+ end227+ it 'should include the helper and translate the text in the layout'228+ helpers._ = function(text){229+ if (text == 'Testing') return 'Probando'230+ }231+ get('/', function(){232+ this.render('helpers-layout.html.haml', { layout: 'layout-helper' })233+ })234+ get('/').body.should.include 'Probando'235+ end236+ end237+ 238 describe 'when engine cannot be found'239 it 'should throw an error'240 get('/', function(){241 this.render('user.html.invalid')53 unmodified linesmodified:Readme.md+1 added
23 unmodified lines24 * Persistent flash messages25 * Route passing26 * View support (ejs, haml, sass, etc)27 * View partials28+ * View globals/helpers support29 * Full test coverage30 * Logger plugin with several formats31 * Upload size restrictions32 * Extremely readable specs100 unmodified lines