Skip to content

Commit

Permalink
Merge pull request #99 from zakhenry/fix/allow-absolute-paths
Browse files Browse the repository at this point in the history
Adds check if paths are already absolute before joining the metalsmith path
  • Loading branch information
doodzik committed Jun 2, 2016
2 parents 63260ba + 78f2a70 commit 4002b65
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/helpers/read-partials.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};

Expand Down
18 changes: 18 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit 4002b65

Please sign in to comment.