Make theme loading more similar to package loading

These changes are mostly aesthetic in nature. I just thought it would 
be a good idea to have theme loading be parallel to package loading as
much as possible. So I localized more logic on the `atom` global.
This commit is contained in:
Nathan Sobo 2012-12-31 14:18:45 -06:00
parent bb913ef9e8
commit 2d73aa292d
6 changed files with 18 additions and 31 deletions

View File

@ -8,7 +8,7 @@ describe "TextMateTheme", ->
beforeEach ->
themePath = require.resolve(fs.join('fixtures', 'test.tmTheme'))
[theme] = Theme.load(themePath)
theme = Theme.load(themePath)
afterEach ->
theme.deactivate()

View File

@ -30,19 +30,3 @@ describe "@load(name)", ->
expect($(".editor").css("padding-top")).toBe("101px")
expect($(".editor").css("padding-right")).toBe("102px")
expect($(".editor").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'))
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)")

View File

@ -3,6 +3,7 @@ fs = require 'fs'
_ = require 'underscore'
Package = require 'package'
TextMatePackage = require 'text-mate-package'
Theme = require 'theme'
messageIdCounter = 1
originalSendMessageToBrowserProcess = atom.sendMessageToBrowserProcess
@ -30,7 +31,15 @@ _.extend atom,
@loadPackage(packageName) unless _.contains(disabledPackages, packageName)
loadPackage: (name) ->
Package.forName(name).load()
Package.load(name)
loadThemes: ->
themeNames = config.get("core.themes") ? ['IR_Black']
themeNames = [themeNames] unless _.isArray(themeNames)
@loadTheme(themeName) for themeName in themeNames
loadTheme: (name) ->
Theme.load(name)
open: (args...) ->
@sendMessageToBrowserProcess('open', args)

View File

@ -32,7 +32,7 @@ class Config
@loadUserConfig()
@requireUserInitScript()
atom.loadPackages()
Theme.load(config.get("core.theme") ? 'IR_Black')
atom.loadThemes()
loadUserConfig: ->
if fs.exists(configJsonPath)

View File

@ -2,14 +2,14 @@ fs = require 'fs'
module.exports =
class Package
@forName: (name) ->
@load: (name) ->
AtomPackage = require 'atom-package'
TextMatePackage = require 'text-mate-package'
if TextMatePackage.testName(name)
new TextMatePackage(name)
new TextMatePackage(name).load()
else
new AtomPackage(name)
new AtomPackage(name).load()
constructor: (@name) ->
@path = require.resolve(@name, verifyExistence: false)

View File

@ -6,13 +6,7 @@ module.exports =
class Theme
@stylesheets: null
@load: (names) ->
if typeof(names) == "string"
[@loadTheme(names)]
else
names.map (name) => @loadTheme(name)
@loadTheme: (name) ->
@load: (name) ->
if fs.exists(name)
path = name
else
@ -25,7 +19,7 @@ class Theme
theme = @loadAtomTheme(path)
throw new Error("Cannot activate theme named '#{name}' located at '#{path}'") unless theme
theme.activate()
theme.load()
theme
@loadTextMateTheme: (path) ->
@ -47,7 +41,7 @@ class Theme
constructor: (@path) ->
@stylesheets = {}
activate: ->
load: ->
for stylesheetPath, stylesheetContent of @stylesheets
applyStylesheet(stylesheetPath, stylesheetContent)