7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/tasks/bunko/helpers.rb', line 7
def render_template(template_name, locals = {})
template_path = File.expand_path("../templates/#{template_name}", __dir__)
unless File.exist?(template_path)
raise "Template file not found: #{template_path}"
end
template_content = File.read(template_path)
context = Object.new
locals.each do |key, value|
context.define_singleton_method(key) { value }
end
ERB.new(template_content, trim_mode: "-").result(context.instance_eval { binding })
end
|