Break AtomTheme out into its own file.

This commit is contained in:
Corey Johnson
2012-12-27 15:25:16 -08:00
parent 0d946078c9
commit 82abbaa71c
4 changed files with 29 additions and 17 deletions

View File

@@ -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()

11
src/app/atom-theme.coffee Normal file
View File

@@ -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)

View File

@@ -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: ->

View File

@@ -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