mirror of
https://github.com/atom/atom.git
synced 2026-02-15 00:55:14 -05:00
Move Theme loading to instance methods on TextMate & Atom subclasses
This commit is contained in:
@@ -3,9 +3,9 @@ Theme = require 'theme'
|
||||
|
||||
module.exports =
|
||||
class AtomTheme extends Theme
|
||||
constructor: (@path) ->
|
||||
super
|
||||
json = fs.read(fs.join(path, "package.json"))
|
||||
load: ->
|
||||
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)
|
||||
super
|
||||
|
||||
@@ -1,16 +1,27 @@
|
||||
_ = require 'underscore'
|
||||
fs = require 'fs'
|
||||
plist = require 'plist'
|
||||
Theme = require 'theme'
|
||||
|
||||
module.exports =
|
||||
class TextMateTheme extends Theme
|
||||
constructor: (@path, {settings}) ->
|
||||
@testPath: (path) ->
|
||||
/\.(tmTheme|plist)$/.test(path)
|
||||
|
||||
constructor: (@path) ->
|
||||
super
|
||||
@rulesets = []
|
||||
globalSettings = settings[0]
|
||||
@buildGlobalSettingsRulesets(settings[0])
|
||||
@buildScopeSelectorRulesets(settings[1..])
|
||||
|
||||
load: ->
|
||||
@buildRulesets()
|
||||
@stylesheets[@path] = @getStylesheet()
|
||||
super
|
||||
|
||||
buildRulesets: ->
|
||||
plist.parseString fs.read(@path), (error, [{settings}]) =>
|
||||
throw new Error("Error loading theme at '#{@path}': #{error}") if error
|
||||
@buildGlobalSettingsRulesets(settings[0])
|
||||
@buildScopeSelectorRulesets(settings[1..])
|
||||
|
||||
getStylesheet: ->
|
||||
lines = []
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
fs = require("fs")
|
||||
plist = require 'plist'
|
||||
_ = require 'underscore'
|
||||
|
||||
module.exports =
|
||||
@@ -7,37 +6,28 @@ class Theme
|
||||
@stylesheets: null
|
||||
|
||||
@load: (name) ->
|
||||
TextMateTheme = require 'text-mate-theme'
|
||||
AtomTheme = require 'atom-theme'
|
||||
|
||||
if fs.exists(name)
|
||||
path = name
|
||||
else
|
||||
path = fs.resolve(config.themeDirPaths..., name)
|
||||
path ?= fs.resolve(config.themeDirPaths..., name + ".tmTheme")
|
||||
|
||||
if @isTextMateTheme(path)
|
||||
theme = @loadTextMateTheme(path)
|
||||
else
|
||||
theme = @loadAtomTheme(path)
|
||||
throw new Error("No theme exists named '#{name}'") unless path
|
||||
|
||||
theme =
|
||||
if TextMateTheme.testPath(path)
|
||||
console.log "it's TM"
|
||||
new TextMateTheme(path)
|
||||
else
|
||||
console.log "it's atom"
|
||||
new AtomTheme(path)
|
||||
|
||||
throw new Error("Cannot activate theme named '#{name}' located at '#{path}'") unless theme
|
||||
theme.load()
|
||||
theme
|
||||
|
||||
@loadTextMateTheme: (path) ->
|
||||
TextMateTheme = require("text-mate-theme")
|
||||
plistString = fs.read(path)
|
||||
theme = null
|
||||
plist.parseString plistString, (err, data) ->
|
||||
throw new Error("Error loading theme at '#{path}': #{err}") if err
|
||||
theme = new TextMateTheme(path, data[0])
|
||||
theme
|
||||
|
||||
@loadAtomTheme: (path) ->
|
||||
AtomTheme = require('atom-theme')
|
||||
new AtomTheme(path)
|
||||
|
||||
@isTextMateTheme: (path) ->
|
||||
/\.(tmTheme|plist)$/.test(path)
|
||||
|
||||
constructor: (@path) ->
|
||||
@stylesheets = {}
|
||||
|
||||
@@ -47,4 +37,4 @@ class Theme
|
||||
|
||||
deactivate: ->
|
||||
for stylesheetPath, stylesheetContent of @stylesheets
|
||||
window.removeStylesheet(stylesheetPath)
|
||||
removeStylesheet(stylesheetPath)
|
||||
|
||||
Reference in New Issue
Block a user