Skip to content

Commit 5e1a958

Browse files
committed
(#302) Fix warnings generated by ERB.new
This has to special case Ruby <2.6.0 since those versions will interpret the keyword argument as a hash passed as the second argument. Without this change running this code in Ruby 2.6+ will generate warnings about the parameters passed to `ERB.new`.
1 parent dba16ed commit 5e1a958

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

Diff for: lib/puppet-strings/markdown/base.rb

+15-2
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,9 @@ def word_wrap(text, line_width: 120, break_sequence: "\n")
181181

182182
# @return [String] full markdown rendering of a component
183183
def render(template)
184+
file = File.join(File.dirname(__FILE__), 'templates', template)
184185
begin
185-
file = File.join(File.dirname(__FILE__),"templates/#{template}")
186-
ERB.new(File.read(file), nil, '-').result(binding)
186+
PuppetStrings::Markdown.erb(file).result(binding)
187187
rescue StandardError => e
188188
fail "Processing #{@registry[:file]}:#{@registry[:line]} with #{file} => #{e}"
189189
end
@@ -196,4 +196,17 @@ def select_tags(name)
196196
tags.empty? ? nil : tags
197197
end
198198
end
199+
200+
# Helper function to load an ERB template.
201+
#
202+
# @param [String] path The full path to the template file.
203+
# @return [ERB] Template
204+
def self.erb(path)
205+
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.6.0')
206+
ERB.new(File.read(path), trim_mode: '-')
207+
else
208+
# This outputs warnings in Ruby 2.6+.
209+
ERB.new(File.read(path), nil, '-')
210+
end
211+
end
199212
end

Diff for: lib/puppet-strings/markdown/table_of_contents.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ def self.render
1717
group = toc
1818
priv = r.contains_private?
1919

20-
template = File.join(File.dirname(__FILE__),"templates/table_of_contents.erb")
21-
final += ERB.new(File.read(template), nil, '-').result(binding)
20+
template = File.join(File.dirname(__FILE__), 'templates/table_of_contents.erb')
21+
final += PuppetStrings::Markdown.erb(template).result(binding)
2222
end
2323
final
2424
end

0 commit comments

Comments
 (0)