mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
Break out window.applyStylesheet from window.requireStylesheet
This will be useful in applying generated stylesheets associated with themes.
This commit is contained in:
@@ -32,15 +32,15 @@ describe "Window", ->
|
||||
|
||||
describe "requireStylesheet(path)", ->
|
||||
it "synchronously loads the stylesheet at the given path and installs a style tag for it in the head", ->
|
||||
$('head style[path*="atom.css"]').remove()
|
||||
$('head style[id*="atom.css"]').remove()
|
||||
lengthBefore = $('head style').length
|
||||
requireStylesheet('atom.css')
|
||||
expect($('head style').length).toBe lengthBefore + 1
|
||||
|
||||
styleElt = $('head style[path*="atom.css"]')
|
||||
styleElt = $('head style[id*="atom.css"]')
|
||||
|
||||
fullPath = require.resolve('atom.css')
|
||||
expect(styleElt.attr('path')).toBe fullPath
|
||||
expect(styleElt.attr('id')).toBe fullPath
|
||||
expect(styleElt.text()).toBe fs.read(fullPath)
|
||||
|
||||
# doesn't append twice
|
||||
|
||||
@@ -53,9 +53,11 @@ windowAdditions =
|
||||
|
||||
requireStylesheet: (path) ->
|
||||
fullPath = require.resolve(path)
|
||||
content = fs.read(fullPath)
|
||||
return if $("head style[path='#{fullPath}']").length
|
||||
$('head').append "<style path='#{fullPath}'>#{content}</style>"
|
||||
window.applyStylesheet(fullPath, fs.read(fullPath))
|
||||
|
||||
applyStylesheet: (id, text) ->
|
||||
unless $("head style[id='#{id}']").length
|
||||
$('head').append "<style id='#{id}'>#{text}</style>"
|
||||
|
||||
requireExtension: (name) ->
|
||||
extensionPath = require.resolve name
|
||||
|
||||
Reference in New Issue
Block a user