Skip to content

Commit d335aae

Browse files
author
Derek Hower
committed
Add render() to TemplateHelpers
1 parent c79a3a5 commit d335aae

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

lib/template_helpers.rb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1+
# frozen_string_literal: true
2+
13
# At this point, we insert a placeholder since it will be up
24
# to the backend to create a specific link.
35

6+
require "erb"
7+
require "pathname"
8+
9+
# collection of functions that can be used inside ERB templates
410
module TemplateHelpers
511
# Insert a hyperlink to an extension.
612
# @param name [#to_s] Name of the extension
@@ -65,4 +71,12 @@ def anchor_for_csr(name)
6571
def anchor_for_csr_field(csr_name, field_name)
6672
"[[csr_field-#{csr_name.gsub(".", "_")}-#{field_name.gsub(".", "_")}-def]]"
6773
end
68-
end
74+
75+
def render(template_path, locals = {})
76+
template_path = Pathname.new(template_path)
77+
erb = ERB.new(template)
78+
erb.filename = template_path.realpath
79+
80+
erb.result(OpenStruct.new(locals).instance_eval { binding })
81+
end
82+
end

0 commit comments

Comments
 (0)