mirror of
https://github.com/atom/atom.git
synced 2026-01-22 21:38:10 -05:00
Make the build green
This commit is contained in:
@@ -13,6 +13,8 @@ module.exports =
|
||||
class AtomPackage extends Package
|
||||
_.extend @prototype, EventEmitter
|
||||
|
||||
@stylesheetsDir: 'stylesheets'
|
||||
|
||||
metadata: null
|
||||
keymaps: null
|
||||
stylesheets: null
|
||||
@@ -84,17 +86,16 @@ class AtomPackage extends Package
|
||||
@stylesheets = @getStylesheetPaths().map (stylesheetPath) -> [stylesheetPath, loadStylesheet(stylesheetPath)]
|
||||
|
||||
getStylesheetsPath: ->
|
||||
path.join(@path, 'stylesheets')
|
||||
path.join(@path, @constructor.stylesheetsDir)
|
||||
|
||||
getStylesheetPaths: ->
|
||||
stylesheetDirPath = @getStylesheetsPath()
|
||||
indexStylesheet = fsUtils.resolve(@path, 'index', ['css', 'less'])
|
||||
|
||||
if @metadata.stylesheetMain
|
||||
[fsUtils.resolve(stylesheetDirPath, @metadata.stylesheetMain)]
|
||||
[fsUtils.resolve(@path, @metadata.stylesheetMain)]
|
||||
else if @metadata.stylesheets
|
||||
@metadata.stylesheets.map (name) -> fsUtils.resolve(stylesheetDirPath, name, ['css', 'less', ''])
|
||||
else if indexStylesheet
|
||||
else if indexStylesheet = fsUtils.resolve(@path, 'index', ['css', 'less'])
|
||||
[indexStylesheet]
|
||||
else
|
||||
fsUtils.listSync(stylesheetDirPath, ['css', 'less'])
|
||||
|
||||
@@ -36,3 +36,6 @@ class Package
|
||||
|
||||
isActive: ->
|
||||
atom.isPackageActive(@name)
|
||||
|
||||
isTheme: ->
|
||||
!!@metadata?.theme
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
path = require 'path'
|
||||
EventEmitter = require 'event-emitter'
|
||||
Package = require 'package'
|
||||
AtomPackage = require 'atom-package'
|
||||
|
||||
_ = require 'underscore'
|
||||
|
||||
@@ -11,22 +13,28 @@ class ThemeManager
|
||||
_.extend @prototype, EventEmitter
|
||||
|
||||
constructor: ->
|
||||
@registeredThemes = []
|
||||
@loadedThemes = []
|
||||
@activeThemes = []
|
||||
|
||||
# Internal-only:
|
||||
register: (theme) ->
|
||||
@registeredThemes.push(theme)
|
||||
@loadedThemes.push(theme)
|
||||
theme
|
||||
|
||||
# Internal-only:
|
||||
getAvailableNames: ->
|
||||
_.map(@registeredThemes, (t) -> t?.metadata?.name)
|
||||
_.map(@loadedThemes, (t) -> t.metadata.name)
|
||||
|
||||
# Internal-only:
|
||||
getActiveThemes: ->
|
||||
_.clone(@activeThemes)
|
||||
|
||||
# Internal-only:
|
||||
unload: ->
|
||||
removeStylesheet(@userStylesheetPath) if @userStylesheetPath?
|
||||
theme.deactivate() while theme = @activeThemes.pop()
|
||||
|
||||
# Internal-only:
|
||||
load: ->
|
||||
config.observe 'core.themes', (themeNames) =>
|
||||
@unload()
|
||||
@@ -36,17 +44,48 @@ class ThemeManager
|
||||
|
||||
@trigger('reloaded')
|
||||
|
||||
activateTheme: (name) ->
|
||||
theme = _.find(@registeredThemes, (t) -> t.metadata.name == name)
|
||||
return console.warn("Theme '#{name}' not found.") unless theme
|
||||
# Private:
|
||||
loadTheme: (name, options) ->
|
||||
if themePath = @resolveThemePath(name)
|
||||
return theme if theme = @getLoadedTheme(name)
|
||||
pack = Package.load(themePath, options)
|
||||
if pack.isTheme()
|
||||
@register(pack)
|
||||
else
|
||||
throw new Error("Attempted to load a non-theme package '#{name}' as a theme")
|
||||
else
|
||||
throw new Error("Could not resolve '#{name}' to a theme path")
|
||||
|
||||
# Private:
|
||||
getLoadedTheme: (name) ->
|
||||
_.find(@loadedThemes, (t) -> t.metadata.name == name)
|
||||
|
||||
# Private:
|
||||
resolveThemePath: (name) ->
|
||||
return name if fsUtils.isDirectorySync(name)
|
||||
|
||||
packagePath = fsUtils.resolve(config.packageDirPaths..., name)
|
||||
return packagePath if fsUtils.isDirectorySync(packagePath)
|
||||
|
||||
packagePath = path.join(window.resourcePath, 'node_modules', name)
|
||||
return packagePath if @isThemePath(packagePath)
|
||||
|
||||
# Private:
|
||||
isThemePath: (packagePath) ->
|
||||
{engines, theme} = Package.loadMetadata(packagePath, true)
|
||||
engines?.atom? and theme
|
||||
|
||||
# Private:
|
||||
activateTheme: (name) ->
|
||||
try
|
||||
theme = @loadTheme(name)
|
||||
theme.activate()
|
||||
@activeThemes.push(theme)
|
||||
@trigger('theme-activated', theme)
|
||||
catch error
|
||||
console.warn("Failed to load theme #{name}", error.stack ? error)
|
||||
|
||||
# Public:
|
||||
getUserStylesheetPath: ->
|
||||
stylesheetPath = fsUtils.resolve(path.join(config.configDirPath, 'user'), ['css', 'less'])
|
||||
if fsUtils.isFileSync(stylesheetPath)
|
||||
@@ -54,17 +93,17 @@ class ThemeManager
|
||||
else
|
||||
null
|
||||
|
||||
# Public:
|
||||
getImportPaths: ->
|
||||
if @activeThemes.length
|
||||
theme.getStylesheetPath() for theme in @activeThemes when theme.getStylesheetPath
|
||||
if @activeThemes.length > 0
|
||||
themePaths = (theme.getStylesheetsPath() for theme in @activeThemes when theme)
|
||||
else
|
||||
themeNames = config.get('core.themes')
|
||||
themes = []
|
||||
for themeName in themeNames
|
||||
theme = _.find(@registeredTheme, (t) -> t.metadata.name == themeName)
|
||||
themes.push(theme.getStylesheetPath()) if theme?.getStylesheetPath
|
||||
themes
|
||||
themePaths = (path.join(@resolveThemePath(themeName), AtomPackage.stylesheetsDir) for themeName in themeNames)
|
||||
|
||||
themePath for themePath in themePaths when fsUtils.isDirectorySync(themePath)
|
||||
|
||||
# Private:
|
||||
loadUserStylesheet: ->
|
||||
if userStylesheetPath = @getUserStylesheetPath()
|
||||
@userStylesheetPath = userStylesheetPath
|
||||
|
||||
Reference in New Issue
Block a user