From 07b40cdbeb245c88ebce632a7d32e67acd85e7a7 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 3 Jan 2012 16:01:37 -0700 Subject: [PATCH] RootView opens a project for the directory of the url passed to initialize. Rename fixtures/file-finder-dir to fixtures/dir, because it's not really file-finder specific. --- spec/atom/project-spec.coffee | 15 +++++++++++++++ spec/atom/root-view-spec.coffee | 18 ++++++++++++------ spec/fixtures/{file-finder-dir => dir}/a | 0 .../{file-finder-dir => dir}/a-dir/oh-git | 0 spec/fixtures/{file-finder-dir => dir}/b | 0 spec/stdlib/fs-spec.coffee | 2 +- src/atom/project.coffee | 10 ++++++++++ src/atom/root-view.coffee | 5 ++++- 8 files changed, 42 insertions(+), 8 deletions(-) create mode 100644 spec/atom/project-spec.coffee rename spec/fixtures/{file-finder-dir => dir}/a (100%) rename spec/fixtures/{file-finder-dir => dir}/a-dir/oh-git (100%) rename spec/fixtures/{file-finder-dir => dir}/b (100%) create mode 100644 src/atom/project.coffee diff --git a/spec/atom/project-spec.coffee b/spec/atom/project-spec.coffee new file mode 100644 index 000000000..459ca34b0 --- /dev/null +++ b/spec/atom/project-spec.coffee @@ -0,0 +1,15 @@ +Project = require 'project' +fs = require 'fs' + +describe "Project", -> + project = null + beforeEach -> + project = new Project(require.resolve('fixtures/dir')) + + describe ".list()", -> + it "returns a promise which resolves to a list of all file urls in the project, recursively", -> + waitsFor (complete) -> + project.list().done (result) -> + expect(result).toEqual(fs.list(project.url, true)) + complete() + diff --git a/spec/atom/root-view-spec.coffee b/spec/atom/root-view-spec.coffee index 1aae9bbb6..44d901d13 100644 --- a/spec/atom/root-view-spec.coffee +++ b/spec/atom/root-view-spec.coffee @@ -8,11 +8,17 @@ describe "RootView", -> describe "initialize", -> describe "when called with a url", -> - it "opens the given url in the editor", -> - url = require.resolve 'fixtures/sample.txt' - rootView = RootView.build {url} + describe "when the url references a file", -> + url = null + beforeEach -> + url = require.resolve 'fixtures/sample.txt' + rootView = RootView.build {url} - expect(rootView.editor.buffer.url).toBe url + it "creates a project for the file's parent directory", -> + expect(rootView.project.url).toBe fs.directory(url) + + it "opens the file in the editor", -> + expect(rootView.editor.buffer.url).toBe url describe "when not called with a url", -> it "opens an empty buffer", -> @@ -29,7 +35,7 @@ describe "RootView", -> describe "toggleFileFinder", -> describe "when the editor has a url", -> - baseUrl = require.resolve('fixtures/file-finder-dir/a') + baseUrl = require.resolve('fixtures/dir/a') beforeEach -> rootView.editor.open baseUrl @@ -41,7 +47,7 @@ describe "RootView", -> rootView.toggleFileFinder() expect(rootView.find('.file-finder')).not.toExist() - it "shows urls for all files (not directories) by recursivley searching directory of editor.url", -> + it "shows all urls for the current project", -> rootView.toggleFileFinder() expect(rootView.fileFinder.urlList.children('li').length).toBe 3 diff --git a/spec/fixtures/file-finder-dir/a b/spec/fixtures/dir/a similarity index 100% rename from spec/fixtures/file-finder-dir/a rename to spec/fixtures/dir/a diff --git a/spec/fixtures/file-finder-dir/a-dir/oh-git b/spec/fixtures/dir/a-dir/oh-git similarity index 100% rename from spec/fixtures/file-finder-dir/a-dir/oh-git rename to spec/fixtures/dir/a-dir/oh-git diff --git a/spec/fixtures/file-finder-dir/b b/spec/fixtures/dir/b similarity index 100% rename from spec/fixtures/file-finder-dir/b rename to spec/fixtures/dir/b diff --git a/spec/stdlib/fs-spec.coffee b/spec/stdlib/fs-spec.coffee index 007af1abc..f6459cc65 100644 --- a/spec/stdlib/fs-spec.coffee +++ b/spec/stdlib/fs-spec.coffee @@ -4,7 +4,7 @@ describe "fs", -> describe ".async", -> describe ".list(directoryPath, recursive)", -> directoryPath = null - beforeEach -> directoryPath = require.resolve 'fixtures/file-finder-dir' + beforeEach -> directoryPath = require.resolve 'fixtures/dir' describe "when recursive is true", -> it "returns a promise that resolves to the recursive contents of that directory", -> diff --git a/src/atom/project.coffee b/src/atom/project.coffee new file mode 100644 index 000000000..0e266f28b --- /dev/null +++ b/src/atom/project.coffee @@ -0,0 +1,10 @@ +fs = require 'fs' + +module.exports = + +class Project + constructor: (@url) -> + + list: -> + fs.async.list(@url, true) + diff --git a/src/atom/root-view.coffee b/src/atom/root-view.coffee index c03d44314..4ff40f9cf 100644 --- a/src/atom/root-view.coffee +++ b/src/atom/root-view.coffee @@ -1,9 +1,10 @@ $ = require 'jquery' fs = require 'fs' +Template = require 'template' Editor = require 'editor' FileFinder = require 'file-finder' -Template = require 'template' +Project = require 'project' module.exports = class RootView extends Template @@ -20,6 +21,7 @@ class RootView extends Template @bindKey 'meta+w', => window.close() @bindKey 'meta+t', => @toggleFileFinder() + @project = new Project(fs.directory(url)) if url @editor.open url addPane: (view) -> @@ -40,3 +42,4 @@ class RootView extends Template @fileFinder = FileFinder.build({urls}) @addPane(@fileFinder) @fileFinder.input.focus() +