From 9c5c05ff41c477bcbb60485df1b6f98a531f1406 Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Tue, 3 Sep 2013 12:22:32 -0700 Subject: [PATCH] Get the proper directories before themeManage load --- spec/theme-manager-spec.coffee | 22 ++++++++++++++++++++++ src/theme-manager.coffee | 10 +++++++++- src/theme.coffee | 11 +++++++---- 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/spec/theme-manager-spec.coffee b/spec/theme-manager-spec.coffee index 77bd56635..e734d1886 100644 --- a/spec/theme-manager-spec.coffee +++ b/spec/theme-manager-spec.coffee @@ -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() diff --git a/src/theme-manager.coffee b/src/theme-manager.coffee index 12a7c4485..71de7295a 100644 --- a/src/theme-manager.coffee +++ b/src/theme-manager.coffee @@ -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() diff --git a/src/theme.coffee b/src/theme.coffee index 4688f07bd..a4af012d9 100644 --- a/src/theme.coffee +++ b/src/theme.coffee @@ -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