Skip to content
Myr

spec.plugins.view.js

This file

Path

spec/spec.plugins.view.js

294 lines · 9.6 KiB · JavaScript

Last changed by

Renaming `Globals` to `helpers` (I'm sold)Guillermo Rauchbefore adoption0581ae8

History of this file

Take it

The walk stopped after 200 commits: lines older than fbf547d point at it.

Added Session classvisionmediabefore adoptionfbf547d

line 1why, one step back
1

Merge branch 'master' of http://github.com/visionmedia/expressGuillermo Rauchbefore adoption8ef6a0b

line 2why, one step back
2ejs = require('ejs')

Renaming `Globals` to `helpers` (I'm sold)Guillermo Rauchbefore adoption0581ae8

line 3why, one step back
3helpers = require('express/plugins/view').helpers

Merge branch 'master' of http://github.com/visionmedia/expressGuillermo Rauchbefore adoption8ef6a0b

line 4why, one step back
4

Added Session classvisionmediabefore adoptionfbf547d

lines 5–16why, one step back
5describe 'Express'
6 before_each7 reset()8 end9 10 describe 'View'11 describe 'set("views")'12 it 'should default to <root>/views'13 set('root', 'spec')14 set('views').should.eql 'spec/views'15 end16 end

Closes #52visionmediabefore adoption161c9f9

line 17why, one step back
17

Merge branch 'integration'visionmediabefore adoption7d100da

lines 18–26why, one step back
18 describe 'set("partials")'
19 it 'should default to <views>/partials'20 set('root', 'spec')21 set('partials').should.eql 'spec/views/partials'22 set('views', 'magicland')23 set('partials').should.eql 'magicland/partials'24 end25 end26

Merge branch 'master' of http://github.com/visionmedia/expressGuillermo Rauchbefore adoption8ef6a0b

lines 27–38why, one step back
27 describe 'ejs'
28 it 'should work without options'29 var str = '<h2><%= "Title" %></h2>'30 ejs.render(str).should.eql '<h2>Title</h2>'31 end32 33 it 'should work with locals'34 var str = '<h2><%= title %></h2>'35 ejs.render(str, { locals: { title: 'Title' }}).should.eql '<h2>Title</h2>'36 end37 end38

Merge branch 'partials'visionmediabefore adoption28f2ad0

lines 39–41why, one step back
39 describe '#partial()'
40 before_each41 set('views', 'spec/fixtures')

Merge branch 'integration'visionmediabefore adoption7d100da

line 42why, one step back
42 set('partials', 'spec/fixtures/partials')

Merge branch 'partials'visionmediabefore adoption28f2ad0

lines 43–45why, one step back
43 end
44 45 describe 'given a valid view name'

Merge branch 'master' of http://github.com/visionmedia/expressGuillermo Rauchbefore adoption8ef6a0b

lines 46–49why, one step back
46 describe 'with EJS'
47 it 'should render a partial'48 get('/', function(){49 this.render('list.html.ejs', { locals: { items: ['foo', 'bar'] }})

Merge branch 'partials'visionmediabefore adoption28f2ad0

line 50why, one step back
50 })

Merge branch 'master' of http://github.com/visionmedia/expressGuillermo Rauchbefore adoption8ef6a0b

lines 51–60why, one step back
51 get('/').body.should.include '<ul>'
52 get('/').body.should.include '<li>foo'53 get('/').body.should.include '<li>bar'54 end55 56 it 'should render collections'57 get('/', function(){58 return this.partial('item.html.ejs', {59 collection: ['foo', 'bar']60 })

Merge branch 'partials'visionmediabefore adoption28f2ad0

line 61why, one step back
61 })

Merge branch 'master' of http://github.com/visionmedia/expressGuillermo Rauchbefore adoption8ef6a0b

lines 62–86why, one step back
62 get('/').body.should.include '<li>foo'
63 get('/').body.should.include '<li>bar'64 end65 66 it 'should render collections with a given object name'67 get('/', function(){68 return this.partial('video.html.ejs', {69 collection: ['im a movie', 'im another movie'],70 as: 'vid'71 })72 })73 get('/').body.should.include '<li>im a movie'74 get('/').body.should.include '<li>im another movie'75 end76 77 it 'should pass __isFirst__, __isLast__, and __index__ to partials as locals'78 get('/', function(){79 return this.partial('article.html.ejs', {80 collection: ['a', 'b', 'c']81 })82 })83 get('/').body.should.include '<li class="first">a'84 get('/').body.should.include '<li class="1">b'85 get('/').body.should.include '<li class="last">c'86 end

Merge branch 'partials'visionmediabefore adoption28f2ad0

line 87why, one step back
87 end

Merge branch 'master' of http://github.com/visionmedia/expressGuillermo Rauchbefore adoption8ef6a0b

lines 88–91why, one step back
88 describe 'with Haml'
89 it 'should render a partial'90 get('/', function(){91 this.render('list.html.haml', { locals: { items: ['foo', 'bar'] }})

Merge branch 'partial-index-and-length'visionmediabefore adoptionb2093d6

line 92why, one step back
92 })

Merge branch 'master' of http://github.com/visionmedia/expressGuillermo Rauchbefore adoption8ef6a0b

lines 93–128why, one step back
93 get('/').body.should.include '<ul>'
94 get('/').body.should.include '<li>foo'95 get('/').body.should.include '<li>bar'96 end97 98 it 'should render collections'99 get('/', function(){100 return this.partial('item.html.haml', {101 collection: ['foo', 'bar']102 })103 })104 get('/').body.should.include '<li>foo'105 get('/').body.should.include '<li>bar'106 end107 108 it 'should render collections with a given object name'109 get('/', function(){110 return this.partial('video.html.haml', {111 collection: ['im a movie', 'im another movie'],112 as: 'vid'113 })114 })115 get('/').body.should.include '<li>im a movie'116 get('/').body.should.include '<li>im another movie'117 end118 119 it 'should pass __isFirst__, __isLast__, and __index__ to partials as locals'120 get('/', function(){121 return this.partial('article.html.haml', {122 collection: ['a', 'b', 'c']123 })124 })125 get('/').body.should.include '<li class="first">a'126 get('/').body.should.include '<li class="1">b'127 get('/').body.should.include '<li class="last">c'128 end

Merge branch 'partial-index-and-length'visionmediabefore adoptionb2093d6

line 129why, one step back
129 end

Merge branch 'partials'visionmediabefore adoption28f2ad0

lines 130–132why, one step back
130 end
131 end132

Closes #52visionmediabefore adoption161c9f9

lines 133–137why, one step back
133 describe '#render()'
134 before_each135 set('views', 'spec/fixtures')136 end137

Added Request#render() callback function. Closes #258visionmediabefore adoption7b9f18b

lines 138–140why, one step back
138 describe 'given a callback'
139 it 'should be passed the rendered content'140 get('/', function(){

Merge branch 'master' of http://github.com/visionmedia/expressGuillermo Rauchbefore adoption8ef6a0b

line 141why, one step back
141 this.render('hello.html.haml', {}, function(err, content){

Added Request#render() callback function. Closes #258visionmediabefore adoption7b9f18b

line 142why, one step back
142 if (err) this.error(err)

Merge branch 'master' of http://github.com/visionmedia/expressGuillermo Rauchbefore adoption8ef6a0b

line 143why, one step back
143 else this.respond(203, content)

Added Request#render() callback function. Closes #258visionmediabefore adoption7b9f18b

lines 144–145why, one step back
144 })
145 })

Merge branch 'master' of http://github.com/visionmedia/expressGuillermo Rauchbefore adoption8ef6a0b

line 146why, one step back
146 get('/').body.should.include '<html>\n<body>'

Added Request#render() callback function. Closes #258visionmediabefore adoption7b9f18b

lines 147–150why, one step back
147 get('/').status.should.eql 203
148 end149 end150

Closes #52visionmediabefore adoption161c9f9

lines 151–154why, one step back
151 describe 'given a valid view name'
152 describe 'and layout of the same type exists'153 it 'should render the layout and view'154 get('/', function(){

Merge branch 'master' of http://github.com/visionmedia/expressGuillermo Rauchbefore adoption8ef6a0b

line 155why, one step back
155 this.render('hello.html.haml')

Closes #52visionmediabefore adoption161c9f9

line 156why, one step back
156 })

Merge branch 'master' of http://github.com/visionmedia/expressGuillermo Rauchbefore adoption8ef6a0b

line 157why, one step back
157 get('/').body.should.include '<html>\n<body>'

Closes #52visionmediabefore adoption161c9f9

lines 158–163why, one step back
158 get('/').body.should.include '<h2>Hello'
159 end160 161 it 'should default context to the current request'162 get('/', function(){163 this.title = 'Welcome'

Merge branch 'master' of http://github.com/visionmedia/expressGuillermo Rauchbefore adoption8ef6a0b

line 164why, one step back
164 this.render('page.html.haml', { layout: false })

Closes #52visionmediabefore adoption161c9f9

lines 165–170why, one step back
165 })
166 get('/').body.should.include '<title>Welcome'167 end168 169 it 'should set the content type based on the last path segment'170 get('/', function(){

Merge branch 'master' of http://github.com/visionmedia/expressGuillermo Rauchbefore adoption8ef6a0b

line 171why, one step back
171 this.render('hello.html.haml')

Closes #52visionmediabefore adoption161c9f9

line 172why, one step back
172 })

Merge branch 'master' of http://github.com/visionmedia/expressGuillermo Rauchbefore adoption8ef6a0b

line 173why, one step back
173 get('/').headers['Content-Type'].should.eql 'text/html'

Closes #52visionmediabefore adoption161c9f9

lines 174–179why, one step back
174 end
175 end176 177 describe 'and layout of the same type does not exist'178 it 'should throw an error'179 get('/', function(){

Merge branch 'master' of http://github.com/visionmedia/expressGuillermo Rauchbefore adoption8ef6a0b

line 180why, one step back
180 this.render('hello.html.haml', { layout: 'front' })

Closes #52visionmediabefore adoption161c9f9

line 181why, one step back
181 })

Merge branch 'master' of http://github.com/visionmedia/expressGuillermo Rauchbefore adoption8ef6a0b

line 182why, one step back
182 -{ get('/') }.should.throw_error 'ENOENT, No such file or directory'

Closes #52visionmediabefore adoption161c9f9

lines 183–189why, one step back
183 end
184 end185 186 describe 'given a custom layout name'187 it 'should render the layout and view'188 get('/', function(){189 this.title = 'Express'

Merge branch 'master' of http://github.com/visionmedia/expressGuillermo Rauchbefore adoption8ef6a0b

line 190why, one step back
190 this.render('hello.html.haml', { layout: 'page' })

Closes #52visionmediabefore adoption161c9f9

lines 191–196why, one step back
191 })
192 get('/').body.should.include '<title>Express'193 get('/').body.should.include '<h2>Hello'194 end195 end196

Merge branch 'master' of http://github.com/visionmedia/expressGuillermo Rauchbefore adoption8ef6a0b

lines 197–206why, one step back
197 describe 'given a full layout name'
198 it 'should render a layout of a different engine'199 get('/', function(){200 this.render('hello.html.haml', { layout: 'layout.html.ejs' })201 })202 get('/').body.should.include '<h2>Hello'203 get('/').body.should.include '<p>'204 end205 end206

Closes #52visionmediabefore adoption161c9f9

lines 207–209why, one step back
207 describe 'when layout: false'
208 it 'should render the view only'209 get('/', function(){

Merge branch 'master' of http://github.com/visionmedia/expressGuillermo Rauchbefore adoption8ef6a0b

line 210why, one step back
210 this.render('hello.html.haml', { layout: false })

Closes #52visionmediabefore adoption161c9f9

lines 211–213why, one step back
211 })
212 get('/').body.should.not.include '<body>'213 get('/').body.should.include '<h2>Hello'

Added support for globals (eg: helpers) in viewsGuillermo Rauchbefore adoption216cb1e

lines 214–218why, one step back
214 end
215 end216 217 describe 'when a global is set'218 it 'should include the helper and translate the text in the view'

Renaming `Globals` to `helpers` (I'm sold)Guillermo Rauchbefore adoption0581ae8

line 219why, one step back
219 helpers._ = function(text){

Added support for globals (eg: helpers) in viewsGuillermo Rauchbefore adoption216cb1e

lines 220–227why, one step back
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'

Renaming `Globals` to `helpers` (I'm sold)Guillermo Rauchbefore adoption0581ae8

line 228why, one step back
228 helpers._ = function(text){

Added support for globals (eg: helpers) in viewsGuillermo Rauchbefore adoption216cb1e

lines 229–234why, one step back
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'

Closes #52visionmediabefore adoption161c9f9

lines 235–240why, one step back
235 end
236 end237 238 describe 'when engine cannot be found'239 it 'should throw an error'240 get('/', function(){

Merge branch 'master' of http://github.com/visionmedia/expressGuillermo Rauchbefore adoption8ef6a0b

line 241why, one step back
241 this.render('user.html.invalid')

Closes #52visionmediabefore adoption161c9f9

lines 242–249why, one step back
242 })
243 -{ get('/') }.should.throw_error "Cannot find module 'invalid'"244 end245 end246 247 describe 'when locals are passed'248 it 'should have direct access to locals'249 get('/user', function(){

Merge branch 'master' of http://github.com/visionmedia/expressGuillermo Rauchbefore adoption8ef6a0b

line 250why, one step back
250 this.render('user.html.haml', {

Closes #52visionmediabefore adoption161c9f9

lines 251–262why, one step back
251 locals: {
252 name: 'tj',253 email: 'tj@vision-media.ca'254 }255 })256 })257 get('/user').body.should.include '<h1>tj'258 get('/user').body.should.include '<p>tj@vision-media.ca'259 end260 261 it 'should have direct access to locals within the layout'262 get('/user', function(){

Merge branch 'master' of http://github.com/visionmedia/expressGuillermo Rauchbefore adoption8ef6a0b

lines 263–264why, one step back
263 this.render('user.html.haml', {
264 layout: 'layout-user',

Closes #52visionmediabefore adoption161c9f9

lines 265–279why, one step back
265 locals: {
266 name: 'tj',267 email: 'tj@vision-media.ca'268 }269 })270 })271 get('/user').body.should.include '<title>Viewing tj'272 get('/user').body.should.include '<h1>tj'273 get('/user').body.should.include '<p>tj@vision-media.ca'274 end275 end276 277 describe 'when context is passed'278 it 'should evaluate in context to that object'279 get('/article', function(){

Merge branch 'master' of http://github.com/visionmedia/expressGuillermo Rauchbefore adoption8ef6a0b

line 280why, one step back
280 this.render('article.html.haml', {

Closes #52visionmediabefore adoption161c9f9

lines 281–292why, one step back
281 context: {
282 name: 'Writing a Node.js Web Application'283 }284 })285 })286 get('/article').body.should.include '<h2>Writing a Node.js Web Application'287 end288 end289 290 end291 292 end

Added Session classvisionmediabefore adoptionfbf547d

lines 293–294why, one step back
293 end
294end