Skip to content

Commit

Permalink
Merge pull request puppetlabs#308 from danielparks/fix_erb
Browse files Browse the repository at this point in the history
(puppetlabs#302) Fix warnings generated by ERB.new
  • Loading branch information
chelnak authored Sep 26, 2022
2 parents c53a306 + 630b214 commit 02d29f2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
17 changes: 15 additions & 2 deletions lib/puppet-strings/markdown/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,9 @@ def word_wrap(text, line_width: 120, break_sequence: "\n")

# @return [String] full markdown rendering of a component
def render(template)
file = File.join(File.dirname(__FILE__), 'templates', template)
begin
file = File.join(File.dirname(__FILE__),"templates/#{template}")
ERB.new(File.read(file), nil, '-').result(binding)
PuppetStrings::Markdown.erb(file).result(binding)
rescue StandardError => e
fail "Processing #{@registry[:file]}:#{@registry[:line]} with #{file} => #{e}"
end
Expand All @@ -199,4 +199,17 @@ def clean_link(input)
input.tr('^a-zA-Z0-9_-', '-')
end
end

# Helper function to load an ERB template.
#
# @param [String] path The full path to the template file.
# @return [ERB] Template
def self.erb(path)
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.6.0')
ERB.new(File.read(path), trim_mode: '-')
else
# This outputs warnings in Ruby 2.6+.
ERB.new(File.read(path), nil, '-')
end
end
end
4 changes: 2 additions & 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,8 @@ 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)
template = File.join(File.dirname(__FILE__), 'templates/table_of_contents.erb')
final += PuppetStrings::Markdown.erb(template).result(binding)
end
final
end
Expand Down

0 comments on commit 02d29f2

Please sign in to comment.