From 49471070a329e11433d107ab05bbed503e4e063e Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Wed, 19 Nov 2014 10:31:03 -0700 Subject: [PATCH] Move public stylesheet related methods off of atom.themes * Move atom.themes.getUserStylesheetPath to atom.styles.getUserStyleSheetPath * Deprecate atom.themes.requireStylesheet --- spec/theme-manager-spec.coffee | 4 ++-- src/style-manager.coffee | 16 ++++++++++++++++ src/theme-manager.coffee | 19 ++++++------------- src/workspace.coffee | 2 +- 4 files changed, 25 insertions(+), 16 deletions(-) diff --git a/spec/theme-manager-spec.coffee b/spec/theme-manager-spec.coffee index 70a01c213..d99633d57 100644 --- a/spec/theme-manager-spec.coffee +++ b/spec/theme-manager-spec.coffee @@ -70,7 +70,7 @@ describe "ThemeManager", -> describe "when the core.themes config value changes", -> it "add/removes stylesheets to reflect the new config value", -> themeManager.onDidReloadAll reloadHandler = jasmine.createSpy() - spyOn(themeManager, 'getUserStylesheetPath').andCallFake -> null + spyOn(atom.styles, 'getUserStyleSheetPath').andCallFake -> null waitsForPromise -> themeManager.activateThemes() @@ -268,7 +268,7 @@ describe "ThemeManager", -> [stylesheetRemovedHandler, stylesheetAddedHandler, stylesheetsChangedHandler] = [] userStylesheetPath = path.join(temp.mkdirSync("atom"), 'styles.less') fs.writeFileSync(userStylesheetPath, 'body {border-style: dotted !important;}') - spyOn(themeManager, 'getUserStylesheetPath').andReturn userStylesheetPath + spyOn(atom.styles, 'getUserStyleSheetPath').andReturn userStylesheetPath waitsForPromise -> themeManager.activateThemes() diff --git a/src/style-manager.coffee b/src/style-manager.coffee index d83a72075..f9d6aa373 100644 --- a/src/style-manager.coffee +++ b/src/style-manager.coffee @@ -1,3 +1,5 @@ +fs = require 'fs-plus' +path = require 'path' {Emitter, Disposable} = require 'event-kit' # Extended: A singleton instance of this class available via `atom.styles`, @@ -149,3 +151,17 @@ class StyleManager existingStyleElements = @getStyleElements() for styleElement in styleElementsToRestore @addStyleElement(styleElement) unless styleElement in existingStyleElements + + ### + Section: Paths + ### + + # Extended: Get the path of the user style sheet in `~/.atom`. + # + # Returns a {String}. + getUserStyleSheetPath: -> + stylesheetPath = fs.resolve(path.join(atom.getConfigDirPath(), 'styles'), ['css', 'less']) + if fs.isFileSync(stylesheetPath) + stylesheetPath + else + path.join(atom.getConfigDirPath(), 'styles.less') diff --git a/src/theme-manager.coffee b/src/theme-manager.coffee index 70dce8ef0..3bdb15573 100644 --- a/src/theme-manager.coffee +++ b/src/theme-manager.coffee @@ -202,18 +202,15 @@ class ThemeManager atom.config.set('core.themes', enabledThemeNames) ### - Section: Managing Stylesheets + Section: Private ### - # Public: Returns the {String} path to the user's stylesheet under ~/.atom + # Returns the {String} path to the user's stylesheet under ~/.atom getUserStylesheetPath: -> - stylesheetPath = fs.resolve(path.join(@configDirPath, 'styles'), ['css', 'less']) - if fs.isFileSync(stylesheetPath) - stylesheetPath - else - path.join(@configDirPath, 'styles.less') + Grim.deprecate("Call atom.styles.getUserStyleSheetPath() instead") + atom.styles.getUserStyleSheetPath() - # Public: Resolve and apply the stylesheet specified by the path. + # Resolve and apply the stylesheet specified by the path. # # This supports both CSS and Less stylsheets. # @@ -236,7 +233,7 @@ class ThemeManager loadUserStylesheet: -> @unwatchUserStylesheet() - userStylesheetPath = @getUserStylesheetPath() + userStylesheetPath = atom.styles.getUserStyleSheetPath() return unless fs.isFileSync(userStylesheetPath) @userStylesheetPath = userStylesheetPath @@ -297,10 +294,6 @@ class ThemeManager applyStylesheet: (path, text, type='bundled') -> @styleSheetDisposablesBySourcePath[path] = atom.styles.addStyleSheet(text, sourcePath: path, group: type) - ### - Section: Private - ### - stringToId: (string) -> string.replace(/\\/g, '/') diff --git a/src/workspace.coffee b/src/workspace.coffee index 843827d59..20b46a4d5 100644 --- a/src/workspace.coffee +++ b/src/workspace.coffee @@ -61,7 +61,7 @@ class Workspace extends Model @addOpener (filePath) => switch filePath when 'atom://.atom/stylesheet' - @open(atom.themes.getUserStylesheetPath()) + @open(atom.styles.getUserStyleSheetPath()) when 'atom://.atom/keymap' @open(atom.keymaps.getUserKeymapPath()) when 'atom://.atom/config'