diff --git a/flour.coffee b/flour.coffee index 389591f..a5175d9 100644 --- a/flour.coffee +++ b/flour.coffee @@ -96,13 +96,13 @@ flour = # Get file(s)' contents get: (filepath, cb) -> - if isWild filepath + if isWild(filepath) or Array.isArray(filepath) return flour.getFiles filepath, (files) -> results = [] count = files.length files.forEach (f, i) -> new File(f).read (output) -> - results[i] = output + results[i] = results[f] = output if --count is 0 then cb results, files new File(filepath).read cb diff --git a/test/flour.spec.coffee b/test/flour.spec.coffee index 0ae5abf..2910e0a 100644 --- a/test/flour.spec.coffee +++ b/test/flour.spec.coffee @@ -3,6 +3,7 @@ fs = require 'fs' path = require 'path' flour = require '../flour' +File = require '../lib/file' readFile = (file) -> fs.readFileSync(file).toString() copyFile = (file, out) -> fs.writeFileSync out, readFile file @@ -241,6 +242,48 @@ describe 'Bundle', -> contents.should.include 'bundle2=function(' done() +describe 'flour.get', (contents) -> + + s1 = "#{dir.sources}/compile.coffee" + s2 = "#{dir.sources}/compile.styl" + + lintall = "#{dir.sources}/lint/*" + lint1 = "#{dir.sources}/lint/lint-1.js" + lint2 = "#{dir.sources}/lint/lint-1.js" + + it 'should return an instance of File', (done) -> + flour.get s1, (f) -> + this.should.be.an.instanceof File + done() + + it 'should return a single file\'s contents', (done) -> + flour.get s1, (contents) -> + contents.should.equal readFile(s1) + done() + + it 'should return multiple file\'s contents', (done) -> + flour.get [s1, s2], (res) -> + # contents should be available at both index and filename keys + should.exist res[0] + should.exist res[1] + res[0].should.equal readFile(s1) + res[1].should.equal readFile(s2) + + should.exist res[s1] + should.exist res[s2] + res[s1].should.equal readFile(s1) + res[s2].should.equal readFile(s2) + + done() + + it 'should accept complex paths/patterns', (done) -> + flour.get lintall, (res) -> + should.exist res[lint1] + should.exist res[lint2] + res[lint1].should.equal readFile(lint1) + res[lint2].should.equal readFile(lint2) + done() + describe 'File path handling', -> m1 = "#{dir.temp}/multi1.js"