mirror of
https://github.com/atom/atom.git
synced 2026-01-22 13:28:01 -05:00
Cache compiled LESS files
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
"jasmine-focused": "~0.12.0",
|
||||
"mkdirp": "0.3.5",
|
||||
"less": "git://github.com/nathansobo/less.js.git",
|
||||
"less-cache": "0.5.0",
|
||||
"nak": "0.2.18",
|
||||
"nslog": "0.1.0",
|
||||
"oniguruma": "0.20.0",
|
||||
|
||||
21
src/less-compile-cache.coffee
Normal file
21
src/less-compile-cache.coffee
Normal file
@@ -0,0 +1,21 @@
|
||||
_ = require 'underscore'
|
||||
LessCache = require 'less-cache'
|
||||
|
||||
module.exports =
|
||||
class LessCompileCache
|
||||
_.extend @prototype, require('subscriber')
|
||||
|
||||
@cacheDir: '/tmp/atom-compile-cache/less'
|
||||
|
||||
constructor: ->
|
||||
importPaths =
|
||||
@cache = new LessCache
|
||||
cacheDir: @constructor.cacheDir
|
||||
importPaths: @getImportPaths()
|
||||
@subscribe atom.themes, 'reloaded', => @cache.setImportPaths(@getImportPaths())
|
||||
|
||||
getImportPaths: -> atom.themes.getImportPaths().concat(config.lessSearchPaths)
|
||||
|
||||
read: (stylesheetPath) -> @cache.readFileSync(stylesheetPath)
|
||||
|
||||
destroy: -> @unsubscribe()
|
||||
@@ -3,7 +3,6 @@ path = require 'path'
|
||||
telepath = require 'telepath'
|
||||
$ = require 'jquery'
|
||||
_ = require 'underscore'
|
||||
less = require 'less'
|
||||
remote = require 'remote'
|
||||
ipc = require 'ipc'
|
||||
WindowEventHandler = require 'window-event-handler'
|
||||
@@ -14,6 +13,7 @@ require 'space-pen-extensions'
|
||||
deserializers = {}
|
||||
deferredDeserializers = {}
|
||||
defaultWindowDimensions = {width: 800, height: 600}
|
||||
lessCache = null
|
||||
|
||||
### Internal ###
|
||||
|
||||
@@ -80,6 +80,7 @@ window.unloadEditorWindow = ->
|
||||
rootView.remove()
|
||||
project.destroy()
|
||||
windowEventHandler?.unsubscribe()
|
||||
lessCache?.destroy()
|
||||
window.rootView = null
|
||||
window.project = null
|
||||
|
||||
@@ -153,18 +154,12 @@ window.loadStylesheet = (stylesheetPath) ->
|
||||
fsUtils.read(stylesheetPath)
|
||||
|
||||
window.loadLessStylesheet = (lessStylesheetPath) ->
|
||||
importPaths = atom.themes.getImportPaths()
|
||||
parser = new less.Parser
|
||||
syncImport: true
|
||||
paths: importPaths.concat(config.lessSearchPaths)
|
||||
filename: lessStylesheetPath
|
||||
unless lessCache?
|
||||
LessCompileCache = require 'less-compile-cache'
|
||||
lessCache = new LessCompileCache()
|
||||
|
||||
try
|
||||
content = null
|
||||
parser.parse fsUtils.read(lessStylesheetPath), (e, tree) ->
|
||||
throw e if e?
|
||||
content = tree.toCSS()
|
||||
content
|
||||
lessCache.read(lessStylesheetPath)
|
||||
catch e
|
||||
console.error """
|
||||
Error compiling less stylesheet: #{lessStylesheetPath}
|
||||
|
||||
Reference in New Issue
Block a user