diff --git a/spec/app/window-spec.coffee b/spec/app/window-spec.coffee index 12f79248f..0ae136754 100644 --- a/spec/app/window-spec.coffee +++ b/spec/app/window-spec.coffee @@ -1,5 +1,6 @@ $ = require 'jquery' fs = require 'fs' +{less} = require 'less' describe "Window", -> projectPath = null @@ -78,6 +79,25 @@ describe "Window", -> requireStylesheet('atom.css') expect($('head style').length).toBe lengthBefore + 1 + it "synchronously loads and parses less files at the given path and installs a style tag for it in the head", -> + $('head style[id*="markdown.less"]').remove() + lengthBefore = $('head style').length + requireStylesheet('markdown.less') + expect($('head style').length).toBe lengthBefore + 1 + + styleElt = $('head style[id*="markdown.less"]') + + fullPath = require.resolve('markdown.less') + expect(styleElt.attr('id')).toBe fullPath + + (new less.Parser).parse __read(fullPath), (e, tree) -> + throw new Error(e.message, file, e.line) if e + expect(styleElt.text()).toBe tree.toCSS() + + # doesn't append twice + requireStylesheet('markdown.less') + expect($('head style').length).toBe lengthBefore + 1 + describe ".disableStyleSheet(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 321a60f56..3fafdd953 100644 --- a/src/app/window.coffee +++ b/src/app/window.coffee @@ -1,6 +1,7 @@ fs = require 'fs' $ = require 'jquery' ChildProcess = require 'child-process' +{less} = require 'less' require 'jquery-extensions' require 'underscore-extensions' require 'space-pen-extensions' @@ -33,7 +34,7 @@ window.setUpEnvironment = -> requireStylesheet 'overlay.css' requireStylesheet 'popover-list.css' requireStylesheet 'notification.css' - requireStylesheet 'markdown.css' + requireStylesheet 'markdown.less' if nativeStylesheetPath = require.resolve("#{platform}.css") requireStylesheet(nativeStylesheetPath) @@ -114,8 +115,17 @@ window.stylesheetElementForId = (id) -> $("head style[id='#{id}']") window.requireStylesheet = (path) -> + console.log path if fullPath = require.resolve(path) - window.applyStylesheet(fullPath, fs.read(fullPath)) + content = "" + if fs.extension(fullPath) == '.less' + (new less.Parser).parse __read(fullPath), (e, tree) -> + throw new Error(e.message, file, e.line) if e + content = tree.toCSS() + else + content = fs.read(fullPath) + + window.applyStylesheet(fullPath, content) unless fullPath throw new Error("Could not find a file at path '#{path}'")