diff --git a/lib/consolidate.js b/lib/consolidate.js index 8a06431..cbe80ff 100644 --- a/lib/consolidate.js +++ b/lib/consolidate.js @@ -22,6 +22,7 @@ var join = path.join; var resolve = path.resolve; var extname = path.extname; var dirname = path.dirname; +var isAbsolute = path.isAbsolute; var readCache = {}; @@ -118,7 +119,19 @@ function readPartials(path, options, fn) { function next(index) { if (index === keys.length) return fn(null); var key = keys[index]; - var file = join(dirname(path), partials[key] + extname(path)); + var partialPath = partials[key]; + + var file; + if (isAbsolute(partialPath)) { + if (extname(partialPath) !== '') { + file = partialPath; + } else { + file = join(partialPath + extname(path)); + } + } else { + file = join(dirname(path), partialPath + extname(path)); + } + read(file, options, function(err, str){ if (err) return fn(err); options.partials[key] = str; diff --git a/test/shared/partials.js b/test/shared/partials.js index febd9aa..5982b6c 100644 --- a/test/shared/partials.js +++ b/test/shared/partials.js @@ -23,6 +23,24 @@ exports.test = function(name) { done(); }); }); + it('should support absolute path partial', function(done){ + var path = 'test/fixtures/' + name + '/partials.' + name; + var locals = {user: user, partials: {partial: __dirname + '/../../test/fixtures/' + name + '/user' }}; + cons[name](path, locals, function(err, html){ + if (err) return done(err); + html.should.equal('

Tobi

'); + done(); + }); + }); + it('should support relative path partial', function(done){ + var path = 'test/fixtures/' + name + '/partials.' + name; + var locals = {user: user, partials: {partial: '../' + name + '/user' }}; + cons[name](path, locals, function(err, html){ + if (err) return done(err); + html.should.equal('

Tobi

'); + done(); + }); + }); } else { it('should support rendering a partial', function(done){