Skip to content

Commit

Permalink
Merge 7eb5936 into be61d5f
Browse files Browse the repository at this point in the history
  • Loading branch information
craigmcnamara committed Jan 4, 2015
2 parents be61d5f + 7eb5936 commit f65542c
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 155 deletions.
98 changes: 1 addition & 97 deletions lib/compass-rails.rb
Expand Up @@ -10,27 +10,6 @@ module CompassRails

extend self

def load_rails
return true if rails_loaded?
return if defined?(::Rails) && ::Rails.respond_to?(:application) && !::Rails.application.nil?

rails_path = Dir.pwd
if File.exists?(File.join(rails_path, 'config', 'application.rb'))
raise 'Rails application not found' if rails_config_path == '/'
rails_config_path = File.join(rails_config_path, '..')
#load the rails config
require "#{rails_config_path}/config/application.rb"
require 'sass-rails'
require 'sprockets/railtie'
@app ||= ::Rails.application.initialize!
require 'rails/engine'
return true
end

false
end


def setup_fake_rails_env_paths(sprockets_env)
return unless rails_loaded?
keys = ['app/assets', 'lib/assets', 'vendor/assets']
Expand All @@ -46,17 +25,14 @@ def setup_fake_rails_env_paths(sprockets_env)
end

def sass_config
load_rails
::Rails.application.config.sass
end

def sprockets
load_rails
@sprockets ||= ::Rails.application.assets
end

def context
load_rails
@context ||= begin
sprockets.version = ::Rails.env + "-#{sprockets.version}"
setup_fake_rails_env_paths(sprockets)
Expand All @@ -70,10 +46,6 @@ def context
end
end

def installer(*args)
CompassRails::Installer.new(*args)
end

def rails_loaded?
defined?(::Rails)
end
Expand All @@ -100,23 +72,10 @@ def rails4?
end

def version_match(version)
if (rails_version =~ version).nil?
return false
end

true
end

def booted!
CompassRails.const_set(:BOOTED, true)
end

def booted?
defined?(CompassRails::BOOTED) && CompassRails::BOOTED
!(rails_version =~ version).nil?
end

def configuration
load_rails
config = Compass::Configuration::Data.new('rails')
config.extend(CompassRails::Configuration)
config
Expand All @@ -126,50 +85,6 @@ def prefix
::Rails.application.config.assets.prefix
end

def env_production?
if defined?(::Rails) && ::Rails.respond_to?(:env)
::Rails.env.production?
elsif defined?(RAILS_ENV)
RAILS_ENV == "production"
end
end

def root
@root ||= begin
if defined?(::Rails) && ::Rails.respond_to?(:root)
::Rails.root
elsif defined?(RAILS_ROOT)
Pathname.new(RAILS_ROOT)
else
Pathname.new(Dir.pwd)
end
end
end

def check_for_double_boot!
if booted?
Compass::Util.compass_warn("Warning: Compass was booted twice. Compass-rails has got your back; please remove your compass initializer.")
else
booted!
end
end

def sass_plugin_enabled?
unless rails31?
defined?(Sass::Plugin) && !Sass::Plugin.options[:never_update]
end
end

# Rails projects without asset pipeline use this in their compass initializer.
def initialize!(config = nil)
check_for_double_boot!
config ||= Compass.detect_configuration_file(root)
Compass.add_project_configuration(config, :project_type => :rails)
Compass.discover_extensions!
Compass.configure_sass_plugin!
Compass.handle_configuration_change! if sass_plugin_enabled?
end

def configure_rails!(app)
return unless app.config.respond_to?(:sass)
sass_config = app.config.sass
Expand Down Expand Up @@ -207,16 +122,6 @@ def boot_config
end
end

def asset_pipeline_enabled?
return false unless rails_loaded? && ::Rails.respond_to?(:application) && !::Rails.application.nil?
rails_config = ::Rails.application.config
if rails_config.respond_to?(:assets)
rails_config.assets.enabled != false
else
false
end
end

private

# sets the sass config value only if the corresponding compass-based setting
Expand All @@ -235,6 +140,5 @@ def set_maybe(sass_config, compass_config, sass_option, compass_option)

require "compass-rails/patches"
require "compass-rails/railties"
require "compass-rails/installer"
end

30 changes: 0 additions & 30 deletions lib/compass-rails/installer.rb

This file was deleted.

3 changes: 0 additions & 3 deletions lib/compass-rails/patches.rb
@@ -1,6 +1,3 @@
if CompassRails.rails31? || CompassRails.rails32?
CompassRails.load_rails
require 'compass-rails/patches/importer'
elsif CompassRails.rails4?
CompassRails.load_rails
end
22 changes: 10 additions & 12 deletions lib/compass-rails/patches/importer.rb
Expand Up @@ -4,18 +4,16 @@ class Compiler
attr_accessor :sass_options
STYLESHEET = /stylesheet/
def sass_options
if CompassRails.asset_pipeline_enabled?
@sass_options[:custom] ||= {}
@sass_options[:custom] = {:resolver => ::Sass::Rails::Resolver.new(CompassRails.context)}
@sass_options[:load_paths] ||= []
unless @sass_options[:load_paths].any? {|k| k.is_a?(::Sass::Rails::Importer) }
::Rails.application.assets.paths.each do |path|
next unless path.to_s =~ STYLESHEET
Dir["#{path}/**/*"].each do |pathname|
# args are: sprockets environment, the logical_path ex. 'stylesheets', and the full path name for the render
context = ::CompassRails.context.new(::Rails.application.assets, File.basename(path), Pathname.new(pathname))
@sass_options[:load_paths] << ::Sass::Rails::Importer.new(context)
end
@sass_options[:custom] ||= {}
@sass_options[:custom] = {:resolver => ::Sass::Rails::Resolver.new(CompassRails.context)}
@sass_options[:load_paths] ||= []
unless @sass_options[:load_paths].any? {|k| k.is_a?(::Sass::Rails::Importer) }
::Rails.application.assets.paths.each do |path|
next unless path.to_s =~ STYLESHEET
Dir["#{path}/**/*"].each do |pathname|
# args are: sprockets environment, the logical_path ex. 'stylesheets', and the full path name for the render
context = ::CompassRails.context.new(::Rails.application.assets, File.basename(path), Pathname.new(pathname))
@sass_options[:load_paths] << ::Sass::Rails::Importer.new(context)
end
end
end
Expand Down
13 changes: 3 additions & 10 deletions lib/compass-rails/railties/3_1.rb
Expand Up @@ -3,16 +3,9 @@ class Railtie < Rails::Railtie

initializer "compass.initialize_rails", :group => :all do |app|
require 'compass'
if CompassRails.asset_pipeline_enabled?
require 'compass-rails/patches/3_1'
# Configure compass for use within rails, and provide the project configuration
# that came via the rails boot process.
CompassRails.check_for_double_boot!
Compass.discover_extensions!
CompassRails.configure_rails!(app)
else
CompassRails.initialize!(app.config.compass)
end
require 'compass-rails/patches/3_1'
Compass.discover_extensions!
CompassRails.configure_rails!(app)
end

config.compass = begin
Expand Down
3 changes: 0 additions & 3 deletions lib/compass-rails/railties/4_0.rb
Expand Up @@ -4,9 +4,6 @@ class Railtie < Rails::Railtie
initializer "compass.initialize_rails", :group => :all do |app|
require 'compass'
require 'compass-rails/patches/4_0'
# Configure compass for use within rails, and provide the project configuration
# that came via the rails boot process.
CompassRails.check_for_double_boot!
Compass.discover_extensions!
CompassRails.configure_rails!(app)
end
Expand Down

0 comments on commit f65542c

Please sign in to comment.