From 8172fce22a58ccc523f3a789b99e5bbed49da11e Mon Sep 17 00:00:00 2001 From: Chris Eppstein Date: Sat, 13 Feb 2010 17:07:34 -0800 Subject: [PATCH] [Rails] Fix a setup bug and handle compass configuration changes at rails boot. Existing rails projects should change their compass initializer file to: require 'compass' rails_root = (defined?(Rails) ? Rails.root : RAILS_ROOT).to_s Compass.add_project_configuration(File.join(rails_root, "config", "compass.rb")) Compass.configure_sass_plugin! Compass.handle_configuration_change! --- lib/compass/app_integration/rails.rb | 6 ++++++ lib/compass/app_integration/rails/installer.rb | 13 ++++++++----- lib/compass/configuration/inheritance.rb | 8 ++++++-- lib/compass/configuration/serialization.rb | 2 +- 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/lib/compass/app_integration/rails.rb b/lib/compass/app_integration/rails.rb index 668fbd42..0e5c6a84 100644 --- a/lib/compass/app_integration/rails.rb +++ b/lib/compass/app_integration/rails.rb @@ -20,6 +20,12 @@ module Compass extend(ConfigurationDefaults) end + def env + if rails_env = (defined?(::Rails) ? ::Rails.env : (defined?(RAILS_ENV) ? RAILS_ENV : nil)) + rails_env.production? ? :production : :development + end + end + end end end diff --git a/lib/compass/app_integration/rails/installer.rb b/lib/compass/app_integration/rails/installer.rb index a81e2469..41072844 100644 --- a/lib/compass/app_integration/rails/installer.rb +++ b/lib/compass/app_integration/rails/installer.rb @@ -80,9 +80,12 @@ module Compass end def config_contents + "# This configuration file works with both the Compass command line tool and within Rails.\n" + Compass.configuration.serialize do |prop, value| if prop == :project_path "project_path = RAILS_ROOT if defined?(RAILS_ROOT)\n" + elsif prop == :environment + "environment = Compass::AppIntegration::Rails.env\n" elsif prop == :output_style "" end @@ -91,11 +94,11 @@ module Compass def initializer_contents %Q{require 'compass' - # If you have any compass plugins, require them here. - Compass.configuration.parse(File.join(RAILS_ROOT, "config", "compass.rb")) - Compass.configuration.environment = (defined?(Rails) ? Rails.env : RAILS_ENV).to_sym - Compass.configure_sass_plugin! - } + |rails_root = (defined?(Rails) ? Rails.root : RAILS_ROOT).to_s + |Compass.add_project_configuration(File.join(rails_root, "config", "compass.rb")) + |Compass.configure_sass_plugin! + |Compass.handle_configuration_change! + |}.gsub(/^\s+\|/,'') end def stylesheet_prefix diff --git a/lib/compass/configuration/inheritance.rb b/lib/compass/configuration/inheritance.rb index 255749c2..18884d3d 100644 --- a/lib/compass/configuration/inheritance.rb +++ b/lib/compass/configuration/inheritance.rb @@ -145,13 +145,17 @@ module Compass end end - def debug + def chain instances = [self] instances << instances.last.inherited_data while instances.last.inherited_data + instances + end + + def debug normalized_attrs = {} ATTRIBUTES.each do |prop| values = [] - instances.each do |instance| + chain.each do |instance| values << { :raw => (instance.send("raw_#{prop}") rescue nil), :value => (instance.send("#{prop}_without_default") rescue nil), diff --git a/lib/compass/configuration/serialization.rb b/lib/compass/configuration/serialization.rb index c4c1fb27..ade505df 100644 --- a/lib/compass/configuration/serialization.rb +++ b/lib/compass/configuration/serialization.rb @@ -73,7 +73,7 @@ module Compass def serialize_property(prop, value) %Q(#{prop} = #{value.inspect}\n) end - + def issue_deprecation_warnings if http_images_path == :relative $stderr.puts "DEPRECATION WARNING: Please set relative_assets = true to enable relative paths."