From 43d46f0705e477493131d01cbfc019463ff5c1f2 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 14 Feb 2013 09:03:10 -0800 Subject: [PATCH] Load all .css files when theme has no package file Closes #263 --- spec/app/theme-spec.coffee | 39 ++++++++++++++----- spec/fixtures/themes/theme-stylesheet.css | 3 ++ .../theme-with-package-file}/first.css | 0 .../theme-with-package-file}/last.css | 0 .../theme-with-package-file}/package.json | 0 .../theme-with-package-file}/second.css | 0 .../themes/theme-without-package-file/a.css | 5 +++ .../themes/theme-without-package-file/b.css | 4 ++ .../themes/theme-without-package-file/c.css | 3 ++ .../themes/theme-without-package-file/d.csv | 5 +++ src/app/atom-theme.coffee | 9 ++++- 11 files changed, 57 insertions(+), 11 deletions(-) create mode 100644 spec/fixtures/themes/theme-stylesheet.css rename spec/fixtures/{test-atom-theme => themes/theme-with-package-file}/first.css (100%) rename spec/fixtures/{test-atom-theme => themes/theme-with-package-file}/last.css (100%) rename spec/fixtures/{test-atom-theme => themes/theme-with-package-file}/package.json (100%) rename spec/fixtures/{test-atom-theme => themes/theme-with-package-file}/second.css (100%) create mode 100644 spec/fixtures/themes/theme-without-package-file/a.css create mode 100644 spec/fixtures/themes/theme-without-package-file/b.css create mode 100644 spec/fixtures/themes/theme-without-package-file/c.css create mode 100644 spec/fixtures/themes/theme-without-package-file/d.csv diff --git a/spec/app/theme-spec.coffee b/spec/app/theme-spec.coffee index aef4aab8e..5afebc983 100644 --- a/spec/app/theme-spec.coffee +++ b/spec/app/theme-spec.coffee @@ -20,13 +20,34 @@ describe "@load(name)", -> expect($(".editor").css("background-color")).toBe("rgb(20, 20, 20)") describe "AtomTheme", -> - it "Loads and applies css from package.json in the correct order", -> - expect($(".editor").css("padding-top")).not.toBe("101px") - expect($(".editor").css("padding-right")).not.toBe("102px") - expect($(".editor").css("padding-bottom")).not.toBe("103px") + describe "when the theme contains a package.json file", -> + it "loads and applies css from package.json in the correct order", -> + expect($(".editor").css("padding-top")).not.toBe("101px") + expect($(".editor").css("padding-right")).not.toBe("102px") + expect($(".editor").css("padding-bottom")).not.toBe("103px") - themePath = require.resolve(fs.join('fixtures', 'test-atom-theme')) - theme = Theme.load(themePath) - expect($(".editor").css("padding-top")).toBe("101px") - expect($(".editor").css("padding-right")).toBe("102px") - expect($(".editor").css("padding-bottom")).toBe("103px") + themePath = fixturesProject.resolve('themes/theme-with-package-file') + theme = Theme.load(themePath) + expect($(".editor").css("padding-top")).toBe("101px") + expect($(".editor").css("padding-right")).toBe("102px") + expect($(".editor").css("padding-bottom")).toBe("103px") + + describe "when the theme is a CSS file", -> + it "loads and applies the stylesheet", -> + expect($(".editor").css("padding-bottom")).not.toBe "1234px" + + themePath = fixturesProject.resolve('themes/theme-stylesheet.css') + theme = Theme.load(themePath) + expect($(".editor").css("padding-top")).toBe "1234px" + + describe "when the theme does not contain a package.json file and is a directory", -> + it "loads all CSS files in the directory", -> + expect($(".editor").css("padding-top")).not.toBe "10px" + expect($(".editor").css("padding-right")).not.toBe "20px" + expect($(".editor").css("padding-bottom")).not.toBe "30px" + + themePath = fixturesProject.resolve('themes/theme-without-package-file') + theme = Theme.load(themePath) + expect($(".editor").css("padding-top")).toBe "10px" + expect($(".editor").css("padding-right")).toBe "20px" + expect($(".editor").css("padding-bottom")).toBe "30px" diff --git a/spec/fixtures/themes/theme-stylesheet.css b/spec/fixtures/themes/theme-stylesheet.css new file mode 100644 index 000000000..f69c961a4 --- /dev/null +++ b/spec/fixtures/themes/theme-stylesheet.css @@ -0,0 +1,3 @@ +.editor { + padding-top: 1234px; +} diff --git a/spec/fixtures/test-atom-theme/first.css b/spec/fixtures/themes/theme-with-package-file/first.css similarity index 100% rename from spec/fixtures/test-atom-theme/first.css rename to spec/fixtures/themes/theme-with-package-file/first.css diff --git a/spec/fixtures/test-atom-theme/last.css b/spec/fixtures/themes/theme-with-package-file/last.css similarity index 100% rename from spec/fixtures/test-atom-theme/last.css rename to spec/fixtures/themes/theme-with-package-file/last.css diff --git a/spec/fixtures/test-atom-theme/package.json b/spec/fixtures/themes/theme-with-package-file/package.json similarity index 100% rename from spec/fixtures/test-atom-theme/package.json rename to spec/fixtures/themes/theme-with-package-file/package.json diff --git a/spec/fixtures/test-atom-theme/second.css b/spec/fixtures/themes/theme-with-package-file/second.css similarity index 100% rename from spec/fixtures/test-atom-theme/second.css rename to spec/fixtures/themes/theme-with-package-file/second.css diff --git a/spec/fixtures/themes/theme-without-package-file/a.css b/spec/fixtures/themes/theme-without-package-file/a.css new file mode 100644 index 000000000..aeb9ea203 --- /dev/null +++ b/spec/fixtures/themes/theme-without-package-file/a.css @@ -0,0 +1,5 @@ +.editor { + padding-top: 10px; + padding-right: 10px; + padding-bottom: 10px; +} diff --git a/spec/fixtures/themes/theme-without-package-file/b.css b/spec/fixtures/themes/theme-without-package-file/b.css new file mode 100644 index 000000000..111a7c262 --- /dev/null +++ b/spec/fixtures/themes/theme-without-package-file/b.css @@ -0,0 +1,4 @@ +.editor { + padding-right: 20px; + padding-bottom: 20px; +} diff --git a/spec/fixtures/themes/theme-without-package-file/c.css b/spec/fixtures/themes/theme-without-package-file/c.css new file mode 100644 index 000000000..017dea2af --- /dev/null +++ b/spec/fixtures/themes/theme-without-package-file/c.css @@ -0,0 +1,3 @@ +.editor { + padding-bottom: 30px; +} diff --git a/spec/fixtures/themes/theme-without-package-file/d.csv b/spec/fixtures/themes/theme-without-package-file/d.csv new file mode 100644 index 000000000..91e4e7887 --- /dev/null +++ b/spec/fixtures/themes/theme-without-package-file/d.csv @@ -0,0 +1,5 @@ +.editor { + padding-top: 100px; + padding-right: 100px; + padding-bottom: 100px; +} diff --git a/src/app/atom-theme.coffee b/src/app/atom-theme.coffee index 1d0224acf..6a3e1e379 100644 --- a/src/app/atom-theme.coffee +++ b/src/app/atom-theme.coffee @@ -12,6 +12,11 @@ class AtomTheme extends Theme @loadStylesheet(@path) else metadataPath = fs.resolveExtension(fs.join(@path, 'package'), ['cson', 'json']) - stylesheetNames = fs.readObject(metadataPath).stylesheets - @loadStylesheet(fs.join(@path, name)) for name in stylesheetNames + if fs.isFile(metadataPath) + stylesheetNames = fs.readObject(metadataPath)?.stylesheets + if stylesheetNames + @loadStylesheet(fs.join(@path, name)) for name in stylesheetNames + else + @loadStylesheet(stylesheetPath) for stylesheetPath in fs.list(@path, ['.css']) + super