From 8730638ade5628a13ca74cd510a6ad7f6ed0754e Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Tue, 13 Aug 2013 16:51:21 -0700 Subject: [PATCH] Add directory and ImportPaths paths to themes --- spec/app/theme-manager-spec.coffee | 6 ++++++ spec/app/theme-spec.coffee | 3 +++ src/app/theme-manager.coffee | 3 +++ src/app/theme.coffee | 7 ++++--- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/spec/app/theme-manager-spec.coffee b/spec/app/theme-manager-spec.coffee index e7a2edf00..4863102a0 100644 --- a/spec/app/theme-manager-spec.coffee +++ b/spec/app/theme-manager-spec.coffee @@ -24,6 +24,12 @@ describe "ThemeManager", -> config.set('core.themes', []) expect($('style.userTheme').length).toBe 0 + # atom-dark-ui has an directory path, the syntax ones dont. + config.set('core.themes', ['atom-light-syntax', 'atom-dark-ui', 'atom-dark-syntax']) + importPaths = themeManager.getImportPaths() + expect(importPaths.length).toBe 1 + expect(importPaths[0]).toContain 'atom-dark-ui' + describe "when a theme fails to load", -> it "logs a warning", -> themeManager = new ThemeManager() diff --git a/spec/app/theme-spec.coffee b/spec/app/theme-spec.coffee index 753c12d39..4e1d40a55 100644 --- a/spec/app/theme-spec.coffee +++ b/spec/app/theme-spec.coffee @@ -18,6 +18,7 @@ describe "Theme", -> themePath = project.resolve('themes/theme-stylesheet.css') theme = new Theme(themePath) expect($(".editor").css("padding-top")).toBe "1234px" + expect(theme.directoryPath).not.toBeDefined() it "parses, loads and applies less", -> expect($(".editor").css("padding-bottom")).not.toBe "1234px" @@ -33,6 +34,7 @@ describe "Theme", -> themePath = project.resolve('themes/theme-with-package-file') theme = new Theme(themePath) + expect(theme.directoryPath).toBe themePath expect($(".editor").css("padding-top")).toBe("101px") expect($(".editor").css("padding-right")).toBe("102px") expect($(".editor").css("padding-bottom")).toBe("103px") @@ -45,6 +47,7 @@ describe "Theme", -> themePath = project.resolve('themes/theme-without-package-file') theme = new Theme(themePath) + expect(theme.directoryPath).toBe themePath expect($(".editor").css("padding-top")).toBe "10px" expect($(".editor").css("padding-right")).toBe "20px" expect($(".editor").css("padding-bottom")).toBe "30px" diff --git a/src/app/theme-manager.coffee b/src/app/theme-manager.coffee index f14e6ac7c..ab566745c 100644 --- a/src/app/theme-manager.coffee +++ b/src/app/theme-manager.coffee @@ -40,6 +40,9 @@ class ThemeManager else null + getImportPaths: -> + (theme.directoryPath for theme in @loadedThemes when theme.directoryPath) + loadUserStylesheet: -> if userStylesheetPath = @getUserStylesheetPath() @userStylesheetPath = userStylesheetPath diff --git a/src/app/theme.coffee b/src/app/theme.coffee index 809570d47..4688f07bd 100644 --- a/src/app/theme.coffee +++ b/src/app/theme.coffee @@ -24,11 +24,12 @@ class Theme 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) - stylesheetNames = fsUtils.readObjectSync(metadataPath)?.stylesheets - if stylesheetNames - for name in stylesheetNames + @metadata = fsUtils.readObjectSync(metadataPath) + if @metadata?.stylesheets + for name in @metadata.stylesheets filename = fsUtils.resolveExtension(path.join(@stylesheetPath, name), ['.css', '.less', '']) @loadStylesheet(filename) else