Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 4685621
Showing
35 changed files
with
159 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
0.0.1 - March 6, 2013 | ||
------------------------ | ||
:sparkles: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
node_modules: package.json | ||
@npm install | ||
|
||
test: node_modules | ||
@./node_modules/.bin/mocha --reporter spec | ||
|
||
.PHONY: test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
|
||
# metalsmith-ignore | ||
|
||
A Metalsmith plugin to ignore files that match a pattern. | ||
|
||
## Installation | ||
|
||
$ npm install metalsmith-ignore | ||
|
||
## CLI Usage | ||
|
||
Install via npm and then add the `metalsmith-ignore` key to your `metalsmith.json` plugins. The simplest case just ignores a single pattern: | ||
|
||
```json | ||
{ | ||
"plugins": { | ||
"metalsmith-ignore": "drafts/*" | ||
} | ||
} | ||
``` | ||
|
||
But you can also pass an array of patterns to ignore: | ||
|
||
```json | ||
{ | ||
"plugins": { | ||
"metalsmith-ignore": [ | ||
"drafts/*", | ||
"unfinished/*" | ||
] | ||
} | ||
} | ||
``` | ||
|
||
## Javascript Usage | ||
|
||
Pass the options to `Metalsmith#use`: | ||
|
||
```js | ||
var ignore = require('metalsmith-ignore'); | ||
|
||
metalsmith.use(ignore('drafts/*')); | ||
``` | ||
|
||
You can also pass an array of patterns to ignore: | ||
|
||
```js | ||
var ignore = require('metalsmith-ignore'); | ||
|
||
metalsmith.use(ignore([ | ||
'drafts/*', | ||
'unfinished/*' | ||
])); | ||
``` | ||
|
||
## License | ||
|
||
MIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
|
||
var Match = require('minimatch').Minimatch; | ||
|
||
/** | ||
* Expose `plugin`. | ||
*/ | ||
|
||
module.exports = plugin; | ||
|
||
/** | ||
* Metalsmith plugin to ignore files that match a pattern. | ||
* | ||
* @param {String or Array or Object} opts | ||
* @return {Function} | ||
*/ | ||
|
||
function plugin(opts){ | ||
debugger; | ||
if ('string' == typeof opts) opts = [opts]; | ||
if (opts instanceof Array) opts = { patterns: opts }; | ||
opts = opts || {}; | ||
|
||
var patterns = opts.patterns || []; | ||
var matchers = patterns.map(function(str){ | ||
return new Match(str); | ||
}); | ||
|
||
return function(files, metalsmith, done){ | ||
setImmediate(done); | ||
for (var file in files) { | ||
for (var i = 0, matcher; matcher = matchers[i]; i++) { | ||
if (matcher.match(file)) delete files[file]; | ||
} | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "metalsmith-ignore", | ||
"description": "A Metalsmith plugin to ignore files that match a pattern.", | ||
"repository": "git://github.com/segmentio/metalsmith-ignore.git", | ||
"version": "0.0.1", | ||
"license": "MIT", | ||
"main": "lib/index.js", | ||
"dependencies": { | ||
"minimatch": "^0.2.14" | ||
}, | ||
"devDependencies": { | ||
"mocha": "1.x", | ||
"metalsmith": "^0.2.0", | ||
"assert-dir-equal": "^0.1.0" | ||
} | ||
} |
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
|
||
var equal = require('assert-dir-equal'); | ||
var Metalsmith = require('metalsmith'); | ||
var ignore = require('..'); | ||
|
||
describe('metalsmith-ignore', function(){ | ||
it('should ignore a patterns', function(done){ | ||
var m = Metalsmith('test/fixtures/object').use(ignore({ | ||
patterns: ['ignored.*', 'removed.*'] | ||
})); | ||
|
||
m.build(function(err){ | ||
if (err) return done(err); | ||
equal('test/fixtures/object/build', 'test/fixtures/object/expected'); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should take an array shorthand', function(done){ | ||
var m = Metalsmith('test/fixtures/array').use(ignore(['ignored.*', 'removed.*'])); | ||
m.build(function(err){ | ||
if (err) return done(err); | ||
equal('test/fixtures/array/build', 'test/fixtures/array/expected'); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should take a string shorthand', function(done){ | ||
var m = Metalsmith('test/fixtures/string').use(ignore('ignored.*')); | ||
m.build(function(err){ | ||
if (err) return done(err); | ||
equal('test/fixtures/string/build', 'test/fixtures/string/expected'); | ||
done(); | ||
}); | ||
}); | ||
}); |
multimatch might be useful here.