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.
This commit is contained in:
Chris Eppstein 2010-08-28 23:16:08 -07:00
parent f44e1ea492
commit 52c47d7de4
4 changed files with 51 additions and 19 deletions

View File

@ -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

View File

@ -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

View File

@ -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}"

2
lib/rails/init.rb Normal file
View File

@ -0,0 +1,2 @@
require 'compass'
require 'compass/app_integration/rails'