Ignore files without a layout

This commit is contained in:
ismay 2015-08-14 14:16:18 +02:00
parent 46d20c13f7
commit 5712464e93
9 changed files with 38 additions and 2 deletions

View file

@ -107,9 +107,9 @@ function plugin(opts){
debug('converting file: %s', file);
var data = files[file];
// Require a default or a layout to be specified for each file
// Ignore files without a specified layout
if(!data.layout && !def) {
throw new Error('No layout specified for ' + file);
return done();
}
// Deep clone params (by passing 'true')

View file

@ -0,0 +1,6 @@
<html>
<body>
has a layout
</body>
</html>

View file

@ -0,0 +1 @@
has no layout

View file

@ -0,0 +1,6 @@
<html>
<body>
has a layout
</body>
</html>

View file

@ -0,0 +1 @@
has no layout

View file

@ -0,0 +1,5 @@
<html>
<body>
{{contents}}
</body>
</html>

4
test/fixtures/ignore/src/layout.html vendored Normal file
View file

@ -0,0 +1,4 @@
---
layout: layout.html
---
has a layout

View file

@ -0,0 +1 @@
has no layout

View file

@ -137,4 +137,16 @@ describe('metalsmith-layouts', function(){
});
});
it('should ignore files without a layout', function(done){
Metalsmith('test/fixtures/ignore')
.use(layouts('handlebars'))
.build(function(err){
if (err) {
return done(err);
}
equal('test/fixtures/ignore/expected', 'test/fixtures/ignore/build');
done();
});
});
});