Move public stylesheet related methods off of atom.themes

* Move atom.themes.getUserStylesheetPath to 
  atom.styles.getUserStyleSheetPath
* Deprecate atom.themes.requireStylesheet
This commit is contained in:
Nathan Sobo 2014-11-19 10:31:03 -07:00
parent be7111f007
commit 49471070a3
4 changed files with 25 additions and 16 deletions

View File

@ -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()

View File

@ -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')

View File

@ -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, '/')

View File

@ -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'