From 1bebb026de0d3b1321659adcae187ff61d5117e0 Mon Sep 17 00:00:00 2001 From: Vojta Drbohlav Date: Sat, 6 Feb 2016 18:43:00 +0100 Subject: [PATCH 1/3] Fixed error that occured with sprockets >= 3 in production mode. When config.assets.compile is false sprockets does not set ::Rails.application.assets. Use ::Rails.application.config.assets instead. --- lib/compass-rails.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/compass-rails.rb b/lib/compass-rails.rb index 4ecc73e..4b6e4da 100644 --- a/lib/compass-rails.rb +++ b/lib/compass-rails.rb @@ -35,7 +35,7 @@ def sass_config end def sprockets - @sprockets ||= ::Rails.application.assets + @sprockets ||= ::Rails.application.assets || ::Rails.application.config.assets end def context From feb561270d56ff1bda3aa18b9904665cc0c80343 Mon Sep 17 00:00:00 2001 From: Vojta Drbohlav Date: Sat, 6 Feb 2016 18:51:49 +0100 Subject: [PATCH 2/3] Replaced all occurences of ::Rails.application.assets with CompassRails.sprockets. --- lib/compass-rails.rb | 2 +- lib/compass-rails/patches/compass.rb | 2 +- lib/compass-rails/patches/importer.rb | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/compass-rails.rb b/lib/compass-rails.rb index 4b6e4da..7fbe44d 100644 --- a/lib/compass-rails.rb +++ b/lib/compass-rails.rb @@ -42,7 +42,7 @@ def context @context ||= begin sprockets.version = ::Rails.env + "-#{sprockets.version}" setup_fake_rails_env_paths(sprockets) - context = ::Rails.application.assets.context_class + context = sprockets.context_class context.extend(::Sprockets::Helpers::IsolatedHelper) context.extend(::Sprockets::Helpers::RailsHelper) context.extend(::Sass::Rails::Railtie::SassContext) diff --git a/lib/compass-rails/patches/compass.rb b/lib/compass-rails/patches/compass.rb index a298972..5168996 100644 --- a/lib/compass-rails/patches/compass.rb +++ b/lib/compass-rails/patches/compass.rb @@ -3,7 +3,7 @@ def image_path_for_size(image_file) begin - file = ::Rails.application.assets.find_asset(image_file) + file = CompassRails.sprockets.find_asset(image_file) return file rescue ::Sprockets::FileOutsidePaths return super(image_file) diff --git a/lib/compass-rails/patches/importer.rb b/lib/compass-rails/patches/importer.rb index d723cd4..24ed07b 100644 --- a/lib/compass-rails/patches/importer.rb +++ b/lib/compass-rails/patches/importer.rb @@ -8,11 +8,11 @@ def sass_options @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| + CompassRails.sprockets.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)) + context = ::CompassRails.context.new(CompassRails.sprockets, File.basename(path), Pathname.new(pathname)) @sass_options[:load_paths] << ::Sass::Rails::Importer.new(context) end end From d53c1fa17dd9ebaf33f2491388e4cf92bd81a445 Mon Sep 17 00:00:00 2001 From: Vojta Drbohlav Date: Sat, 6 Feb 2016 20:14:18 +0100 Subject: [PATCH 3/3] Fixed image_path_for_size to work properly with sprockets >= 3. Use ::Rails.application.assets_manifest instead of ::Rails.application.assets when config.assets.compile is not set. --- lib/compass-rails/patches/compass.rb | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/compass-rails/patches/compass.rb b/lib/compass-rails/patches/compass.rb index 5168996..6f34396 100644 --- a/lib/compass-rails/patches/compass.rb +++ b/lib/compass-rails/patches/compass.rb @@ -2,11 +2,23 @@ private def image_path_for_size(image_file) - begin - file = CompassRails.sprockets.find_asset(image_file) - return file - rescue ::Sprockets::FileOutsidePaths - return super(image_file) + if ::Rails.application.config.assets.compile + begin + file = CompassRails.sprockets.find_asset(image_file) + return file.respond_to?(:pathname) ? file.pathname.to_s : file + rescue ::Sprockets::FileOutsidePaths + return super(image_file) + end + else + return image_file if File.exists?(image_file) + + assets_manifest = ::Rails.application.assets_manifest + file = assets_manifest.assets[image_file] + if file + ::Rails.root.join("public", assets_manifest.directory, file) + else + super(image_file) + end end end end