Method: Init::Renderer#render
- Defined in:
- lib/bundles/inspec-init/renderer.rb
#render(template_content, hash) ⇒ Object
This is a render helper to bind hash values to a ERB template ERB provides result_with_hash in ruby 2.5.0+, which does exactly this
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/bundles/inspec-init/renderer.rb', line 63 def render(template_content, hash) # create a new binding class cls = Class.new do hash.each do |key, value| define_method key.to_sym do value end end # expose binding define_method :bind do binding end end ERB.new(template_content).result(cls.new.bind) end |