diff --git a/package.json b/package.json index afcb1d89d..c2b7658d5 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/less-compile-cache.coffee b/src/less-compile-cache.coffee new file mode 100644 index 000000000..3485e4c44 --- /dev/null +++ b/src/less-compile-cache.coffee @@ -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() diff --git a/src/window.coffee b/src/window.coffee index ecf8100c8..e238d5115 100644 --- a/src/window.coffee +++ b/src/window.coffee @@ -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}