Break out window.applyStylesheet from window.requireStylesheet

This will be useful in applying generated stylesheets associated with themes.
This commit is contained in:
Nathan Sobo
2012-08-08 16:09:23 -06:00
parent 3376dead06
commit 2df05e235a
2 changed files with 8 additions and 6 deletions

View File

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

View File

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