mirror of
https://github.com/atom/atom.git
synced 2026-01-23 22:08:08 -05:00
Add Project.open, which returns a buffer for an absolute/relative path.
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user