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:
parent
f44e1ea492
commit
52c47d7de4
17
lib/compass/app_integration/rails/actionpack3/railtie.rb
Normal file
17
lib/compass/app_integration/rails/actionpack3/railtie.rb
Normal 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
|
@ -23,9 +23,11 @@ module Compass
|
|||||||
directory File.dirname(config_file)
|
directory File.dirname(config_file)
|
||||||
write_file config_file, config_contents
|
write_file config_file, config_contents
|
||||||
end
|
end
|
||||||
|
unless rails3?
|
||||||
directory File.dirname(targetize('config/initializers/compass.rb'))
|
directory File.dirname(targetize('config/initializers/compass.rb'))
|
||||||
write_file targetize('config/initializers/compass.rb'), initializer_contents
|
write_file targetize('config/initializers/compass.rb'), initializer_contents
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def rails3?
|
def rails3?
|
||||||
File.exists?(targetize('config/application.rb'))
|
File.exists?(targetize('config/application.rb'))
|
||||||
@ -73,6 +75,9 @@ NEXTSTEPS
|
|||||||
end
|
end
|
||||||
|
|
||||||
def prompt_sass_dir
|
def prompt_sass_dir
|
||||||
|
if rails3?
|
||||||
|
nil
|
||||||
|
else
|
||||||
recommended_location = separate('app/stylesheets')
|
recommended_location = separate('app/stylesheets')
|
||||||
default_location = separate('public/stylesheets/sass')
|
default_location = separate('public/stylesheets/sass')
|
||||||
print %Q{Compass recommends that you keep your stylesheets in #{recommended_location}
|
print %Q{Compass recommends that you keep your stylesheets in #{recommended_location}
|
||||||
@ -81,8 +86,12 @@ NEXTSTEPS
|
|||||||
answer = $stdin.gets.downcase[0]
|
answer = $stdin.gets.downcase[0]
|
||||||
answer == ?n ? default_location : recommended_location
|
answer == ?n ? default_location : recommended_location
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def prompt_css_dir
|
def prompt_css_dir
|
||||||
|
if rails3?
|
||||||
|
nil
|
||||||
|
else
|
||||||
recommended_location = separate("public/stylesheets/compiled")
|
recommended_location = separate("public/stylesheets/compiled")
|
||||||
default_location = separate("public/stylesheets")
|
default_location = separate("public/stylesheets")
|
||||||
puts
|
puts
|
||||||
@ -94,6 +103,7 @@ NEXTSTEPS
|
|||||||
answer = answer.downcase[0]
|
answer = answer.downcase[0]
|
||||||
answer == ?n ? default_location : recommended_location
|
answer == ?n ? default_location : recommended_location
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def config_contents
|
def config_contents
|
||||||
"# This configuration file works with both the Compass command line tool and within Rails.\n" +
|
"# This configuration file works with both the Compass command line tool and within Rails.\n" +
|
||||||
|
@ -4,6 +4,9 @@ unless defined?(Compass::RAILS_LOADED)
|
|||||||
require 'action_pack/version'
|
require 'action_pack/version'
|
||||||
if ActionPack::VERSION::MAJOR >= 3
|
if ActionPack::VERSION::MAJOR >= 3
|
||||||
# TODO figure something out so image_path works with rails integration
|
# 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
|
else
|
||||||
%w(action_controller sass_plugin urls).each do |lib|
|
%w(action_controller sass_plugin urls).each do |lib|
|
||||||
require "compass/app_integration/rails/actionpack2/#{lib}"
|
require "compass/app_integration/rails/actionpack2/#{lib}"
|
||||||
|
2
lib/rails/init.rb
Normal file
2
lib/rails/init.rb
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
require 'compass'
|
||||||
|
require 'compass/app_integration/rails'
|
Loading…
Reference in New Issue
Block a user