mirror of
https://github.com/atom/atom.git
synced 2026-01-24 06:18:03 -05:00
Break AtomTheme out into its own file.
This commit is contained in:
@@ -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
11
src/app/atom-theme.coffee
Normal 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)
|
||||
@@ -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: ->
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user