Adds check if paths are already absolute before joining the metalsmith path

This commit is contained in:
Zak Henry 2016-05-31 13:07:13 +01:00
parent 63260bafda
commit 78f2a70605
2 changed files with 23 additions and 5 deletions

View file

@ -13,14 +13,14 @@ module.exports = readPartials;
* Helper for reading a folder with partials, returns a `partials` object that
* can be consumed by consolidate.
*
* @param {String} partialsRel
* @param {String} layoutsRel
* @param {String} partialsPath
* @param {String} layoutsPath
* @param {Object} metalsmith
* @return {Object}
*/
function readPartials(partialsRel, layoutsRel, metalsmith) {
var partialsAbs = path.join(metalsmith.path(), partialsRel);
var layoutsAbs = path.join(metalsmith.path(), layoutsRel);
function readPartials(partialsPath, layoutsPath, metalsmith) {
var partialsAbs = path.isAbsolute(partialsPath) ? partialsPath : path.join(metalsmith.path(), partialsPath);
var layoutsAbs = path.isAbsolute(layoutsPath) ? layoutsPath : path.join(metalsmith.path(), layoutsPath);
var files = read(partialsAbs);
var partials = {};

View file

@ -153,6 +153,24 @@ describe('metalsmith-layouts', function(){
});
});
it('should find partials in subdirectories with absolute directory path', function(done){
var instance = Metalsmith('test/fixtures/partials-subdirectories')
.use(layouts({
engine: 'handlebars',
templates: __dirname + '/fixtures/partials-subdirectories/layouts',
partials: __dirname + '/fixtures/partials-subdirectories/layouts/partials'
}));
instance.build(function(err){
if (err) {
return done(err);
}
equal('test/fixtures/partials-subdirectories/expected', 'test/fixtures/partials-subdirectories/build');
done();
});
});
it('should accept a partials option', function(done){
Metalsmith('test/fixtures/partials-option')
.use(layouts({