From 30e01c7cbd543eeff28f0f3051ffe7437edf455e Mon Sep 17 00:00:00 2001 From: Chris Eppstein Date: Fri, 22 Apr 2011 09:43:49 -0700 Subject: [PATCH] Clean up the creation and management of importers and compilers --- lib/compass/commands/update_project.rb | 15 ++++++++-- lib/compass/commands/watch_project.rb | 41 ++++++++++++-------------- lib/compass/compiler.rb | 4 +-- lib/compass/configuration/adapters.rb | 8 +++-- 4 files changed, 39 insertions(+), 29 deletions(-) diff --git a/lib/compass/commands/update_project.rb b/lib/compass/commands/update_project.rb index c451db1d..b98fa93a 100644 --- a/lib/compass/commands/update_project.rb +++ b/lib/compass/commands/update_project.rb @@ -59,10 +59,18 @@ module Compass compiler_opts end - Compass::Compiler.new(working_path, + @memory_store ||= Sass::CacheStores::Memory.new + @backing_store ||= compiler_opts[:cache_store] + @backing_store ||= Sass::CacheStores::Filesystem.new(determine_cache_location) + @cache_store ||= Sass::CacheStores::Chain.new(@memory_store, @backing_store) + @memory_store.reset! + + Compass::Compiler.new( + working_path, Compass.configuration.sass_path, Compass.configuration.css_path, - @compiler_opts.merge(additional_options)) + @compiler_opts.merge(:cache_store => @cache_store).merge(additional_options) + ) end def explicit_sass_files @@ -76,6 +84,9 @@ module Compass end end + def determine_cache_location + Compass.configuration.cache_path || Sass::Plugin.options[:cache_location] || File.join(working_path, ".sass-cache") + end class << self def option_parser(arguments) diff --git a/lib/compass/commands/watch_project.rb b/lib/compass/commands/watch_project.rb index 4fcaea8e..a2861c5b 100644 --- a/lib/compass/commands/watch_project.rb +++ b/lib/compass/commands/watch_project.rb @@ -2,6 +2,7 @@ require 'fileutils' require 'pathname' require 'compass/commands/base' require 'compass/commands/update_project' +require 'sass/plugin' module Compass module Commands @@ -33,16 +34,18 @@ module Compass GC.start sleep options.fetch(:gc_pause, 1) count = ObjectSpace.each_object(type) do |obj| - if @@runs > 2 - if options.fetch(:verbose, true) && !@@object_id_tracker[type].include?(obj.object_id) - begin - puts obj.inspect - rescue + if options.fetch(:verbose, true) + if @@runs > 2 + if !@@object_id_tracker[type].include?(obj.object_id) + begin + puts obj.inspect + rescue + end + puts "#{obj.class.name}:#{obj.object_id}" end - puts "#{obj.class.name}:#{obj.object_id}" end + @@object_id_tracker[type] << obj.object_id end - @@object_id_tracker[type] << obj.object_id end puts "#{type}: #{count} instances." end @@ -61,19 +64,6 @@ module Compass exit 0 end - unless Compass.sass_engine_options[:cache_store] - @memory_cache = Sass::CacheStores::Memory.new - Compass.configuration.sass_options ||= {} - Sass::CacheStores::Chain.new( - @memory_cache, - Sass::CacheStores::Filesystem.new( - Compass.sass_engine_options[:cache_location] || - Sass::Engine::DEFAULT_OPTIONS[:cache_location] - ) - ) - - end - check_for_sass_files!(new_compiler_instance) recompile @@ -92,8 +82,10 @@ module Compass puts ">>> Compass is #{action} for changes. Press Ctrl-C to Stop." + begin FSSM.monitor do |monitor| Compass.configuration.sass_load_paths.each do |load_path| + load_path = load_path.root if load_path.respond_to?(:root) next unless load_path.is_a? String monitor.path load_path do |path| path.glob '**/*.s[ac]ss' @@ -122,7 +114,12 @@ module Compass end end - + rescue FSSM::CallbackError => e + # FSSM catches exit? WTF. + if e.message =~ /exit/ + exit + end + end end def remove_obsolete_css(base = nil, relative = nil) @@ -143,7 +140,7 @@ module Compass begin puts ">>> Change detected to: #{relative}" compiler.run - # report_on_instances(Sass::Importers::Base, :verbose => false) + report_on_instances(Sass::Importers::Base, :verbose => false) rescue StandardError => e ::Compass::Exec::Helpers.report_error(e, options) end diff --git a/lib/compass/compiler.rb b/lib/compass/compiler.rb index a611f6ef..92ca8fa6 100644 --- a/lib/compass/compiler.rb +++ b/lib/compass/compiler.rb @@ -11,9 +11,7 @@ module Compass self.logger = options.delete(:logger) self.options = options self.options[:cache_location] ||= determine_cache_location - Compass.configure_sass_plugin! - - self.options[:importer] = self.importer = Sass::Importers::Filesystem.new(from) + options[:importer] = self.importer = Sass::Importers::Filesystem.new(from) self.staleness_checker = Sass::Plugin::StalenessChecker.new(options) end diff --git a/lib/compass/configuration/adapters.rb b/lib/compass/configuration/adapters.rb index 3ae9149b..9897f321 100644 --- a/lib/compass/configuration/adapters.rb +++ b/lib/compass/configuration/adapters.rb @@ -55,10 +55,14 @@ module Compass def sass_load_paths load_paths = [] load_paths << sass_path if sass_path - Compass::Frameworks::ALL.each do |framework| - load_paths << framework.stylesheets_directory if File.exists?(framework.stylesheets_directory) + Compass::Frameworks::ALL.each do |f| + load_paths << f.stylesheets_directory if File.directory?(f.stylesheets_directory) end load_paths += resolve_additional_import_paths + load_paths.map! do |p| + next p if p.respond_to?(:find_relative) + Sass::Importers::Filesystem.new(p.to_s) + end load_paths << Compass::Sprites.new load_paths end