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
  • Loading branch information
koic committed May 2, 2018
1 parent d6491b4 commit 707663a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion benchmarks/erb_vs_erubis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def erb_with(str, x) Erubis::TinyEruby.new(str) end
x.report("erb") do
eval <<-eof
module YARD; module Templates; module Template
def erb_with(str, x) ERB.new(str, nil) end
def erb_with(str, x) ERB.new(str) end
end end end
eof

Expand Down
2 changes: 1 addition & 1 deletion benchmarks/template_erb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module YARD
module Templates
module Template
def erb(section, &block)
erb = ERB.new(cache(section), nil)
erb = ERB.new(cache(section))
erb.filename = cache_filename(section).to_s
erb.result(binding, &block)
end
Expand Down
6 changes: 5 additions & 1 deletion lib/yard/templates/template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,11 @@ def erb_file_for(section)
end

def erb_with(content, filename = nil)
erb = ERB.new(content, nil, options.format == :text ? '<>' : nil)
erb = if ERB.instance_method(:initialize).parameters.assoc(:key) # Ruby 2.6+
ERB.new(content, :trim_mode => options.format == :text ? '<>' : nil)
else
ERB.new(content, nil, options.format == :text ? '<>' : nil)
end
erb.filename = filename if filename
erb
end
Expand Down

0 comments on commit 707663a

Please sign in to comment.