diff --git a/spec/app/window-spec.coffee b/spec/app/window-spec.coffee index 7b93a6f9b..0615cdc91 100644 --- a/spec/app/window-spec.coffee +++ b/spec/app/window-spec.coffee @@ -94,7 +94,7 @@ describe "Window", -> $('head style[id*="css.css"]').remove() - it "synchronously loads and parses less files at the given path and installs a style tag for it in the head", -> + it "synchronously loads and parses less files at the given path and installs a style tag for it in the head", -> lessPath = project.resolve('sample.less') lengthBefore = $('head style').length requireStylesheet(lessPath) @@ -117,7 +117,16 @@ describe "Window", -> expect($('head style').length).toBe lengthBefore + 1 $('head style[id*="sample.less"]').remove() - describe ".disableStyleSheet(path)", -> + it "supports requiring css and less stylesheets without an explicit extension", -> + requireStylesheet 'fixtures/css' + expect($('head style[id*="css.css"]').attr('id')).toBe project.resolve('css.css') + requireStylesheet 'fixtures/sample' + expect($('head style[id*="sample.less"]').attr('id')).toBe project.resolve('sample.less') + + $('head style[id*="css.css"]').remove() + $('head style[id*="sample.less"]').remove() + + describe ".removeStylesheet(path)", -> it "removes styling applied by given stylesheet path", -> cssPath = require.resolve(fs.join("fixtures", "css.css")) diff --git a/src/app/window.coffee b/src/app/window.coffee index 8c186b438..a2056a672 100644 --- a/src/app/window.coffee +++ b/src/app/window.coffee @@ -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() diff --git a/src/stdlib/fs-utils.coffee b/src/stdlib/fs-utils.coffee index 5a912717c..1acf41169 100644 --- a/src/stdlib/fs-utils.coffee +++ b/src/stdlib/fs-utils.coffee @@ -218,6 +218,12 @@ module.exports = pathToResolve = args.pop() loadPaths = args + if pathToResolve[0] is '/' + if extensions and resolvedPath = @resolveExtension(pathToResolve, extensions) + return resolvedPath + else + return pathToResolve if @exists(pathToResolve) + for loadPath in loadPaths candidatePath = @join(loadPath, pathToResolve) if extensions