Skip to content

Commit

Permalink
Avoid using Sprockets::Utils.module_include in SasscProcessor if …
Browse files Browse the repository at this point in the history
…possible
  • Loading branch information
ntkme committed Jan 2, 2024
1 parent 3dfec04 commit 284092a
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions lib/sprockets/sassc_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ 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] || {}
@include_module_functions = Gem::Version.new(Autoload::SassC::VERSION) < Gem::Version.new('2.3.0')
@functions = Module.new do
include Functions
include options[:functions] if options[:functions]
Expand All @@ -54,17 +53,16 @@ def call(input)
context = input[:environment].context_class.new(input)

options = engine_options(input, context)
options[:functions] = @functions
engine = Autoload::SassC::Engine.new(input[:data], options)

css = if @include_module_functions
Utils.module_include(Autoload::SassC::Script::Functions, @functions) do
engine.render
end
else
engine.render
end
css = css.sub(/^\n^\/\*# sourceMappingURL=.*\*\/$/m, '')
css = if Gem::Version.new(Autoload::SassC::VERSION) < Gem::Version.new('2.3.0')
Utils.module_include(Autoload::SassC::Script::Functions, @functions) do
engine.render
end
else
@functions.singleton_class.prepend(Autoload::SassC::Script::Functions)
engine.render
end.sub(/^\n^\/\*# sourceMappingURL=.*\*\/$/m, '')

begin
map = SourceMapUtils.format_source_map(JSON.parse(engine.source_map), input)
Expand Down Expand Up @@ -282,6 +280,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

0 comments on commit 284092a

Please sign in to comment.