lib/sprockets/sass/v3/importer.rb in sprockets-sass-2.0.0.beta1 vs lib/sprockets/sass/v3/importer.rb in sprockets-sass-2.0.0.beta2
- old
+ new
@@ -4,13 +4,13 @@
module Sass
module V3
# class used for importing files from SCCS and SASS files
class Importer < Sprockets::Sass::V2::Importer
GLOB = /\*|\[.+\]/
-
- protected
+ protected
+
def resolve_path_with_load_paths(context, path, root_path, file)
context.resolve(file.to_s, load_paths: context.environment.paths, base_path: root_path, accept: syntax_mime_type(path))
rescue
nil
end
@@ -41,14 +41,14 @@
context.content_type.nil? || available_mimes.include?(path_content_type) || available_mimes.include?(context.content_type)
end
def asset_requirable?(context, path)
pathname = begin
- context.resolve(path)
- rescue
- nil
- end
+ context.resolve(path)
+ rescue
+ nil
+ end
return false if pathname.nil?
stat = stat_of_pathname(context, pathname, path)
return false unless stat && stat.file?
check_context_content_types(context, path)
end
@@ -116,10 +116,11 @@
def call_processor_input(processor, context, input, processors)
metadata = (input[:metadata] || {}).dup
metadata[:data] = input[:data]
result = processor.call(input)
+ processors.delete(processor)
handle_process_result(context, result, processors, metadata)
end
def handle_complex_process_result(context, result, processors)
data = result[:data] if result.key?(:data)
@@ -135,18 +136,18 @@
end
def handle_process_result(context, result, processors, metadata)
data = nil
case result
- when NilClass
- data = metadata[:data]
- when Hash
- data = handle_complex_process_result(context, result, processors)
- when String
- data = result
- else
- raise Error, "invalid processor return type: #{result.class}"
+ when NilClass
+ data = metadata[:data]
+ when Hash
+ data = handle_complex_process_result(context, result, processors)
+ when String
+ data = result
+ else
+ raise Error, "invalid processor return type: #{result.class}"
end
data
end
# Internal: Run processors on filename and data.
@@ -154,11 +155,10 @@
# Returns Hash.
def process(processors, context, path)
path = check_path_before_process(context, path)
data = Sprockets::Sass::Utils.read_template_file(path.to_s)
input = build_input_for_process(context, path, data)
-
processors.each do |processor|
data = call_processor_input(processor, context, input, processors)
end
data
@@ -172,18 +172,30 @@
available_transformers = context.environment.transformers[content_type]
additional_transformers = available_transformers.key?(syntax_mime_type(path)) ? available_transformers[syntax_mime_type(path)] : []
additional_transformers.is_a?(Array) ? additional_transformers : [additional_transformers]
end
- def get_engines_from_attributes(_attributes)
- []
+ def get_engines_from_attributes(context, attributes)
+ engines = []
+ attributes[2].each do |extension|
+ ext = ::Sprockets::Utils.normalize_extension(extension)
+ ext_engines = context.environment.engines[ext]
+ ext_engines = ext_engines.is_a?(Array) ? ext_engines : [ext_engines]
+ engines.concat(ext_engines)
+ end
+ engines
end
def get_all_processors_for_evaluate(context, content_type, attributes, path)
- engines = get_engines_from_attributes(attributes)
+ engines = get_engines_from_attributes(context, attributes)
preprocessors = get_context_preprocessors(context, content_type)
additional_transformers = get_context_transformers(context, content_type, path)
- additional_transformers.reverse + preprocessors + engines.reverse
+ postprocessors = get_context_postprocessors(context, content_type)
+ engines.reverse + preprocessors + additional_transformers.reverse + postprocessors
+ end
+
+ def get_context_postprocessors(context, content_type)
+ context.environment.postprocessors[content_type].map { |a| a.class == Class ? a : a.class }
end
def filter_all_processors(processors)
processors.delete_if do |processor|
filtered_processor_classes.include?(processor) || filtered_processor_classes.any? do |filtered_processor|