From 82abbaa71c94d8686bc0d87360236229e46c9674 Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Thu, 27 Dec 2012 15:25:16 -0800 Subject: [PATCH] Break AtomTheme out into its own file. --- spec/app/theme-spec.coffee | 12 +++++++++++- src/app/atom-theme.coffee | 11 +++++++++++ src/app/text-mate-theme.coffee | 3 +-- src/app/theme.coffee | 20 ++++++-------------- 4 files changed, 29 insertions(+), 17 deletions(-) create mode 100644 src/app/atom-theme.coffee diff --git a/spec/app/theme-spec.coffee b/spec/app/theme-spec.coffee index 5a64fa22a..01da55c61 100644 --- a/spec/app/theme-spec.coffee +++ b/spec/app/theme-spec.coffee @@ -2,7 +2,16 @@ $ = require 'jquery' fs = require 'fs' Theme = require 'theme' -describe "Theme", -> +describe "TextMateTheme", -> + describe "@load(name)", -> + it "applies the theme's stylesheet to the current window", -> + themePath = require.resolve(fs.join('fixtures', 'test.tmTheme')) + spyOn window, 'applyStylesheet' + theme = Theme.load(themePath) + expect(window.applyStylesheet).toHaveBeenCalledWith(themePath, theme.getStylesheet()) + theme.deactivate() + +describe "AtomTheme", -> describe "@load(name)", -> it "Loads and applies css from package.json in the correct order", -> themePath = require.resolve(fs.join('fixtures', 'test-atom-theme')) @@ -14,4 +23,5 @@ describe "Theme", -> expect($(document.body).css("padding-top")).toBe("101px") expect($(document.body).css("padding-right")).toBe("102px") expect($(document.body).css("padding-bottom")).toBe("103px") + theme.deactivate() diff --git a/src/app/atom-theme.coffee b/src/app/atom-theme.coffee new file mode 100644 index 000000000..531bb34ec --- /dev/null +++ b/src/app/atom-theme.coffee @@ -0,0 +1,11 @@ +fs = require 'fs' +Theme = require 'theme' + +module.exports = +class AtomTheme extends Theme + constructor: (@path) -> + super + json = fs.read(fs.join(path, "package.json")) + for stylesheetName in JSON.parse(json).stylesheets + stylesheetPath = fs.join(@path, stylesheetName) + @stylesheets[stylesheetPath] = fs.read(stylesheetPath) diff --git a/src/app/text-mate-theme.coffee b/src/app/text-mate-theme.coffee index 4fd21b42a..5aafb7e3d 100644 --- a/src/app/text-mate-theme.coffee +++ b/src/app/text-mate-theme.coffee @@ -5,12 +5,11 @@ Theme = require 'Theme' module.exports = class TextMateTheme extends Theme constructor: (@path, {settings}) -> + super @rulesets = [] globalSettings = settings[0] @buildGlobalSettingsRulesets(settings[0]) @buildScopeSelectorRulesets(settings[1..]) - - @stylesheets = {} @stylesheets[@path] = @getStylesheet() getStylesheet: -> diff --git a/src/app/theme.coffee b/src/app/theme.coffee index bf429892f..d52f8f5e3 100644 --- a/src/app/theme.coffee +++ b/src/app/theme.coffee @@ -4,6 +4,8 @@ _ = require 'underscore' module.exports = class Theme + @stylesheets: null + @load: (name) -> if fs.exists(name) path = name @@ -11,18 +13,13 @@ class Theme regex = new RegExp("#{_.escapeRegExp(name)}(\.[^.]*)?$", "i") path = _.find fs.list(config.themeDirPath), (path) -> regex.test(path) - return null unless path - if @isTextMateTheme(path) theme = @loadTextMateTheme(path) else theme = @loadAtomTheme(path) - if theme - theme.activate() - else - throw new Error("Cannot activate theme named '#{name}'") - + throw new Error("Cannot activate theme named '#{name}' located at '#{path}'") unless theme + theme.activate() theme @loadTextMateTheme: (path) -> @@ -35,19 +32,14 @@ class Theme theme @loadAtomTheme: (path) -> - new Theme(path) + AtomTheme = require('atom-theme') + new AtomTheme(path) @isTextMateTheme: (path) -> /\.(tmTheme|plist)$/.test(path) - @stylesheets: null - constructor: (@path) -> - json = fs.read(fs.join(path, "package.json")) @stylesheets = {} - for stylesheetName in JSON.parse(json).stylesheets - stylesheetPath = fs.join(@path, stylesheetName) - @stylesheets[stylesheetPath] = fs.read(stylesheetPath) activate: -> for stylesheetPath, stylesheetContent of @stylesheets