From 4a6d336763d0e5cb9d64c982aec14d2a72e84213 Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Thu, 27 Dec 2012 16:09:31 -0800 Subject: [PATCH] Theme.load can take multiple theme names --- spec/app/text-mate-theme-spec.coffee | 9 ++-- spec/app/theme-spec.coffee | 53 +++++++++++++++++------- spec/fixtures/test-atom-theme/first.css | 4 +- spec/fixtures/test-atom-theme/last.css | 2 +- spec/fixtures/test-atom-theme/second.css | 2 +- src/app/config.coffee | 4 +- src/app/theme.coffee | 8 +++- 7 files changed, 53 insertions(+), 29 deletions(-) diff --git a/spec/app/text-mate-theme-spec.coffee b/spec/app/text-mate-theme-spec.coffee index b879ec7d0..0ea739f7e 100644 --- a/spec/app/text-mate-theme-spec.coffee +++ b/spec/app/text-mate-theme-spec.coffee @@ -8,13 +8,10 @@ describe "TextMateTheme", -> beforeEach -> themePath = require.resolve(fs.join('fixtures', 'test.tmTheme')) - theme = Theme.load(themePath) + [theme] = Theme.load(themePath) - describe "@load(name)", -> - it "applies the theme's stylesheet to the current window", -> - spyOn window, 'applyStylesheet' - Theme.load(themePath) - expect(window.applyStylesheet).toHaveBeenCalledWith(themePath, theme.getStylesheet()) + afterEach -> + theme.deactivate() describe ".getRulesets()", -> rulesets = null diff --git a/spec/app/theme-spec.coffee b/spec/app/theme-spec.coffee index 01da55c61..4c366db10 100644 --- a/spec/app/theme-spec.coffee +++ b/spec/app/theme-spec.coffee @@ -2,26 +2,47 @@ $ = require 'jquery' fs = require 'fs' Theme = require 'theme' -describe "TextMateTheme", -> - describe "@load(name)", -> +fdescribe "@load(name)", -> + themes = null + + beforeEach -> + $("#jasmine-content").append $("
") + + afterEach -> + theme.deactivate() for theme in themes + + describe "TextMateTheme", -> it "applies the theme's stylesheet to the current window", -> + expect($(".editor").css("background-color")).not.toBe("rgb(20, 20, 20)") + themePath = require.resolve(fs.join('fixtures', 'test.tmTheme')) - spyOn window, 'applyStylesheet' - theme = Theme.load(themePath) - expect(window.applyStylesheet).toHaveBeenCalledWith(themePath, theme.getStylesheet()) - theme.deactivate() + themes = Theme.load(themePath) + expect($(".editor").css("background-color")).toBe("rgb(20, 20, 20)") -describe "AtomTheme", -> - describe "@load(name)", -> + 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") + themePath = require.resolve(fs.join('fixtures', 'test-atom-theme')) + themes = Theme.load(themePath) + expect($(".editor").css("padding-top")).toBe("101px") + expect($(".editor").css("padding-right")).toBe("102px") + expect($(".editor").css("padding-bottom")).toBe("103px") - expect($(document.body).css("padding-top")).not.toBe("101px") - expect($(document.body).css("padding-right")).not.toBe("102px") - expect($(document.body).css("padding-bottom")).not.toBe("103px") - theme = Theme.load(themePath) - expect($(document.body).css("padding-top")).toBe("101px") - expect($(document.body).css("padding-right")).toBe("102px") - expect($(document.body).css("padding-bottom")).toBe("103px") + describe "when name is an array of themes", -> + it "loads all themes in order", -> + firstThemePath = require.resolve(fs.join('fixtures', 'test.tmTheme')) + secondThemePath = require.resolve(fs.join('fixtures', 'test-atom-theme')) - theme.deactivate() + expect($(".editor").css("padding-top")).not.toBe("101px") + expect($(".editor").css("padding-right")).not.toBe("102px") + expect($(".editor").css("padding-bottom")).not.toBe("103px") + expect($(".editor").css("color")).not.toBe("rgb(0, 255, 0)") + + themes = Theme.load([firstThemePath, secondThemePath]) + expect($(".editor").css("padding-top")).toBe("101px") + expect($(".editor").css("padding-right")).toBe("102px") + expect($(".editor").css("padding-bottom")).toBe("103px") + expect($(".editor").css("color")).toBe("rgb(255, 0, 0)") diff --git a/spec/fixtures/test-atom-theme/first.css b/spec/fixtures/test-atom-theme/first.css index 65f387e95..f9af1a345 100644 --- a/spec/fixtures/test-atom-theme/first.css +++ b/spec/fixtures/test-atom-theme/first.css @@ -1,5 +1,7 @@ -body { +.editor { padding-top: 101px; padding-right: 101px; padding-bottom: 101px; + + color: red; } \ No newline at end of file diff --git a/spec/fixtures/test-atom-theme/last.css b/spec/fixtures/test-atom-theme/last.css index df4661420..c0cface8c 100644 --- a/spec/fixtures/test-atom-theme/last.css +++ b/spec/fixtures/test-atom-theme/last.css @@ -1,4 +1,4 @@ -body { +.editor { /* padding-top: 103px; padding-right: 103px;*/ padding-bottom: 103px; diff --git a/spec/fixtures/test-atom-theme/second.css b/spec/fixtures/test-atom-theme/second.css index c34cf946b..3ddf03add 100644 --- a/spec/fixtures/test-atom-theme/second.css +++ b/spec/fixtures/test-atom-theme/second.css @@ -1,4 +1,4 @@ -body { +.editor { /* padding-top: 102px;*/ padding-right: 102px; padding-bottom: 102px; diff --git a/src/app/config.coffee b/src/app/config.coffee index cd307becd..9b10426dc 100644 --- a/src/app/config.coffee +++ b/src/app/config.coffee @@ -31,9 +31,7 @@ class Config @loadUserConfig() @requireUserInitScript() atom.loadPackages() - - themeName = config.get("core.theme") ? 'IR_Black' - Theme.load(themeName) + Theme.load(config.get("core.theme") ? 'IR_Black') loadUserConfig: -> if fs.exists(configJsonPath) diff --git a/src/app/theme.coffee b/src/app/theme.coffee index d52f8f5e3..59f7ae08a 100644 --- a/src/app/theme.coffee +++ b/src/app/theme.coffee @@ -6,7 +6,13 @@ module.exports = class Theme @stylesheets: null - @load: (name) -> + @load: (names) -> + if typeof(names) == "string" + [@loadTheme(names)] + else + names.map (name) => @loadTheme(name) + + @loadTheme: (name) -> if fs.exists(name) path = name else