From 707663ad9dc33ae7159079ebae2dc5f0caf2a78b Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Wed, 2 May 2018 20:22:30 +0900 Subject: [PATCH] Deprecate safe_level of ERB.new in Ruby 2.6 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 --- benchmarks/erb_vs_erubis.rb | 2 +- benchmarks/template_erb.rb | 2 +- lib/yard/templates/template.rb | 6 +++++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/benchmarks/erb_vs_erubis.rb b/benchmarks/erb_vs_erubis.rb index 2c146107d..69cb16566 100644 --- a/benchmarks/erb_vs_erubis.rb +++ b/benchmarks/erb_vs_erubis.rb @@ -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 diff --git a/benchmarks/template_erb.rb b/benchmarks/template_erb.rb index 1457230d2..259772b17 100644 --- a/benchmarks/template_erb.rb +++ b/benchmarks/template_erb.rb @@ -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 diff --git a/lib/yard/templates/template.rb b/lib/yard/templates/template.rb index 2ba4c3e12..975be87c5 100644 --- a/lib/yard/templates/template.rb +++ b/lib/yard/templates/template.rb @@ -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