Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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