Created
November 30, 2010 04:48
-
-
Save aconbere/721169 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // Which files to traverse while finding id? Returns generator function. | |
| function traverser (id, dirs) { | |
| var head = [], | |
| inDir = [], | |
| dirs = dirs.slice(), // a copy of the original array | |
| exts = Object.keys(extensions); | |
| return function next () { | |
| var result = head.shift(); | |
| if (result) { return result; } | |
| var gen = inDir.shift(); | |
| if (gen) { head = gen(); return next(); } | |
| var dir = dirs.shift(); | |
| if (dir !== undefined) { | |
| function direct (ext) { return path.join(dir, id + ext); } | |
| function index (ext) { return path.join(dir, id, 'index' + ext); } | |
| inDir = [ | |
| function () { return exts.map(direct); }, | |
| function () { return exts.map(index); } | |
| ]; | |
| head = [path.join(dir, id)]; | |
| return next(); | |
| } | |
| }; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment