Browse files

fix partial.bind for relative partials

  • Loading branch information...
1 parent bbff6da commit 40a7ef274acf95fd8d420cd739dae58356ed3dfa @RandomEtc committed Nov 12, 2012
View
3 index.js
@@ -317,6 +317,9 @@ function partial(view, options){
options.filename = file;
+ // re-bind partial for relative partial paths
+ options.partial = partial.bind(options);
+
// render partial
function render(){
if (object) {
View
1 test/fixtures/blog/home.ejs
@@ -0,0 +1 @@
+<h1><%-partial('user',user)%></h1><ul><%-partial('post',posts)%></ul>
View
1 test/fixtures/blog/post/comment.ejs
@@ -0,0 +1 @@
+<li><%=comment.text%></li>
View
1 test/fixtures/blog/post/index.ejs
@@ -0,0 +1 @@
+<li><%=post.text%><ul><%-partial('comment',post.comments)%></ul></li>
View
1 test/fixtures/blog/user.ejs
@@ -0,0 +1 @@
+<%=user.name%>
View
32 test/test.partials.js
@@ -21,6 +21,23 @@ app.get('/',function(req,res,next){
res.render('index.ejs')
})
+app.get('/blog',function(req,res,next){
+ res.render('blog/home.ejs', {
+ _layoutFile:false,
+ user: { name: 'Tom' },
+ posts: [
+ {
+ text: '1',
+ comments: [ { text: '1.1' }, { text: '1.2' } ]
+ },
+ {
+ text: '2',
+ comments: [ { text: '2.1' }, { text: '2.2' }, { text: '2.3' } ]
+ }
+ ]
+ })
+})
+
app.get('/no-layout',function(req,res,next){
res.render('index.ejs',{_layoutFile:false})
})
@@ -127,9 +144,8 @@ app.get('/filters-custom',function(req,res,next){
// override the default error handler so it doesn't log to console:
app.use(function(err,req,res,next) {
- res.send(500, err.stack);
// console.log(err.stack);
- // next();
+ res.send(500, err.stack);
})
describe('app',function(){
@@ -146,6 +162,18 @@ describe('app',function(){
})
})
+ describe('GET /blog',function(){
+ it('should render all the fiddly partials',function(done){
+ request(app)
+ .get('/blog')
+ .end(function(res){
+ res.should.have.status(200);
+ res.body.should.equal('<h1>Tom</h1><ul><li>1<ul><li>1.1</li><li>1.2</li></ul></li><li>2<ul><li>2.1</li><li>2.2</li><li>2.3</li></ul></li></ul>');
+ done();
+ })
+ })
+ })
+
describe('GET /no-layout',function(){
it('should render without layout',function(done){
request(app)

0 comments on commit 40a7ef2

Please sign in to comment.