Files
atom/src/theme.coffee
Kevin Sawicki 76332c76bd Flatten src directory
* Move src/app to src/
  * Move src/stdlib to src/
  * Remove src/app and src/stdlib from NODE_PATH
2013-08-19 20:13:57 -07:00

48 lines
1.6 KiB
CoffeeScript

fsUtils = require 'fs-utils'
path = require 'path'
### Internal ###
module.exports =
class Theme
stylesheetPath: null
stylesheets: null
constructor: (name) ->
@stylesheets = []
if fsUtils.exists(name)
@stylesheetPath = name
else
@stylesheetPath = fsUtils.resolve(config.themeDirPaths..., name, ['', '.css', 'less'])
throw new Error("No theme exists named '#{name}'") unless @stylesheetPath
@load()
# Loads the stylesheets found in a `package.cson` file.
load: ->
if path.extname(@stylesheetPath) in ['.css', '.less']
@loadStylesheet(@stylesheetPath)
else
@directoryPath = @stylesheetPath
metadataPath = fsUtils.resolveExtension(path.join(@stylesheetPath, 'package'), ['cson', 'json'])
if fsUtils.isFileSync(metadataPath)
@metadata = fsUtils.readObjectSync(metadataPath)
if @metadata?.stylesheets
for name in @metadata.stylesheets
filename = fsUtils.resolveExtension(path.join(@stylesheetPath, name), ['.css', '.less', ''])
@loadStylesheet(filename)
else
@loadStylesheet(stylesheetPath) for stylesheetPath in fsUtils.listSync(@stylesheetPath, ['.css', '.less'])
# Given a path, this loads it as a stylesheet.
#
# stylesheetPath - A {String} to a stylesheet
loadStylesheet: (stylesheetPath) ->
@stylesheets.push stylesheetPath
content = window.loadStylesheet(stylesheetPath)
window.applyStylesheet(stylesheetPath, content, 'userTheme')
deactivate: ->
window.removeStylesheet(stylesheetPath) for stylesheetPath in @stylesheets