Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid using Sprockets::Utils.module_include in SasscProcessor #798

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions lib/sprockets/sassc_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ def initialize(options = {}, &block)
@cache_key = "#{self.class.name}:#{VERSION}:#{Autoload::SassC::VERSION}:#{@cache_version}".freeze
@importer_class = options[:importer]
@sass_config = options[:sass_config] || {}
parameters_include_functions = parameters_include_functions?
@functions = Module.new do
include Autoload::SassC::Script::Functions if parameters_include_functions
include Functions
include options[:functions] if options[:functions]
class_eval(&block) if block_given?
Expand All @@ -55,9 +57,13 @@ def call(input)
options = engine_options(input, context)
engine = Autoload::SassC::Engine.new(input[:data], options)

css = Utils.module_include(Autoload::SassC::Script::Functions, @functions) do
engine.render.sub(/^\n^\/\*# sourceMappingURL=.*\*\/$/m, '')
end
css = if parameters_include_functions?
engine.render
else
Utils.module_include(Autoload::SassC::Script::Functions, @functions) do
engine.render
end
end.sub(/^\n^\/\*# sourceMappingURL=.*\*\/$/m, '')

begin
map = SourceMapUtils.format_source_map(JSON.parse(engine.source_map), input)
Expand Down Expand Up @@ -86,6 +92,15 @@ def merge_options(options)
options
end

def parameters_include_functions?
if defined?(@@parameters_include_functions)
@@parameters_include_functions
else
@@parameters_include_functions =
Autoload::SassC::FunctionsHandler.instance_method(:setup).parameters.include?([:key, :functions])
end
end

# Public: Functions injected into Sass context during Sprockets evaluation.
#
# This module may be extended to add global functionality to all Sprockets
Expand Down Expand Up @@ -275,6 +290,7 @@ def engine_options(input, context)
filename: input[:filename],
syntax: self.class.syntax,
load_paths: input[:environment].paths,
functions: @functions,
importer: @importer_class,
source_map_contents: false,
source_map_file: "#{input[:filename]}.map",
Expand Down