Support requiring stylesheets without an extension

Stylesheets will attempt to be resolved with both css
and less extensions if no extension is included in the
path specified to requireStylesheet().
This commit is contained in:
Kevin Sawicki
2013-03-25 23:34:51 -04:00
parent 844f5343c2
commit fab5842651
3 changed files with 32 additions and 11 deletions

View File

@@ -24,14 +24,14 @@ window.setUpEnvironment = ->
$(document).on 'keydown', keymap.handleKeyEvent
keymap.bindDefaultKeys()
requireStylesheet 'reset.less'
requireStylesheet 'atom.less'
requireStylesheet 'overlay.less'
requireStylesheet 'popover-list.less'
requireStylesheet 'notification.less'
requireStylesheet 'markdown.less'
requireStylesheet 'reset'
requireStylesheet 'atom'
requireStylesheet 'overlay'
requireStylesheet 'popover-list'
requireStylesheet 'notification'
requireStylesheet 'markdown'
if nativeStylesheetPath = fs.resolveOnLoadPath("#{process.platform}.css")
if nativeStylesheetPath = fs.resolveOnLoadPath(process.platform, ['css', 'less'])
requireStylesheet(nativeStylesheetPath)
# This method is only called when opening a real application window
@@ -111,8 +111,14 @@ window.deserializeWindowState = ->
window.stylesheetElementForId = (id) ->
$("head style[id='#{id}']")
window.resolveStylesheet = (path) ->
if fs.extension(path).length > 0
fs.resolveOnLoadPath(path)
else
fs.resolveOnLoadPath(path, ['css', 'less'])
window.requireStylesheet = (path) ->
if fullPath = require.resolve(path)
if fullPath = window.resolveStylesheet(path)
content = window.loadStylesheet(fullPath)
window.applyStylesheet(fullPath, content)
else
@@ -128,7 +134,7 @@ window.loadStylesheet = (path) ->
content
window.removeStylesheet = (path) ->
unless fullPath = require.resolve(path)
unless fullPath = window.resolveStylesheet(path)
throw new Error("Could not find a file at path '#{path}'")
window.stylesheetElementForId(fullPath).remove()