Basic Rails 3.1 integration.
This commit is contained in:
parent
4852e7803c
commit
1b689ce966
@ -24,8 +24,10 @@ module Compass
|
|||||||
end
|
end
|
||||||
|
|
||||||
def configuration
|
def configuration
|
||||||
Compass::Configuration::Data.new('rails').
|
config = Compass::Configuration::Data.new('rails')
|
||||||
extend(ConfigurationDefaults)
|
config.extend(ConfigurationDefaults)
|
||||||
|
config.extend(ConfigurationDefaultsWithAssetPipeline) if Sass::Util.ap_geq?('3.1.0.beta')
|
||||||
|
config
|
||||||
end
|
end
|
||||||
|
|
||||||
def env
|
def env
|
||||||
@ -48,12 +50,17 @@ module Compass
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize!(config = nil)
|
def check_for_double_boot!
|
||||||
if booted?
|
if booted?
|
||||||
Compass::Util.compass_warn("Warning: Compass was booted twice. Compass has a Railtie now; please remove your intializer.")
|
Compass::Util.compass_warn("Warning: Compass was booted twice. If you're using Rails 3, Compass has a Railtie now; please remove your compass intializer.")
|
||||||
else
|
else
|
||||||
booted!
|
booted!
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Rails 2.x projects use this in their compass initializer.
|
||||||
|
def initialize!(config = nil)
|
||||||
|
check_for_double_boot!
|
||||||
config ||= Compass.detect_configuration_file(root)
|
config ||= Compass.detect_configuration_file(root)
|
||||||
Compass.add_project_configuration(config, :project_type => :rails)
|
Compass.add_project_configuration(config, :project_type => :rails)
|
||||||
Compass.discover_extensions!
|
Compass.discover_extensions!
|
||||||
|
10
lib/compass/app_integration/rails/actionpack2x.rb
Normal file
10
lib/compass/app_integration/rails/actionpack2x.rb
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
%w(action_controller sass_plugin urls).each do |lib|
|
||||||
|
require "compass/app_integration/rails/actionpack2x/#{lib}"
|
||||||
|
end
|
||||||
|
|
||||||
|
# Wierd that this has to be re-included to pick up sub-modules. Ruby bug?
|
||||||
|
class Sass::Script::Functions::EvaluationContext
|
||||||
|
include Sass::Script::Functions
|
||||||
|
private
|
||||||
|
include ActionView::Helpers::AssetTagHelper
|
||||||
|
end
|
11
lib/compass/app_integration/rails/actionpack30.rb
Normal file
11
lib/compass/app_integration/rails/actionpack30.rb
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
# TODO figure something out so image_path works with rails integration
|
||||||
|
%w(railtie).each do |lib|
|
||||||
|
require "compass/app_integration/rails/actionpack30/#{lib}"
|
||||||
|
end
|
||||||
|
|
||||||
|
# Wierd that this has to be re-included to pick up sub-modules. Ruby bug?
|
||||||
|
class Sass::Script::Functions::EvaluationContext
|
||||||
|
include Sass::Script::Functions
|
||||||
|
private
|
||||||
|
include ActionView::Helpers::AssetTagHelper
|
||||||
|
end
|
@ -40,7 +40,10 @@ module Compass
|
|||||||
initializer "compass.initialize_rails" do |app|
|
initializer "compass.initialize_rails" do |app|
|
||||||
# Configure compass for use within rails, and provide the project configuration
|
# Configure compass for use within rails, and provide the project configuration
|
||||||
# that came via the rails boot process.
|
# that came via the rails boot process.
|
||||||
Compass::AppIntegration::Rails.initialize!(app.config.compass)
|
Compass::AppIntegration::Rails.check_for_double_boot!
|
||||||
|
Compass.discover_extensions!
|
||||||
|
Compass.configure_sass_plugin!
|
||||||
|
Compass.handle_configuration_change!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
5
lib/compass/app_integration/rails/actionpack31.rb
Normal file
5
lib/compass/app_integration/rails/actionpack31.rb
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
# TODO figure something out so image_path works with rails integration
|
||||||
|
%w(railtie).each do |lib|
|
||||||
|
require "compass/app_integration/rails/actionpack31/#{lib}"
|
||||||
|
end
|
||||||
|
|
50
lib/compass/app_integration/rails/actionpack31/railtie.rb
Normal file
50
lib/compass/app_integration/rails/actionpack31/railtie.rb
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
require 'compass'
|
||||||
|
require 'rails'
|
||||||
|
|
||||||
|
class Rails::Railtie::Configuration
|
||||||
|
# Adds compass configuration accessor to the application configuration.
|
||||||
|
#
|
||||||
|
# If a configuration file for compass exists, it will be read in and
|
||||||
|
# the project's configuration values will already be set on the config
|
||||||
|
# object.
|
||||||
|
#
|
||||||
|
# For example:
|
||||||
|
#
|
||||||
|
# module MyApp
|
||||||
|
# class Application < Rails::Application
|
||||||
|
# config.compass.line_comments = !Rails.env.production?
|
||||||
|
# config.compass.fonts_dir = "app/assets/fonts"
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
#
|
||||||
|
# It is suggested that you create a compass configuration file if you
|
||||||
|
# want a quicker boot time when using the compass command line tool.
|
||||||
|
#
|
||||||
|
# For more information on available configuration options see:
|
||||||
|
# http://compass-style.org/help/tutorials/configuration-reference/
|
||||||
|
def compass
|
||||||
|
@compass ||= begin
|
||||||
|
data = if (config_file = Compass.detect_configuration_file) && (config_data = Compass.configuration_for(config_file))
|
||||||
|
config_data
|
||||||
|
else
|
||||||
|
Compass::Configuration::Data.new("rails_config")
|
||||||
|
end
|
||||||
|
data.project_type = :rails # Forcing this makes sure all the rails defaults will be loaded.
|
||||||
|
Compass.add_project_configuration(data)
|
||||||
|
data
|
||||||
|
end
|
||||||
|
@compass
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
module Compass
|
||||||
|
class Railtie < Rails::Railtie
|
||||||
|
initializer "compass.initialize_rails" do |app|
|
||||||
|
# Configure compass for use within rails, and provide the project configuration
|
||||||
|
# that came via the rails boot process.
|
||||||
|
Compass::AppIntegration::Rails.check_for_double_boot!
|
||||||
|
Compass.discover_extensions!
|
||||||
|
Compass.configure_rails!(app)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -1,6 +1,28 @@
|
|||||||
module Compass
|
module Compass
|
||||||
module AppIntegration
|
module AppIntegration
|
||||||
module Rails
|
module Rails
|
||||||
|
|
||||||
|
module ConfigurationDefaultsWithAssetPipeline
|
||||||
|
# These methods overwrite the old rails defaults
|
||||||
|
# when rails 3.1 is detected.
|
||||||
|
|
||||||
|
def default_sass_dir
|
||||||
|
File.join("app", "assets", "stylesheets")
|
||||||
|
end
|
||||||
|
|
||||||
|
def default_images_dir
|
||||||
|
File.join("app", "assets", "images")
|
||||||
|
end
|
||||||
|
|
||||||
|
def default_fonts_dir
|
||||||
|
File.join("app", "assets", "fonts")
|
||||||
|
end
|
||||||
|
|
||||||
|
def default_javascripts_dir
|
||||||
|
File.join("app", "assets", "javascripts")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
module ConfigurationDefaults
|
module ConfigurationDefaults
|
||||||
|
|
||||||
def project_type_without_default
|
def project_type_without_default
|
||||||
@ -8,11 +30,7 @@ module Compass
|
|||||||
end
|
end
|
||||||
|
|
||||||
def default_sass_dir
|
def default_sass_dir
|
||||||
if Sass::Util.ap_geq?('3.1.0.beta')
|
File.join("app", "stylesheets")
|
||||||
File.join("app", "assets", "stylesheets")
|
|
||||||
else
|
|
||||||
File.join("app", "stylesheets")
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def default_css_dir
|
def default_css_dir
|
||||||
@ -28,11 +46,7 @@ module Compass
|
|||||||
end
|
end
|
||||||
|
|
||||||
def default_javascripts_dir
|
def default_javascripts_dir
|
||||||
if Sass::Util.ap_geq?('3.1.0.beta')
|
File.join("public", "javascripts")
|
||||||
File.join("app", "assets", "javascripts")
|
|
||||||
else
|
|
||||||
File.join("public", "javascripts")
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def default_http_images_path
|
def default_http_images_path
|
||||||
|
@ -3,25 +3,15 @@ unless defined?(Compass::RAILS_LOADED)
|
|||||||
begin
|
begin
|
||||||
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
|
if ActionPack::VERSION::MINOR < 1
|
||||||
%w(railtie).each do |lib|
|
require 'compass/app_integration/rails/actionpack30'
|
||||||
require "compass/app_integration/rails/actionpack3/#{lib}"
|
else
|
||||||
|
require 'compass/app_integration/rails/actionpack31'
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
%w(action_controller sass_plugin urls).each do |lib|
|
require 'compass/app_integration/rails/actionpack2x'
|
||||||
require "compass/app_integration/rails/actionpack2/#{lib}"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
rescue LoadError => e
|
rescue LoadError, NameError
|
||||||
$stderr.puts "Compass could not access the rails environment."
|
$stderr.puts "Compass could not access the rails environment."
|
||||||
rescue NameError => e
|
|
||||||
$stderr.puts "Compass could not access the rails environment."
|
|
||||||
end
|
|
||||||
|
|
||||||
# Wierd that this has to be re-included to pick up sub-modules. Ruby bug?
|
|
||||||
class Sass::Script::Functions::EvaluationContext
|
|
||||||
include Sass::Script::Functions
|
|
||||||
private
|
|
||||||
include ActionView::Helpers::AssetTagHelper
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -77,6 +77,12 @@ module Compass
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def configure_rails!(app)
|
||||||
|
app.config.compass.to_sass_engine_options.each do |key, value|
|
||||||
|
app.config.sass.send(:"#{key}=", value)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def sass_engine_options
|
def sass_engine_options
|
||||||
configuration.to_sass_engine_options
|
configuration.to_sass_engine_options
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user