Skip to content
Myr

Added support for globals (eg: helpers) in views

Before adoption: this commit came in with the history the project adopted, so no landing records it.

- Added export.Globals in plugins/view.js - Added two specs (one for a simple template, one for a template with a layout) with a dummy i18n helper - Updated README features list

authored by Guillermo Rauch · committed by Guillermo Rauch · parent 8ef6a0b · 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

6 files+34 added−3 removed

modified:lib/express/plugins/view.js+8 added-3 removed
added:spec/fixtures/helpers-layout.html.haml+1 added
1Testing
added: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
12ejs = require('ejs')3Globals = require('express/plugins/view').Globals45describe 'Express'6 before_each7 reset()
205 unmodified lines
213 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 Globals._ = 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 Globals._ = 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 lines
modified:Readme.md+1 added
23 unmodified lines
24 * 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 specs
100 unmodified lines