Skip to content

Commit

Permalink
Merged bdotdub/master
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed May 6, 2010
2 parents b8833f4 + 57f4978 commit cb8e704
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 36 deletions.
1 change: 1 addition & 0 deletions examples/hello-world/app.js
Expand Up @@ -10,6 +10,7 @@ get('/', function(){
this.render('front.html.ejs', {
locals: {
title: 'Hello World',
name: 'Joe',
items: ['one', 'two', 'three']
}
})
Expand Down
1 change: 1 addition & 0 deletions examples/hello-world/views/front.html.ejs
@@ -1,4 +1,5 @@
<h1><%= title %></h1>
<%= this.partial("greeting.html.ejs", { locals: { name: name } }) %>
<% if (items && items.length) { %>
<ul>
<% for (var i = 0; i < items.length; ++i) { %>
Expand Down
1 change: 1 addition & 0 deletions examples/hello-world/views/partials/greeting.html.ejs
@@ -0,0 +1 @@
Welcome back, <strong><%= name %></strong>!
2 changes: 1 addition & 1 deletion lib/support/ejs/lib/ejs.js
Expand Up @@ -21,6 +21,6 @@ exports.render = function(str, options) {
.split("%>").join("p.push('")
.split("\r").join("\\'")
+ "');}return p.join('');")
return fn(options.locals || {})
return fn.call(options.context, options.locals || {})
}

5 changes: 5 additions & 0 deletions spec/fixtures/list.html.ejs
@@ -0,0 +1,5 @@
<ul>
<% for (idx in items) { %>
<%= this.partial("item.html.ejs", { locals: { item: items[idx] }}) %>
<% } %>
</ul>
9 changes: 9 additions & 0 deletions spec/fixtures/partials/article.html.ejs
@@ -0,0 +1,9 @@
<ul>
<% if (__isFirst__) { %>
<li class="first"><%= article %></li>
<% } else if (__isLast__) { %>
<li class="last"><%= article %></li>
<% } else if (!__isLast__ && !__isFirst__) { %>
<li class="<%= __index__ %>"><%= article %></li>
<% } %>
</ul>
1 change: 1 addition & 0 deletions spec/fixtures/partials/item.html.ejs
@@ -0,0 +1 @@
<li><%= item %></li>
1 change: 1 addition & 0 deletions spec/fixtures/partials/video.html.ejs
@@ -0,0 +1 @@
<li><%= vid %></li>
114 changes: 79 additions & 35 deletions spec/spec.plugins.view.js
Expand Up @@ -42,45 +42,89 @@ describe 'Express'
end

describe 'given a valid view name'
it 'should render a partial'
get('/', function(){
this.render('list.html.haml', { locals: { items: ['foo', 'bar'] }})
})
get('/').body.should.include '<ul>'
get('/').body.should.include '<li>foo'
get('/').body.should.include '<li>bar'
end
it 'should render collections'
get('/', function(){
return this.partial('item.html.haml', {
collection: ['foo', 'bar']
describe 'with EJS'
it 'should render a partial'
get('/', function(){
this.render('list.html.ejs', { locals: { items: ['foo', 'bar'] }})
})
})
get('/').body.should.include '<li>foo'
get('/').body.should.include '<li>bar'
end

it 'should render collections with a given object name'
get('/', function(){
return this.partial('video.html.haml', {
collection: ['im a movie', 'im another movie'],
as: 'vid'
get('/').body.should.include '<ul>'
get('/').body.should.include '<li>foo'
get('/').body.should.include '<li>bar'
end
it 'should render collections'
get('/', function(){
return this.partial('item.html.ejs', {
collection: ['foo', 'bar']
})
})
})
get('/').body.should.include '<li>im a movie'
get('/').body.should.include '<li>im another movie'
get('/').body.should.include '<li>foo'
get('/').body.should.include '<li>bar'
end

it 'should render collections with a given object name'
get('/', function(){
return this.partial('video.html.ejs', {
collection: ['im a movie', 'im another movie'],
as: 'vid'
})
})
get('/').body.should.include '<li>im a movie'
get('/').body.should.include '<li>im another movie'
end

it 'should pass __isFirst__, __isLast__, and __index__ to partials as locals'
get('/', function(){
return this.partial('article.html.ejs', {
collection: ['a', 'b', 'c']
})
})
get('/').body.should.include '<li class="first">a'
get('/').body.should.include '<li class="1">b'
get('/').body.should.include '<li class="last">c'
end
end

it 'should pass __isFirst__, __isLast__, and __index__ to partials as locals'
get('/', function(){
return this.partial('article.html.haml', {
collection: ['a', 'b', 'c']
describe 'with Haml'
it 'should render a partial'
get('/', function(){
this.render('list.html.haml', { locals: { items: ['foo', 'bar'] }})
})
})
get('/').body.should.include '<li class="first">a'
get('/').body.should.include '<li class="1">b'
get('/').body.should.include '<li class="last">c'
get('/').body.should.include '<ul>'
get('/').body.should.include '<li>foo'
get('/').body.should.include '<li>bar'
end
it 'should render collections'
get('/', function(){
return this.partial('item.html.haml', {
collection: ['foo', 'bar']
})
})
get('/').body.should.include '<li>foo'
get('/').body.should.include '<li>bar'
end

it 'should render collections with a given object name'
get('/', function(){
return this.partial('video.html.haml', {
collection: ['im a movie', 'im another movie'],
as: 'vid'
})
})
get('/').body.should.include '<li>im a movie'
get('/').body.should.include '<li>im another movie'
end

it 'should pass __isFirst__, __isLast__, and __index__ to partials as locals'
get('/', function(){
return this.partial('article.html.haml', {
collection: ['a', 'b', 'c']
})
})
get('/').body.should.include '<li class="first">a'
get('/').body.should.include '<li class="1">b'
get('/').body.should.include '<li class="last">c'
end
end
end
end
Expand Down

0 comments on commit cb8e704

Please sign in to comment.