mirror of
https://github.com/atom/atom.git
synced 2026-01-23 22:08:08 -05:00
Load stylesheets from package stylesheets directory
This commit is contained in:
@@ -2,13 +2,23 @@ RootView = require 'root-view'
|
||||
|
||||
describe "the `atom` global", ->
|
||||
describe ".loadPackage(name)", ->
|
||||
extension = null
|
||||
[extension, stylesheetPath] = []
|
||||
|
||||
beforeEach ->
|
||||
rootView = new RootView
|
||||
extension = require "package-with-module"
|
||||
stylesheetPath = require.resolve("fixtures/packages/package-with-module/stylesheets/styles.css")
|
||||
|
||||
afterEach ->
|
||||
removeStylesheet(stylesheetPath)
|
||||
|
||||
it "requires and activates the package's main module if it exists", ->
|
||||
spyOn(rootView, 'activatePackage').andCallThrough()
|
||||
atom.loadPackage("package-with-module")
|
||||
expect(rootView.activatePackage).toHaveBeenCalledWith(extension)
|
||||
|
||||
it "loads stylesheets associated with the package", ->
|
||||
stylesheetPath = require.resolve("fixtures/packages/package-with-module/stylesheets/styles.css")
|
||||
expect(stylesheetElementForId(stylesheetPath).length).toBe 0
|
||||
atom.loadPackage("package-with-module")
|
||||
expect(stylesheetElementForId(stylesheetPath).length).toBe 1
|
||||
|
||||
0
spec/fixtures/packages/package-with-module/stylesheets/styles.css
vendored
Normal file
0
spec/fixtures/packages/package-with-module/stylesheets/styles.css
vendored
Normal file
@@ -10,8 +10,9 @@ class AtomPackage extends Package
|
||||
|
||||
load: ->
|
||||
try
|
||||
rootView.activatePackage(@module)
|
||||
@loadKeymaps()
|
||||
@loadStylesheets()
|
||||
rootView.activatePackage(@module)
|
||||
catch e
|
||||
console.error "Failed to load package named '#{@name}'", e.stack
|
||||
|
||||
@@ -25,3 +26,14 @@ class AtomPackage extends Package
|
||||
fs.list keymapsDirPath
|
||||
else
|
||||
[]
|
||||
|
||||
loadStylesheets: ->
|
||||
for stylesheetPath in @getStylesheetPaths()
|
||||
requireStylesheet(stylesheetPath)
|
||||
|
||||
getStylesheetPaths: ->
|
||||
stylesheetDirPath = fs.join(@path, 'stylesheets')
|
||||
if fs.exists stylesheetDirPath
|
||||
fs.list stylesheetDirPath
|
||||
else
|
||||
[]
|
||||
|
||||
@@ -61,6 +61,9 @@ windowAdditions =
|
||||
@_handleKeyEvent = (e) => @keymap.handleKeyEvent(e)
|
||||
$(document).on 'keydown', @_handleKeyEvent
|
||||
|
||||
stylesheetElementForId: (id) ->
|
||||
$("head style[id='#{id}']")
|
||||
|
||||
requireStylesheet: (path) ->
|
||||
unless fullPath = require.resolve(path)
|
||||
throw new Error("Could not find a file at path '#{path}'")
|
||||
@@ -69,10 +72,10 @@ windowAdditions =
|
||||
removeStylesheet: (path) ->
|
||||
unless fullPath = require.resolve(path)
|
||||
throw new Error("Could not find a file at path '#{path}'")
|
||||
$("head style[id='#{fullPath}']").remove()
|
||||
window.stylesheetElementForId(fullPath).remove()
|
||||
|
||||
applyStylesheet: (id, text) ->
|
||||
unless $("head style[id='#{id}']").length
|
||||
unless window.stylesheetElementForId(id).length
|
||||
$('head').append "<style id='#{id}'>#{text}</style>"
|
||||
|
||||
reload: ->
|
||||
|
||||
Reference in New Issue
Block a user