From 52c47d7de4cc4f78e6f40c623c245bbaa11e4060 Mon Sep 17 00:00:00 2001 From: Chris Eppstein Date: Sat, 28 Aug 2010 23:16:08 -0700 Subject: [PATCH] In rails 3, there's no need for an initializer. Instead we use a Railstie. Additionally, we now default to app/stylesheets for sass files and public/stylesheets for css files -- though they can still be changed after installation or on the command line during project initialization. Compass is now a gem plugin in a rails environment. Lastly, in a rails3 environment the compass configuration can now be changed without restarting the rails server process. --- .../rails/actionpack3/railtie.rb | 17 +++++++ .../app_integration/rails/installer.rb | 48 +++++++++++-------- lib/compass/app_integration/rails/runtime.rb | 3 ++ lib/rails/init.rb | 2 + 4 files changed, 51 insertions(+), 19 deletions(-) create mode 100644 lib/compass/app_integration/rails/actionpack3/railtie.rb create mode 100644 lib/rails/init.rb diff --git a/lib/compass/app_integration/rails/actionpack3/railtie.rb b/lib/compass/app_integration/rails/actionpack3/railtie.rb new file mode 100644 index 00000000..f51d5bfd --- /dev/null +++ b/lib/compass/app_integration/rails/actionpack3/railtie.rb @@ -0,0 +1,17 @@ +require 'compass' +require 'rails' +module Compass + class Railtie < Rails::Railtie + config.to_prepare do + # putting this here allows compass to detect + # and adjust to changes to the project configuration + Compass.reset_configuration! + Compass::AppIntegration::Rails.initialize! + end + + # Might need to do this... + # initializer "compass/railtie.configure_rails_initialization" do |app| + # puts "Initializing compass" + # end + end +end \ No newline at end of file diff --git a/lib/compass/app_integration/rails/installer.rb b/lib/compass/app_integration/rails/installer.rb index d6296279..a17bb57b 100644 --- a/lib/compass/app_integration/rails/installer.rb +++ b/lib/compass/app_integration/rails/installer.rb @@ -23,8 +23,10 @@ module Compass directory File.dirname(config_file) write_file config_file, config_contents end - directory File.dirname(targetize('config/initializers/compass.rb')) - write_file targetize('config/initializers/compass.rb'), initializer_contents + unless rails3? + directory File.dirname(targetize('config/initializers/compass.rb')) + write_file targetize('config/initializers/compass.rb'), initializer_contents + end end def rails3? @@ -73,26 +75,34 @@ NEXTSTEPS end def prompt_sass_dir - recommended_location = separate('app/stylesheets') - default_location = separate('public/stylesheets/sass') - print %Q{Compass recommends that you keep your stylesheets in #{recommended_location} - instead of the Sass default location of #{default_location}. - Is this OK? (Y/n) } - answer = $stdin.gets.downcase[0] - answer == ?n ? default_location : recommended_location + if rails3? + nil + else + recommended_location = separate('app/stylesheets') + default_location = separate('public/stylesheets/sass') + print %Q{Compass recommends that you keep your stylesheets in #{recommended_location} + instead of the Sass default location of #{default_location}. + Is this OK? (Y/n) } + answer = $stdin.gets.downcase[0] + answer == ?n ? default_location : recommended_location + end end def prompt_css_dir - recommended_location = separate("public/stylesheets/compiled") - default_location = separate("public/stylesheets") - puts - print %Q{Compass recommends that you keep your compiled css in #{recommended_location}/ - instead the Sass default of #{default_location}/. - However, if you're exclusively using Sass, then #{default_location}/ is recommended. - Emit compiled stylesheets to #{recommended_location}/? (Y/n) } - answer = $stdin.gets - answer = answer.downcase[0] - answer == ?n ? default_location : recommended_location + if rails3? + nil + else + recommended_location = separate("public/stylesheets/compiled") + default_location = separate("public/stylesheets") + puts + print %Q{Compass recommends that you keep your compiled css in #{recommended_location}/ + instead the Sass default of #{default_location}/. + However, if you're exclusively using Sass, then #{default_location}/ is recommended. + Emit compiled stylesheets to #{recommended_location}/? (Y/n) } + answer = $stdin.gets + answer = answer.downcase[0] + answer == ?n ? default_location : recommended_location + end end def config_contents diff --git a/lib/compass/app_integration/rails/runtime.rb b/lib/compass/app_integration/rails/runtime.rb index a3ac8dfa..d2765ef0 100644 --- a/lib/compass/app_integration/rails/runtime.rb +++ b/lib/compass/app_integration/rails/runtime.rb @@ -4,6 +4,9 @@ unless defined?(Compass::RAILS_LOADED) require 'action_pack/version' if ActionPack::VERSION::MAJOR >= 3 # TODO figure something out so image_path works with rails integration + %w(railtie).each do |lib| + require "compass/app_integration/rails/actionpack3/#{lib}" + end else %w(action_controller sass_plugin urls).each do |lib| require "compass/app_integration/rails/actionpack2/#{lib}" diff --git a/lib/rails/init.rb b/lib/rails/init.rb new file mode 100644 index 00000000..7600ef54 --- /dev/null +++ b/lib/rails/init.rb @@ -0,0 +1,2 @@ +require 'compass' +require 'compass/app_integration/rails'