add shorthand for pattern matching

This commit is contained in:
Ian Storm Taylor 2014-03-06 14:40:19 -08:00
parent 97d1d86bf5
commit f573929416
2 changed files with 31 additions and 1 deletions

View file

@ -19,7 +19,7 @@ module.exports = plugin;
*/ */
function plugin(opts){ function plugin(opts){
opts = opts || {}; opts = normalize(opts);
var keys = Object.keys(opts); var keys = Object.keys(opts);
var match = matcher(opts); var match = matcher(opts);
@ -79,6 +79,23 @@ function plugin(opts){
}; };
} }
/**
* Normalize an `options` dictionary.
*
* @param {Object} options
*/
function normalize(options){
options = options || {};
for (var key in options) {
var val = options[key];
if ('string' == typeof val) options[key] = { pattern: val };
}
return options;
}
/** /**
* Generate a matching function for a given set of `collections`. * Generate a matching function for a given set of `collections`.
* *

View file

@ -30,6 +30,19 @@ describe('metalsmith-collections', function(){
}); });
}); });
it('should take a pattern shorthand string', function(done){
var metalsmith = Metalsmith('test/fixtures/basic');
metalsmith
.use(collections({
articles: '*.md'
}))
.build(function(err){
if (err) return done(err);
assert.equal(3, metalsmith.metadata().articles.length);
done();
});
});
it('should accept a "sortBy" option', function(done){ it('should accept a "sortBy" option', function(done){
var metalsmith = Metalsmith('test/fixtures/sort'); var metalsmith = Metalsmith('test/fixtures/sort');
metalsmith metalsmith