Flatten src directory

* Move src/app to src/
  * Move src/stdlib to src/
  * Remove src/app and src/stdlib from NODE_PATH
This commit is contained in:
Kevin Sawicki
2013-08-14 10:46:20 -07:00
parent 45c11e6fd4
commit 76332c76bd
60 changed files with 0 additions and 2 deletions

58
src/theme-manager.coffee Normal file
View File

@@ -0,0 +1,58 @@
path = require 'path'
EventEmitter = require 'event-emitter'
_ = require 'underscore'
fsUtils = require 'fs-utils'
Theme = require 'theme'
module.exports =
class ThemeManager
_.extend @prototype, EventEmitter
constructor: ->
@loadedThemes = []
getAvailablePaths: ->
themePaths = []
for themeDirPath in config.themeDirPaths
themePaths.push(fsUtils.listSync(themeDirPath, ['', '.css', 'less'])...)
_.uniq(themePaths)
getAvailableNames: ->
path.basename(themePath).split('.')[0] for themePath in @getAvailablePaths()
unload: ->
removeStylesheet(@userStylesheetPath) if @userStylesheetPath?
theme.deactivate() while theme = @loadedThemes.pop()
load: ->
config.observe 'core.themes', (themeNames) =>
@unload()
themeNames = [themeNames] unless _.isArray(themeNames)
@loadTheme(themeName) for themeName in themeNames
@loadUserStylesheet()
@trigger('reloaded')
loadTheme: (name) ->
try
@loadedThemes.push(new Theme(name))
catch error
console.warn("Failed to load theme #{name}", error.stack ? error)
getUserStylesheetPath: ->
stylesheetPath = fsUtils.resolve(path.join(config.configDirPath, 'user'), ['css', 'less'])
if fsUtils.isFileSync(stylesheetPath)
stylesheetPath
else
null
getImportPaths: ->
theme.directoryPath for theme in @loadedThemes when theme.directoryPath
loadUserStylesheet: ->
if userStylesheetPath = @getUserStylesheetPath()
@userStylesheetPath = userStylesheetPath
userStylesheetContents = loadStylesheet(userStylesheetPath)
applyStylesheet(userStylesheetPath, userStylesheetContents, 'userTheme')