diff --git a/src/app/atom-theme.coffee b/src/app/atom-theme.coffee index 531bb34ec..f955402b5 100644 --- a/src/app/atom-theme.coffee +++ b/src/app/atom-theme.coffee @@ -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 diff --git a/src/app/text-mate-theme.coffee b/src/app/text-mate-theme.coffee index caae44298..9c56ec222 100644 --- a/src/app/text-mate-theme.coffee +++ b/src/app/text-mate-theme.coffee @@ -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 = [] diff --git a/src/app/theme.coffee b/src/app/theme.coffee index dde5144bb..6c415759e 100644 --- a/src/app/theme.coffee +++ b/src/app/theme.coffee @@ -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) \ No newline at end of file + removeStylesheet(stylesheetPath)