mirror of
https://github.com/atom/atom.git
synced 2026-02-12 23:55:10 -05:00
TextMateTheme extend Theme
This commit is contained in:
@@ -1,41 +1,17 @@
|
||||
_ = require 'underscore'
|
||||
fs = require 'fs'
|
||||
plist = require 'plist'
|
||||
|
||||
Theme = require 'Theme'
|
||||
|
||||
module.exports =
|
||||
class TextMateTheme
|
||||
@load: (name) ->
|
||||
regex = new RegExp("#{_.escapeRegExp(name)}\.(tmTheme|plist)$", "i")
|
||||
|
||||
if fs.exists(name)
|
||||
path = name
|
||||
else
|
||||
path = _.find fs.list(config.themeDirPath), (path) -> regex.test(path)
|
||||
|
||||
return null unless path
|
||||
|
||||
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(data[0])
|
||||
theme
|
||||
|
||||
@activate: (name) ->
|
||||
if theme = @load(name)
|
||||
theme.activate()
|
||||
else
|
||||
throw new Error("No theme with name '#{name}'")
|
||||
|
||||
constructor: ({@name, settings}) ->
|
||||
class TextMateTheme extends Theme
|
||||
constructor: (@path, {settings}) ->
|
||||
super
|
||||
@rulesets = []
|
||||
globalSettings = settings[0]
|
||||
@buildGlobalSettingsRulesets(settings[0])
|
||||
@buildScopeSelectorRulesets(settings[1..])
|
||||
|
||||
activate: ->
|
||||
applyStylesheet(@name, @getStylesheet())
|
||||
|
||||
getStylesheet: ->
|
||||
lines = []
|
||||
for {selector, properties} in @getRulesets()
|
||||
|
||||
46
src/app/theme.coffee
Normal file
46
src/app/theme.coffee
Normal file
@@ -0,0 +1,46 @@
|
||||
fs = require("fs")
|
||||
plist = require 'plist'
|
||||
_ = require 'underscore'
|
||||
|
||||
module.exports =
|
||||
class Theme
|
||||
@load: (name) ->
|
||||
if fs.exists(name)
|
||||
path = name
|
||||
else
|
||||
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
|
||||
throw new Error("I only know how to load textmate themes!")
|
||||
|
||||
if theme
|
||||
theme.activate()
|
||||
else
|
||||
throw new Error("Cannot activate theme named '#{name}'")
|
||||
|
||||
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
|
||||
|
||||
@isTextMateTheme: (path) ->
|
||||
/\.(tmTheme|plist)$/.test(path)
|
||||
|
||||
constructor: (@path) ->
|
||||
|
||||
activate: ->
|
||||
applyStylesheet(@path, @getStylesheet())
|
||||
|
||||
getStylesheet: ->
|
||||
fs.read(@path)
|
||||
Reference in New Issue
Block a user