|
|
cc1d14 |
From bd63297c31aceb079595c3a3d9007b0e4df505b6 Mon Sep 17 00:00:00 2001
|
|
|
cc1d14 |
From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?=
|
|
|
cc1d14 |
<rafael.franca@plataformatec.com.br>
|
|
|
cc1d14 |
Date: Thu, 13 Mar 2014 21:13:33 -0300
|
|
|
cc1d14 |
Subject: [PATCH] Define our own importer instead of monkey patching sprockets
|
|
|
cc1d14 |
|
|
|
cc1d14 |
---
|
|
|
cc1d14 |
lib/sass/rails/importer.rb | 112 ++++++---------------------------------------
|
|
|
cc1d14 |
lib/sass/rails/template.rb | 4 +-
|
|
|
cc1d14 |
2 files changed, 16 insertions(+), 100 deletions(-)
|
|
|
cc1d14 |
|
|
|
cc1d14 |
diff --git a/lib/sass/rails/importer.rb b/lib/sass/rails/importer.rb
|
|
|
cc1d14 |
index 23c03e9..e31302c 100644
|
|
|
cc1d14 |
--- a/lib/sass/rails/importer.rb
|
|
|
cc1d14 |
+++ b/lib/sass/rails/importer.rb
|
|
|
cc1d14 |
@@ -1,104 +1,20 @@
|
|
|
cc1d14 |
require 'sprockets/sass_importer'
|
|
|
cc1d14 |
|
|
|
cc1d14 |
-module Sprockets
|
|
|
cc1d14 |
- class SassImporter < Sass::Importers::Filesystem
|
|
|
cc1d14 |
- GLOB = /\*|\[.+\]/
|
|
|
cc1d14 |
-
|
|
|
cc1d14 |
- attr_reader :context
|
|
|
cc1d14 |
- private :context
|
|
|
cc1d14 |
-
|
|
|
cc1d14 |
- def extensions
|
|
|
cc1d14 |
- {
|
|
|
cc1d14 |
- 'css' => :scss,
|
|
|
cc1d14 |
- 'css.scss' => :scss,
|
|
|
cc1d14 |
- 'css.sass' => :sass,
|
|
|
cc1d14 |
- 'css.erb' => :scss,
|
|
|
cc1d14 |
- 'scss.erb' => :scss,
|
|
|
cc1d14 |
- 'sass.erb' => :sass,
|
|
|
cc1d14 |
- 'css.scss.erb' => :scss,
|
|
|
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 |
- def each_globbed_file(glob, base_pathname, options)
|
|
|
cc1d14 |
- Dir["#{base_pathname}/#{glob}"].sort.each do |filename|
|
|
|
cc1d14 |
- next if filename == options[:filename]
|
|
|
cc1d14 |
- yield filename if File.directory?(filename) || context.asset_requirable?(filename)
|
|
|
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 |
- if File.directory?(filename)
|
|
|
cc1d14 |
- depend_on(filename)
|
|
|
cc1d14 |
- elsif context.asset_requirable?(filename)
|
|
|
cc1d14 |
- depend_on(filename)
|
|
|
cc1d14 |
- contents << "@import #{Pathname.new(filename).relative_path_from(base_pathname.dirname).to_s.inspect};\n"
|
|
|
cc1d14 |
- end
|
|
|
cc1d14 |
+module Sass
|
|
|
cc1d14 |
+ module Rails
|
|
|
cc1d14 |
+ class SassImporter < Sprockets::SassImporter
|
|
|
cc1d14 |
+ def extensions
|
|
|
cc1d14 |
+ {
|
|
|
cc1d14 |
+ 'css' => :scss,
|
|
|
cc1d14 |
+ 'css.scss' => :scss,
|
|
|
cc1d14 |
+ 'css.sass' => :sass,
|
|
|
cc1d14 |
+ 'css.erb' => :scss,
|
|
|
cc1d14 |
+ 'scss.erb' => :scss,
|
|
|
cc1d14 |
+ 'sass.erb' => :sass,
|
|
|
cc1d14 |
+ 'css.scss.erb' => :scss,
|
|
|
cc1d14 |
+ 'css.sass.erb' => :sass
|
|
|
cc1d14 |
+ }.merge!(super)
|
|
|
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 |
- private
|
|
|
cc1d14 |
-
|
|
|
cc1d14 |
- def depend_on(filename)
|
|
|
cc1d14 |
- context.depend_on(filename)
|
|
|
cc1d14 |
- context.depend_on(globbed_file_parent(filename))
|
|
|
cc1d14 |
- end
|
|
|
cc1d14 |
-
|
|
|
cc1d14 |
- def globbed_file_parent(filename)
|
|
|
cc1d14 |
- if File.directory?(filename)
|
|
|
cc1d14 |
- File.expand_path('..', filename)
|
|
|
cc1d14 |
- else
|
|
|
cc1d14 |
- File.dirname(filename)
|
|
|
cc1d14 |
- end
|
|
|
cc1d14 |
- end
|
|
|
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 |
- engine = Sass::Engine.new(evaluate(full_filename), options.merge(
|
|
|
cc1d14 |
- syntax: syntax,
|
|
|
cc1d14 |
- filename: full_filename,
|
|
|
cc1d14 |
- importer: self
|
|
|
cc1d14 |
- ))
|
|
|
cc1d14 |
-
|
|
|
cc1d14 |
- if engine && (filename = engine.options[:filename])
|
|
|
cc1d14 |
- @context.depend_on(filename)
|
|
|
cc1d14 |
- end
|
|
|
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 - [Sprockets::ScssTemplate, Sprockets::SassTemplate]
|
|
|
cc1d14 |
-
|
|
|
cc1d14 |
- context.evaluate(filename, processors: processors)
|
|
|
cc1d14 |
- end
|
|
|
cc1d14 |
end
|
|
|
cc1d14 |
end
|
|
|
cc1d14 |
diff --git a/lib/sass/rails/template.rb b/lib/sass/rails/template.rb
|
|
|
cc1d14 |
index 9def8d7..be7ccca 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 => Sprockets::SassImporter.new(context.pathname.to_s),
|
|
|
cc1d14 |
- :load_paths => context.environment.paths.map { |path| Sprockets::SassImporter.new(path.to_s) },
|
|
|
cc1d14 |
+ :importer => SassImporter.new(context.pathname.to_s),
|
|
|
cc1d14 |
+ :load_paths => context.environment.paths.map { |path| SassImporter.new(path.to_s) },
|
|
|
cc1d14 |
:sprockets => {
|
|
|
cc1d14 |
:context => context,
|
|
|
cc1d14 |
:environment => context.environment
|
|
|
cc1d14 |
--
|
|
|
cc1d14 |
1.9.3
|
|
|
cc1d14 |
|