diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1f63d68 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.DS_Store +node_modules/ +*~ diff --git a/index.js b/index.js index 27177a3..1033925 100644 --- a/index.js +++ b/index.js @@ -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/_.jade // taking precedence over the direct path view = resolve(root,'_'+name+ext) diff --git a/test/fixtures/partial-from-fn.ejs b/test/fixtures/partial-from-fn.ejs new file mode 100644 index 0000000..9daf6b0 --- /dev/null +++ b/test/fixtures/partial-from-fn.ejs @@ -0,0 +1 @@ +

partial-from-absolute-path:<%- partial(get_template_path()) %>

\ No newline at end of file diff --git a/test/test.partials.js b/test/test.partials.js index b15f589..c936a59 100644 --- a/test/test.partials.js +++ b/test/test.partials.js @@ -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){ @@ -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); @@ -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('express-partials

partial-from-absolute-path:

Hello World

'); + done(); + }) + }) + }) + })