Skip to content

Commit

Permalink
Merge pull request #732 from casperisfine/3.x-fix-erb-version-checking
Browse files Browse the repository at this point in the history
Better check for ERB keyword arguments
  • Loading branch information
rafaelfranca committed Jun 23, 2022
2 parents 4174470 + 7cfb0a0 commit f4d3dae
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/sprockets/erb_processor.rb
Expand Up @@ -18,8 +18,7 @@ def initialize(&block)
end

def call(input)
match = ERB.version.match(/\Aerb\.rb \[(?<version>[^ ]+) /)
if match && match[:version] >= "2.2.0" # Ruby 2.6+
if keyword_constructor? # Ruby 2.6+
engine = ::ERB.new(input[:data], trim_mode: '<>')
else
engine = ::ERB.new(input[:data], nil, '<>')
Expand All @@ -32,5 +31,12 @@ def call(input)
data = context._evaluate_template
context.metadata.merge(data: data)
end

private

def keyword_constructor?
return @keyword_constructor if defined? @keyword_constructor
@keyword_constructor = ::ERB.instance_method(:initialize).parameters.include?([:key, :trim_mode])
end
end
end

0 comments on commit f4d3dae

Please sign in to comment.