From 8c1f5658be6005bc1d3d75d512ceb36b925ab88a Mon Sep 17 00:00:00 2001 From: Corey Johnson & Nathan Sobo Date: Tue, 26 Mar 2013 10:50:40 -0600 Subject: [PATCH] Allow packages to have stylesheet manifests --- spec/app/atom-spec.coffee | 19 ++++++++++++++++--- .../package.cson | 1 + .../stylesheets/1.css | 3 +++ .../stylesheets/2.less | 5 +++++ .../stylesheets/3.css | 3 +++ src/app/atom-package.coffee | 9 +++++++-- 6 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 spec/fixtures/packages/package-with-stylesheets-manifest/package.cson create mode 100644 spec/fixtures/packages/package-with-stylesheets-manifest/stylesheets/1.css create mode 100644 spec/fixtures/packages/package-with-stylesheets-manifest/stylesheets/2.less create mode 100644 spec/fixtures/packages/package-with-stylesheets-manifest/stylesheets/3.css diff --git a/spec/app/atom-spec.coffee b/spec/app/atom-spec.coffee index 71287630d..1be3f87b1 100644 --- a/spec/app/atom-spec.coffee +++ b/spec/app/atom-spec.coffee @@ -35,7 +35,7 @@ describe "the `atom` global", -> expect(console.error).not.toHaveBeenCalled() expect(console.warn).not.toHaveBeenCalled() - it "passes the package its previously serialized state if it exists", -> + it "passes the activate method the package's previously serialized state if it exists", -> pack = atom.activatePackage("package-with-serialization") expect(pack.mainModule.someNumber).not.toBe 77 pack.mainModule.someNumber = 77 @@ -44,7 +44,7 @@ describe "the `atom` global", -> atom.activatePackage("package-with-serialization") expect(pack.mainModule.activate).toHaveBeenCalledWith({someNumber: 77}) - it "logs warning instead of throwing an exception if a package fails to load", -> + it "logs warning instead of throwing an exception if the package fails to load", -> config.set("core.disabledPackages", []) spyOn(console, "warn") expect(-> atom.activatePackage("package-that-throws-an-exception")).not.toThrow() @@ -82,7 +82,20 @@ describe "the `atom` global", -> describe "stylesheet loading", -> describe "when the metadata contains a 'stylesheets' manifest", -> - # WIP + it "loads stylesheets from the stylesheets directory as specified by the manifest", -> + one = fs.resolveOnLoadPath("package-with-stylesheets-manifest/stylesheets/1.css") + two = fs.resolveOnLoadPath("package-with-stylesheets-manifest/stylesheets/2.less") + three = fs.resolveOnLoadPath("package-with-stylesheets-manifest/stylesheets/3.css") + expect(stylesheetElementForId(one)).not.toExist() + expect(stylesheetElementForId(two)).not.toExist() + expect(stylesheetElementForId(three)).not.toExist() + + atom.activatePackage("package-with-stylesheets-manifest") + + expect(stylesheetElementForId(one)).toExist() + expect(stylesheetElementForId(two)).toExist() + expect(stylesheetElementForId(three)).not.toExist() + expect($('#jasmine-content').css('font-size')).toBe '1px' describe "when the metadata does not contains a 'stylesheets' manifest", -> it "loads all stylesheets from the stylesheets directory", -> diff --git a/spec/fixtures/packages/package-with-stylesheets-manifest/package.cson b/spec/fixtures/packages/package-with-stylesheets-manifest/package.cson new file mode 100644 index 000000000..45ccf32bc --- /dev/null +++ b/spec/fixtures/packages/package-with-stylesheets-manifest/package.cson @@ -0,0 +1 @@ +stylesheets: ['2', '1'] diff --git a/spec/fixtures/packages/package-with-stylesheets-manifest/stylesheets/1.css b/spec/fixtures/packages/package-with-stylesheets-manifest/stylesheets/1.css new file mode 100644 index 000000000..c16849c0e --- /dev/null +++ b/spec/fixtures/packages/package-with-stylesheets-manifest/stylesheets/1.css @@ -0,0 +1,3 @@ +#jasmine-content { + font-size: 1px; +} diff --git a/spec/fixtures/packages/package-with-stylesheets-manifest/stylesheets/2.less b/spec/fixtures/packages/package-with-stylesheets-manifest/stylesheets/2.less new file mode 100644 index 000000000..c0ffbc897 --- /dev/null +++ b/spec/fixtures/packages/package-with-stylesheets-manifest/stylesheets/2.less @@ -0,0 +1,5 @@ +@size: 2px; + +#jasmine-content { + font-size: @size; +} diff --git a/spec/fixtures/packages/package-with-stylesheets-manifest/stylesheets/3.css b/spec/fixtures/packages/package-with-stylesheets-manifest/stylesheets/3.css new file mode 100644 index 000000000..f43408c63 --- /dev/null +++ b/spec/fixtures/packages/package-with-stylesheets-manifest/stylesheets/3.css @@ -0,0 +1,3 @@ +#jasmine-content { + font-size: 3px; +} diff --git a/src/app/atom-package.coffee b/src/app/atom-package.coffee index 373c440ef..75e9f52a6 100644 --- a/src/app/atom-package.coffee +++ b/src/app/atom-package.coffee @@ -69,9 +69,14 @@ class AtomPackage extends Package loadStylesheets: -> @stylesheets = [] + @stylesheets.push([path, loadStylesheet(path)]) for path in @getStylesheetPaths() + + getStylesheetPaths: -> stylesheetDirPath = fsUtils.join(@path, 'stylesheets') - for stylesheetPath in fsUtils.list(stylesheetDirPath, ['css', 'less']) ? [] - @stylesheets.push([stylesheetPath, loadStylesheet(stylesheetPath)]) + if @metadata.stylesheets + @metadata.stylesheets.map (name) -> fsUtils.resolve(stylesheetDirPath, name, ['css', 'less', '']) + else + fsUtils.list(stylesheetDirPath, ['css', 'less']) ? [] loadGrammars: -> @grammars = []