From 7a6c75a83ea653a2a90e28af7cbb8c7db0284bf3 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 21 Nov 2013 17:44:57 -0800 Subject: [PATCH] Refresh cache when core.themes changes Previously this wasn't needed because a new cache was created for each stylesheet loaded. --- src/less-compile-cache.coffee | 14 +++++++++----- src/theme-manager.coffee | 7 ++++++- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/less-compile-cache.coffee b/src/less-compile-cache.coffee index ac965b4f5..935f53339 100644 --- a/src/less-compile-cache.coffee +++ b/src/less-compile-cache.coffee @@ -11,21 +11,25 @@ class LessCompileCache @cacheDir: path.join(tmpDir, 'atom-compile-cache', 'less') - constructor: ({resourcePath}) -> + constructor: ({resourcePath, importPaths}) -> @lessSearchPaths = [ path.join(resourcePath, 'static', 'variables') path.join(resourcePath, 'static') ] + if importPaths? + importPaths = importPaths.concat(@lessSearchPaths) + else + importPaths = @lessSearchPaths + @cache = new LessCache cacheDir: @constructor.cacheDir - importPaths: @getImportPaths() + importPaths: importPaths resourcePath: resourcePath fallbackDir: path.join(resourcePath, 'less-compile-cache') - @subscribe atom.themes, 'reloaded', => @cache.setImportPaths(@getImportPaths()) - - getImportPaths: -> atom.themes.getImportPaths().concat(@lessSearchPaths) + setImportPaths: (importPaths=[]) -> + @cache.setImportPaths(importPaths.concat(@lessSearchPaths)) read: (stylesheetPath) -> @cache.readFileSync(stylesheetPath) diff --git a/src/theme-manager.coffee b/src/theme-manager.coffee index 3e6f75d70..aedffae3a 100644 --- a/src/theme-manager.coffee +++ b/src/theme-manager.coffee @@ -56,6 +56,7 @@ class ThemeManager themeNames = _.clone(themeNames).reverse() @packageManager.activatePackage(themeName) for themeName in themeNames + @refreshLessCache() @loadUserStylesheet() @reloadBaseStylesheets() @emit('reloaded') @@ -66,6 +67,10 @@ class ThemeManager @packageManager.deactivatePackage(pack.name) for pack in @getActiveThemes() null + # Internal-only: + refreshLessCache: -> + @lessCache?.setImportPaths(@getImportPaths()) + # Public: Set the list of enabled themes. # # * enabledThemeNames: An {Array} of {String} theme names. @@ -148,7 +153,7 @@ class ThemeManager loadLessStylesheet: (lessStylesheetPath) -> unless @lessCache? LessCompileCache = require './less-compile-cache' - @lessCache = new LessCompileCache({@resourcePath}) + @lessCache = new LessCompileCache({@resourcePath, importPaths: @getImportPaths()}) try @lessCache.read(lessStylesheetPath)