Skip to content

Commit

Permalink
Deprecate safe_level of ERB.new in Ruby 2.6
Browse files Browse the repository at this point in the history
The interface of `ERB.new` will change from Ruby 2.6.

> Add :trim_mode and :eoutvar keyword arguments to ERB.new.
> Now non-keyword arguments other than first one are softly deprecated
> and will be removed when Ruby 2.5 becomes EOL. [Feature #14256]

https://github.com/ruby/ruby/blob/2311087b685e8dc0f21f4a89875f25c22f5c39a9/NEWS#stdlib-updates-outstanding-ones-only

The following address is related Ruby's commit.
ruby/ruby@cc777d0

This PR uses `ERB.version` to switch `ERB.new` interface. Because Padrino
supports multiple Ruby versions, it need to use the appropriate interface.

Using `ERB.version` instead of `RUBY_VERSON` is based on the following
patch.
ruby/ruby#1826

This patch is built into Ruby.
ruby/ruby@40db89c
  • Loading branch information
koic committed Mar 14, 2018
1 parent 1800c02 commit 9bb45ff
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion padrino-helpers/lib/padrino/rendering/erb_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ def render(*args)
def prepare
@outvar = options[:outvar] || self.class.default_output_variable
options[:trim] = '<>' if !(options[:trim] == false) && (options[:trim].nil? || options[:trim] == true)
@engine = SafeERB.new(data, options[:safe], options[:trim], @outvar)

match = ERB.version.match(/\Aerb\.rb \[(?<version>[^ ]+) /)
@engine = if match && match[:version] >= '2.2.0' # Ruby 2.6+
SafeERB.new(data, trim_mode: options[:trim], eoutvar: @outvar)
else
SafeERB.new(data, options[:safe], options[:trim], @outvar)
end
end

def precompiled_preamble(locals)
Expand Down

0 comments on commit 9bb45ff

Please sign in to comment.