lib/pdk/template/renderer/v1/template_file.rb in pdk-2.7.1 vs lib/pdk/template/renderer/v1/template_file.rb in pdk-3.0.0
- old
+ new
@@ -18,13 +18,11 @@
#
# @api public
def initialize(template_file, data = {})
@template_file = template_file
- if data.key?(:configs)
- @configs = data[:configs]
- end
+ @configs = data[:configs] if data.key?(:configs)
super(data)
end
# Renders the template by calling the appropriate engine based on the file
@@ -63,15 +61,13 @@
# @raise [ArgumentError] If the template file does not exist or can not be
# read.
#
# @api private
def template_content
- if PDK::Util::Filesystem.file?(@template_file) && PDK::Util::Filesystem.readable?(@template_file)
- return PDK::Util::Filesystem.read_file(@template_file)
- end
+ return PDK::Util::Filesystem.read_file(@template_file) if PDK::Util::Filesystem.file?(@template_file) && PDK::Util::Filesystem.readable?(@template_file)
- raise ArgumentError, "'%{template}' is not a readable file" % { template: @template_file }
+ raise ArgumentError, format("'%{template}' is not a readable file", template: @template_file)
end
# Renders the content of the template file as an ERB template.
#
# @return [String] The rendered template.
@@ -80,10 +76,10 @@
#
# @api private
def render_erb
require 'erb'
- renderer = ERB.new(template_content, nil, '-')
+ renderer = ERB.new(template_content, trim_mode: '-')
renderer.filename = @template_file
renderer.result(binding)
end
# Renders the content of the template file as plain text.