mirror of
https://github.com/vale981/metalsmith-layouts
synced 2025-03-04 17:21:37 -05:00
added patternExtension property to provide method for limiting which files are considered patterns
This commit is contained in:
parent
ed5ec42ed1
commit
abff1127a9
11 changed files with 42 additions and 5 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1 +1,2 @@
|
||||||
node_modules
|
node_modules
|
||||||
|
debug.log
|
|
@ -18,7 +18,7 @@ module.exports = readPartials;
|
||||||
* @param {Object} metalsmith
|
* @param {Object} metalsmith
|
||||||
* @return {Object}
|
* @return {Object}
|
||||||
*/
|
*/
|
||||||
function readPartials(partialsPath, layoutsPath, metalsmith) {
|
function readPartials(partialsPath, partialExtension, layoutsPath, metalsmith) {
|
||||||
var partialsAbs = path.isAbsolute(partialsPath) ? partialsPath : path.join(metalsmith.path(), partialsPath);
|
var partialsAbs = path.isAbsolute(partialsPath) ? partialsPath : path.join(metalsmith.path(), partialsPath);
|
||||||
var layoutsAbs = path.isAbsolute(layoutsPath) ? layoutsPath : path.join(metalsmith.path(), layoutsPath);
|
var layoutsAbs = path.isAbsolute(layoutsPath) ? layoutsPath : path.join(metalsmith.path(), layoutsPath);
|
||||||
var files = read(partialsAbs);
|
var files = read(partialsAbs);
|
||||||
|
@ -35,8 +35,9 @@ function readPartials(partialsPath, layoutsPath, metalsmith) {
|
||||||
var name = path.join(fileInfo.dir, fileInfo.name);
|
var name = path.join(fileInfo.dir, fileInfo.name);
|
||||||
var partialAbs = path.join(partialsAbs, name);
|
var partialAbs = path.join(partialsAbs, name);
|
||||||
var partialPath = path.relative(layoutsAbs, partialAbs);
|
var partialPath = path.relative(layoutsAbs, partialAbs);
|
||||||
|
if (!partialExtension || fileInfo.ext == partialExtension) {
|
||||||
partials[name.replace(/\\/g, '/')] = partialPath;
|
partials[name.replace(/\\/g, '/')] = partialPath;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return partials;
|
return partials;
|
||||||
|
|
|
@ -29,6 +29,7 @@ var settings = [
|
||||||
'directory',
|
'directory',
|
||||||
'engine',
|
'engine',
|
||||||
'partials',
|
'partials',
|
||||||
|
'partialExtension',
|
||||||
'pattern',
|
'pattern',
|
||||||
'rename',
|
'rename',
|
||||||
'exposeConsolidate'
|
'exposeConsolidate'
|
||||||
|
@ -42,6 +43,7 @@ var settings = [
|
||||||
* @property {String} directory (optional)
|
* @property {String} directory (optional)
|
||||||
* @property {String} engine
|
* @property {String} engine
|
||||||
* @property {String} partials (optional)
|
* @property {String} partials (optional)
|
||||||
|
* @property {String} partialExtension (optional)
|
||||||
* @property {String} pattern (optional)
|
* @property {String} pattern (optional)
|
||||||
* @property {Boolean} rename (optional)
|
* @property {Boolean} rename (optional)
|
||||||
* @return {Function}
|
* @return {Function}
|
||||||
|
@ -75,6 +77,7 @@ function plugin(opts){
|
||||||
var def = opts.default;
|
var def = opts.default;
|
||||||
var dir = opts.directory || 'layouts';
|
var dir = opts.directory || 'layouts';
|
||||||
var engine = opts.engine;
|
var engine = opts.engine;
|
||||||
|
var partialExtension = opts.partialExtension;
|
||||||
var partials = opts.partials;
|
var partials = opts.partials;
|
||||||
var pattern = opts.pattern;
|
var pattern = opts.pattern;
|
||||||
var rename = opts.rename;
|
var rename = opts.rename;
|
||||||
|
@ -94,7 +97,7 @@ function plugin(opts){
|
||||||
*/
|
*/
|
||||||
if (partials) {
|
if (partials) {
|
||||||
if (typeof partials === 'string') {
|
if (typeof partials === 'string') {
|
||||||
params.partials = readPartials(partials, dir, metalsmith);
|
params.partials = readPartials(partials, partialExtension, dir, metalsmith);
|
||||||
} else {
|
} else {
|
||||||
params.partials = partials;
|
params.partials = partials;
|
||||||
}
|
}
|
||||||
|
|
3
test/fixtures/partials-partialExtension/build/index.html
vendored
Normal file
3
test/fixtures/partials-partialExtension/build/index.html
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
<p>Nav</p>
|
||||||
|
<p>Content</p>
|
||||||
|
|
3
test/fixtures/partials-partialExtension/expected/index.html
vendored
Normal file
3
test/fixtures/partials-partialExtension/expected/index.html
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
<p>Nav</p>
|
||||||
|
<p>Content</p>
|
||||||
|
|
2
test/fixtures/partials-partialExtension/layouts/layout.html
vendored
Normal file
2
test/fixtures/partials-partialExtension/layouts/layout.html
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
{{>nested/nav}}
|
||||||
|
{{{contents}}}
|
1
test/fixtures/partials-partialExtension/layouts/partials/nested/nav.config.yaml
vendored
Normal file
1
test/fixtures/partials-partialExtension/layouts/partials/nested/nav.config.yaml
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
foo: bar
|
1
test/fixtures/partials-partialExtension/layouts/partials/nested/nav.html
vendored
Normal file
1
test/fixtures/partials-partialExtension/layouts/partials/nested/nav.html
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
<p>Nav</p>
|
4
test/fixtures/partials-partialExtension/src/index.html
vendored
Normal file
4
test/fixtures/partials-partialExtension/src/index.html
vendored
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
---
|
||||||
|
layout: layout.html
|
||||||
|
---
|
||||||
|
<p>Content</p>
|
|
@ -135,6 +135,24 @@ describe('metalsmith-layouts', function(){
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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){
|
it('should find partials in subdirectories correctly', function(done){
|
||||||
// This test would only fail on Windows if readPartials did not
|
// This test would only fail on Windows if readPartials did not
|
||||||
// replace backslashes in partial names
|
// replace backslashes in partial names
|
||||||
|
|
Loading…
Add table
Reference in a new issue