Skip to content

Commit 630b214

Browse files
danielparkschelnak
authored andcommitted
(#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 c53a306 commit 630b214

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
@@ -172,9 +172,9 @@ def word_wrap(text, line_width: 120, break_sequence: "\n")
172172

173173
# @return [String] full markdown rendering of a component
174174
def render(template)
175+
file = File.join(File.dirname(__FILE__), 'templates', template)
175176
begin
176-
file = File.join(File.dirname(__FILE__),"templates/#{template}")
177-
ERB.new(File.read(file), nil, '-').result(binding)
177+
PuppetStrings::Markdown.erb(file).result(binding)
178178
rescue StandardError => e
179179
fail "Processing #{@registry[:file]}:#{@registry[:line]} with #{file} => #{e}"
180180
end
@@ -199,4 +199,17 @@ def clean_link(input)
199199
input.tr('^a-zA-Z0-9_-', '-')
200200
end
201201
end
202+
203+
# Helper function to load an ERB template.
204+
#
205+
# @param [String] path The full path to the template file.
206+
# @return [ERB] Template
207+
def self.erb(path)
208+
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.6.0')
209+
ERB.new(File.read(path), trim_mode: '-')
210+
else
211+
# This outputs warnings in Ruby 2.6+.
212+
ERB.new(File.read(path), nil, '-')
213+
end
214+
end
202215
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)