metalsmith-layouts
Advanced tools
Comparing version 1.7.0 to 1.8.0
@@ -0,1 +1,5 @@ | ||
1.8.0 - February 3, 2017 | ||
------------------------ | ||
* add partialExtension option, to fix partials matching on the wrong extension | ||
1.7.0 - November 6, 2016 | ||
@@ -2,0 +6,0 @@ ------------------- |
@@ -21,3 +21,3 @@ /** | ||
*/ | ||
function readPartials(partialsPath, layoutsPath, metalsmith) { | ||
function readPartials(partialsPath, partialExtension, layoutsPath, metalsmith) { | ||
var partialsAbs = path.isAbsolute(partialsPath) ? partialsPath : path.join(metalsmith.path(), partialsPath); | ||
@@ -39,4 +39,5 @@ var layoutsAbs = path.isAbsolute(layoutsPath) ? layoutsPath : path.join(metalsmith.path(), layoutsPath); | ||
var partialPath = path.relative(layoutsAbs, partialAbs); | ||
partials[name.replace(/\\/g, '/')] = partialPath; | ||
if (!partialExtension || fileInfo.ext == partialExtension) { | ||
partials[name.replace(/\\/g, '/')] = partialPath; | ||
} | ||
} | ||
@@ -43,0 +44,0 @@ |
@@ -32,2 +32,3 @@ /** | ||
'partials', | ||
'partialExtension', | ||
'pattern', | ||
@@ -46,2 +47,3 @@ 'rename', | ||
* @property {String} partials (optional) | ||
* @property {String} partialExtension (optional) | ||
* @property {String} pattern (optional) | ||
@@ -80,2 +82,3 @@ * @property {Boolean} rename (optional) | ||
var engine = opts.engine; | ||
var partialExtension = opts.partialExtension; | ||
var partials = opts.partials; | ||
@@ -100,3 +103,3 @@ var pattern = opts.pattern; | ||
if (typeof partials === 'string') { | ||
params.partials = readPartials(partials, dir, metalsmith); | ||
params.partials = readPartials(partials, partialExtension, dir, metalsmith); | ||
} else { | ||
@@ -103,0 +106,0 @@ params.partials = partials; |
@@ -6,3 +6,3 @@ { | ||
"repository": "git://github.com/superwolff/metalsmith-layouts.git", | ||
"version": "1.7.0", | ||
"version": "1.8.0", | ||
"license": "MIT", | ||
@@ -9,0 +9,0 @@ "main": "lib/index.js", |
@@ -86,2 +86,3 @@ # metalsmith-layouts | ||
* [partials](#partials): directory for the partials (optional) | ||
* [partialExtension](#partialextension): extension for the partial files (optional) | ||
* [pattern](#pattern): only files that match this pattern will be processed (optional) | ||
@@ -161,2 +162,20 @@ * [rename](#rename): change the file extension of processed files to `.html` (optional) | ||
### partialExtension | ||
The file extension used on partial files. Only the first file matching this file extension will be passed into templating engine. | ||
```json | ||
{ | ||
"plugins": { | ||
"metalsmith-layouts": { | ||
"engine": "handlebars", | ||
"partials": "partials", | ||
"partialExtension": ".html" | ||
} | ||
} | ||
} | ||
``` | ||
Would mean that even if your partials folder contained `footer.html`, `footer.config.yaml` and `footer.md` (say for documentation or pattern library), only the `footer.html` would be passed to the templating engine. | ||
### pattern | ||
@@ -163,0 +182,0 @@ |
@@ -138,2 +138,20 @@ var assert = require('assert'); | ||
it('should use partialExtension to limit the matching partial files', function(done){ | ||
// Without partialExtension the nav.config.yaml would cause an error | ||
var instance = Metalsmith('test/fixtures/partials-partialExtension') | ||
.use(layouts({ | ||
engine: 'handlebars', | ||
partials: 'layouts/partials', | ||
partialExtension: '.html' | ||
})); | ||
instance.build(function(err){ | ||
if (err) { | ||
return done(err); | ||
} | ||
equal('test/fixtures/partials-partialExtension/expected', 'test/fixtures/partials-partialExtension/build'); | ||
done(); | ||
}); | ||
}); | ||
it('should find partials in subdirectories correctly', function(done){ | ||
@@ -140,0 +158,0 @@ // This test would only fail on Windows if readPartials did not |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
260680
97
453
259