Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.DS_Store
node_modules/
*~
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ function resolveObjectName(view){
function lookup(root, view, ext){
var name = resolveObjectName(view);

if(exists(view)) return view;

// Try _ prefix ex: ./views/_<name>.jade
// taking precedence over the direct path
view = resolve(root,'_'+name+ext)
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/partial-from-fn.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>partial-from-absolute-path:<%- partial(get_template_path()) %></h1>
22 changes: 20 additions & 2 deletions test/test.partials.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ var app = express();
app.use(partials());
app.set('views',__dirname + '/fixtures')

app.locals.use(function(req,res){
app.locals.hello = 'there';
app.use(function(req,res,next){
res.locals.hello = 'there';
res.locals.get_template_path = function() { return __dirname + '/fixtures/subdir/index.ejs'; };
next();
})

app.get('/',function(req,res,next){
Expand Down Expand Up @@ -50,6 +52,10 @@ app.get('/subdir-explicit',function(req,res,next){
res.render('subdir/index.ejs', {layout: 'subdir/layout.ejs', list:[{name:'one'},{name:'two'}]})
})

app.get('/absolute-path',function(req,res,next){
res.render('partial-from-fn.ejs', {})
})


/* Use `register` to substitute the file extension. */
app.engine('.j',require('jade').__express);
Expand Down Expand Up @@ -279,4 +285,16 @@ describe('app',function(){
})
})

describe('GET /absolute-path',function() {
it('should render index.ejs with layout.ejs layout and a partial specified by an absolute path returned by a function', function(done) {
request(app)
.get('/absolute-path')
.end(function(res) {
res.should.have.status(200);
res.body.should.equal('<html><head><title>express-partials</title></head><body><h1>partial-from-absolute-path:<h2>Hello World</h2></h1></body></html>');
done();
})
})
})

})