Skip to content

Commit

Permalink
(puppetlabs#302) Fix warnings generated by ERB.new
Browse files Browse the repository at this point in the history
Unfortunately, this fix will not work with Ruby <2.6.0.
  • Loading branch information
danielparks committed Sep 25, 2022
1 parent dba16ed commit 2e48f1a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
12 changes: 10 additions & 2 deletions lib/puppet-strings/markdown/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,7 @@ def word_wrap(text, line_width: 120, break_sequence: "\n")
# @return [String] full markdown rendering of a component
def render(template)
begin
file = File.join(File.dirname(__FILE__),"templates/#{template}")
ERB.new(File.read(file), nil, '-').result(binding)
PuppetStrings::Markdown.erb(template).result(binding)
rescue StandardError => e
fail "Processing #{@registry[:file]}:#{@registry[:line]} with #{file} => #{e}"
end
Expand All @@ -196,4 +195,13 @@ def select_tags(name)
tags.empty? ? nil : tags
end
end

# Helper function to load an ERB template
#
# @param [String] template The template name, including the .erb suffix.
# @return [ERB] Template
def self.erb(template)
template_path = File.join(File.dirname(__FILE__), 'templates', template)
ERB.new(File.read(template_path), trim_mode: '-')
end
end
3 changes: 1 addition & 2 deletions lib/puppet-strings/markdown/table_of_contents.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ def self.render
group = toc
priv = r.contains_private?

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

0 comments on commit 2e48f1a

Please sign in to comment.