Blame SOURCES/rubygem-sass-rails-4.0.3-restore-special-behavior-in-sassimporter.patch

cc1d14
From e56c2fbf60ef2bd879aae6f6163c90326b4017be Mon Sep 17 00:00:00 2001
cc1d14
From: Matthew Draper <matthew@trebex.net>
cc1d14
Date: Wed, 23 Apr 2014 04:42:06 +0930
cc1d14
Subject: [PATCH] Restore special behaviour in SassImporter
cc1d14
cc1d14
---
cc1d14
 Gemfile                          |  1 +
cc1d14
 lib/sass/rails/importer.rb       | 78 +++++++++++++++++++++++++++++++++++++++-
cc1d14
 lib/sass/rails/template.rb       | 11 ++----
cc1d14
 sass-rails.gemspec               |  2 +-
cc1d14
 sass-rails.gemspec.erb           |  2 +-
cc1d14
 test/gemfiles/Gemfile-master     |  1 +
cc1d14
 6 files changed, 84 insertions(+), 11 deletions(-)
cc1d14
cc1d14
diff --git a/Gemfile b/Gemfile
cc1d14
index e93ce25..94da4f5 100644
cc1d14
--- a/Gemfile
cc1d14
+++ b/Gemfile
cc1d14
@@ -4,5 +4,6 @@ source "https://rubygems.org"
cc1d14
 gemspec
cc1d14
 
cc1d14
 gem "rails"
cc1d14
+gem "sprockets-rails"
cc1d14
 
cc1d14
 gem "sqlite3"
cc1d14
diff --git a/lib/sass/rails/importer.rb b/lib/sass/rails/importer.rb
cc1d14
index e31302c..699b7a1 100644
cc1d14
--- a/lib/sass/rails/importer.rb
cc1d14
+++ b/lib/sass/rails/importer.rb
cc1d14
@@ -2,7 +2,15 @@
cc1d14
 
cc1d14
 module Sass
cc1d14
   module Rails
cc1d14
-    class SassImporter < Sprockets::SassImporter
cc1d14
+    class SassImporter < Sass::Importers::Filesystem
cc1d14
+      GLOB = /\*|\[.+\]/
cc1d14
+
cc1d14
+      attr_reader :context
cc1d14
+      def initialize(context, *args)
cc1d14
+        @context = context
cc1d14
+        super(*args)
cc1d14
+      end
cc1d14
+
cc1d14
       def extensions
cc1d14
         {
cc1d14
           'css'          => :scss,
cc1d14
@@ -15,6 +23,74 @@ def extensions
cc1d14
           'css.sass.erb' => :sass
cc1d14
         }.merge!(super)
cc1d14
       end
cc1d14
+
cc1d14
+      def find_relative(name, base, options)
cc1d14
+        if name =~ GLOB
cc1d14
+          glob_imports(name, Pathname.new(base), options)
cc1d14
+        else
cc1d14
+          engine_from_path(name, File.dirname(base), options)
cc1d14
+        end
cc1d14
+      end
cc1d14
+
cc1d14
+      def find(name, options)
cc1d14
+        if name =~ GLOB
cc1d14
+          nil # globs must be relative
cc1d14
+        else
cc1d14
+          engine_from_path(name, root, options)
cc1d14
+        end
cc1d14
+      end
cc1d14
+
cc1d14
+      private
cc1d14
+
cc1d14
+        def each_globbed_file(glob, base_pathname, options)
cc1d14
+          Dir["#{base_pathname}/#{glob}"].sort.each do |filename|
cc1d14
+            next if filename == options[:filename]
cc1d14
+            if File.directory?(filename)
cc1d14
+              context.depend_on(filename)
cc1d14
+              context.depend_on(File.expand_path('..', filename))
cc1d14
+            elsif context.asset_requirable?(filename)
cc1d14
+              context.depend_on(File.dirname(filename))
cc1d14
+              yield filename
cc1d14
+            end
cc1d14
+          end
cc1d14
+        end
cc1d14
+
cc1d14
+        def glob_imports(glob, base_pathname, options)
cc1d14
+          contents = ""
cc1d14
+          each_globbed_file(glob, base_pathname.dirname, options) do |filename|
cc1d14
+            contents << "@import #{Pathname.new(filename).relative_path_from(base_pathname.dirname).to_s.inspect};\n"
cc1d14
+          end
cc1d14
+          return nil if contents.empty?
cc1d14
+          Sass::Engine.new(contents, options.merge(
cc1d14
+            :filename => base_pathname.to_s,
cc1d14
+            :importer => self,
cc1d14
+            :syntax => :scss
cc1d14
+          ))
cc1d14
+        end
cc1d14
+
cc1d14
+
cc1d14
+        def engine_from_path(name, dir, options)
cc1d14
+          full_filename, syntax = Sass::Util.destructure(find_real_file(dir, name, options))
cc1d14
+          return unless full_filename && File.readable?(full_filename)
cc1d14
+
cc1d14
+          context.depend_on full_filename
cc1d14
+          engine = Sass::Engine.new(evaluate(full_filename), options.merge(
cc1d14
+            syntax: syntax,
cc1d14
+            filename: full_filename,
cc1d14
+            importer: self
cc1d14
+          ))
cc1d14
+
cc1d14
+          engine
cc1d14
+        end
cc1d14
+
cc1d14
+        def evaluate(filename)
cc1d14
+          attributes = context.environment.attributes_for(filename)
cc1d14
+          processors = context.environment.preprocessors(attributes.content_type) +
cc1d14
+            attributes.engines.reverse - [Sass::Rails::ScssTemplate, Sass::Rails::SassTemplate]
cc1d14
+
cc1d14
+          context.evaluate(filename, processors: processors)
cc1d14
+        end
cc1d14
+
cc1d14
     end
cc1d14
   end
cc1d14
 end
cc1d14
diff --git a/lib/sass/rails/template.rb b/lib/sass/rails/template.rb
cc1d14
index be7ccca..d319905 100644
cc1d14
--- a/lib/sass/rails/template.rb
cc1d14
+++ b/lib/sass/rails/template.rb
cc1d14
@@ -12,8 +12,8 @@ def evaluate(context, locals, &block)
cc1d14
           :line => line,
cc1d14
           :syntax => syntax,
cc1d14
           :cache_store => cache_store,
cc1d14
-          :importer => SassImporter.new(context.pathname.to_s),
cc1d14
-          :load_paths => context.environment.paths.map { |path| SassImporter.new(path.to_s) },
cc1d14
+          :importer => SassImporter.new(context, context.pathname.to_s),
cc1d14
+          :load_paths => context.environment.paths.map { |path| SassImporter.new(context, path.to_s) },
cc1d14
           :sprockets => {
cc1d14
             :context => context,
cc1d14
             :environment => context.environment
cc1d14
@@ -22,12 +22,7 @@ def evaluate(context, locals, &block)
cc1d14
 
cc1d14
         sass_config = context.environment.context_class.sass_config.merge(options)
cc1d14
 
cc1d14
-        result = ::Sass::Engine.new(data, sass_config).render
cc1d14
-
cc1d14
-        filenames = ([options[:importer].imported_filenames] + options[:load_path].map(&:imported_filenames)).flatten.uniq
cc1d14
-        filenames.each { |filename| context.depend_on(filename) }
cc1d14
-
cc1d14
-        result
cc1d14
+        ::Sass::Engine.new(data, sass_config).render
cc1d14
       rescue ::Sass::SyntaxError => e
cc1d14
         context.__LINE__ = e.sass_backtrace.first[:line]
cc1d14
         raise e
cc1d14
diff --git a/sass-rails.gemspec b/sass-rails.gemspec
cc1d14
index 2ce5250..d4d67ec 100644
cc1d14
--- a/sass-rails.gemspec
cc1d14
+++ b/sass-rails.gemspec
cc1d14
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
cc1d14
 
cc1d14
   s.rubyforge_project = "sass-rails"
cc1d14
 
cc1d14
-  s.add_dependency 'sass',            '~> 3.2.0'
cc1d14
+  s.add_dependency 'sass',            '~> 3.2'
cc1d14
   s.add_dependency 'railties',        '>= 4.0.0', '< 5.0'
cc1d14
   s.add_dependency 'sprockets-rails', '~> 2.0'
cc1d14
   s.add_dependency 'sprockets',       '~> 2.12'
cc1d14
diff --git a/sass-rails.gemspec.erb b/sass-rails.gemspec.erb
cc1d14
index 3bf13fd..296d330 100644
cc1d14
--- a/sass-rails.gemspec.erb
cc1d14
+++ b/sass-rails.gemspec.erb
cc1d14
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
cc1d14
 
cc1d14
   s.rubyforge_project = "sass-rails"
cc1d14
 
cc1d14
-  s.add_dependency 'sass',            '~> 3.2.0'
cc1d14
+  s.add_dependency 'sass',            '~> 3.2'
cc1d14
   s.add_dependency 'railties',        '>= 4.0.0', '< 5.0'
cc1d14
   s.add_dependency 'sprockets-rails', '~> 2.0'
cc1d14
   s.add_dependency 'sprockets',       '~> 2.12'
cc1d14
diff --git a/test/gemfiles/Gemfile-master b/test/gemfiles/Gemfile-master
cc1d14
index 7b09aaf..587850a 100644
cc1d14
--- a/test/gemfiles/Gemfile-master
cc1d14
+++ b/test/gemfiles/Gemfile-master
cc1d14
@@ -4,5 +4,6 @@ source "https://rubygems.org"
cc1d14
 gemspec path: '../..'
cc1d14
 
cc1d14
 gem "rails", github: 'rails/rails', branch: 'master'
cc1d14
+gem "sprockets-rails", github: 'rails/sprockets-rails', branch: '2-1-stable'
cc1d14
 
cc1d14
 gem "sqlite3"
cc1d14
-- 
cc1d14
1.9.3
cc1d14