mirror of
https://github.com/atom/atom.git
synced 2026-01-23 05:48:10 -05:00
move less parsing to requireStylesheet
This commit is contained in:
committed by
Corey Johnson
parent
0b674978db
commit
b502c811cb
@@ -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"))
|
||||
|
||||
@@ -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}'")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user