Get the proper directories before themeManage load

This commit is contained in:
Ben Ogle
2013-09-03 12:22:32 -07:00
parent a9c4b23563
commit 9c5c05ff41
3 changed files with 38 additions and 5 deletions

View File

@@ -12,6 +12,28 @@ describe "ThemeManager", ->
afterEach ->
themeManager.unload()
describe "getImportPaths()", ->
it "returns the theme directories before the themes are loaded", ->
config.set('core.themes', ['atom-dark-syntax', 'atom-dark-ui', 'atom-light-ui'])
paths = themeManager.getImportPaths()
# syntax theme is not a dir at this time, so only two.
expect(paths.length).toBe 2
expect(paths[0]).toContain 'atom-dark-ui'
expect(paths[1]).toContain 'atom-light-ui'
it "returns the theme directories before the themes are loaded", ->
config.set('core.themes', ['atom-dark-syntax', 'atom-dark-ui', 'atom-light-ui'])
themeManager.load()
paths = themeManager.getImportPaths()
# syntax theme is not a dir at this time, so only two.
expect(paths.length).toBe 2
expect(paths[0]).toContain 'atom-dark-ui'
expect(paths[1]).toContain 'atom-light-ui'
describe "when the core.themes config value changes", ->
it "add/removes stylesheets to reflect the new config value", ->
themeManager.on 'reloaded', reloadHandler = jasmine.createSpy()

View File

@@ -50,7 +50,15 @@ class ThemeManager
null
getImportPaths: ->
theme.directoryPath for theme in @loadedThemes when theme.directoryPath
if @loadedThemes.length
theme.directoryPath for theme in @loadedThemes when theme.directoryPath
else
themeNames = config.get('core.themes')
themes = []
for themeName in themeNames
themePath = Theme.resolve(themeName)
themes.push(themePath) if fsUtils.isDirectorySync(themePath)
themes
loadUserStylesheet: ->
if userStylesheetPath = @getUserStylesheetPath()

View File

@@ -8,12 +8,15 @@ class Theme
stylesheetPath: null
stylesheets: null
@resolve: (themeName) ->
if fsUtils.exists(themeName)
themeName
else
fsUtils.resolve(config.themeDirPaths..., themeName, ['', '.css', 'less'])
constructor: (name) ->
@stylesheets = []
if fsUtils.exists(name)
@stylesheetPath = name
else
@stylesheetPath = fsUtils.resolve(config.themeDirPaths..., name, ['', '.css', 'less'])
@stylesheetPath = Theme.resolve(name)
throw new Error("No theme exists named '#{name}'") unless @stylesheetPath