diff --git a/spec/atom/project-spec.coffee b/spec/atom/project-spec.coffee index 39f6517a6..72032caa0 100644 --- a/spec/atom/project-spec.coffee +++ b/spec/atom/project-spec.coffee @@ -14,3 +14,16 @@ describe "Project", -> project.getFilePaths().done (result) -> expect(result).toEqual(expectedPaths) + describe ".open(path)", -> + absolutePath = null + beforeEach -> + absolutePath = require.resolve('fixtures/dir/a') + + describe "when given an absolute path", -> + it "returns a buffer for the given path", -> + expect(project.open(absolutePath).url).toBe absolutePath + + describe "when given a relative path", -> + it "returns a buffer for the given path (relative to the project root)", -> + expect(project.open('a').url).toBe absolutePath + diff --git a/src/atom/project.coffee b/src/atom/project.coffee index b6a91a791..ca0369f3d 100644 --- a/src/atom/project.coffee +++ b/src/atom/project.coffee @@ -1,4 +1,5 @@ fs = require 'fs' +Buffer = require 'buffer' module.exports = @@ -8,3 +9,12 @@ class Project getFilePaths: -> fs.async.listFiles(@url, true) + open: (filePath) -> + new Buffer(@resolve(filePath)) + + resolve: (filePath) -> + if filePath[0] == '/' + filePath + else + fs.join(@url, filePath) +