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,9 +23,11 @@ module Compass
directory File.dirname(config_file)
write_file config_file, config_contents
end
unless rails3?
directory File.dirname(targetize('config/initializers/compass.rb'))
write_file targetize('config/initializers/compass.rb'), initializer_contents
end
end
def rails3?
File.exists?(targetize('config/application.rb'))
@ -73,6 +75,9 @@ NEXTSTEPS
end
def prompt_sass_dir
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}
@ -81,8 +86,12 @@ NEXTSTEPS
answer = $stdin.gets.downcase[0]
answer == ?n ? default_location : recommended_location
end
end
def prompt_css_dir
if rails3?
nil
else
recommended_location = separate("public/stylesheets/compiled")
default_location = separate("public/stylesheets")
puts
@ -94,6 +103,7 @@ NEXTSTEPS
answer = answer.downcase[0]
answer == ?n ? default_location : recommended_location
end
end
def config_contents
"# This configuration file works with both the Compass command line tool and within Rails.\n" +

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'