Module: Kreegerator::Renderable

Included in:
IOS
Defined in:
lib/kreegerator/renderable.rb

Instance Method Summary collapse

Instance Method Details

#render(template, data) ⇒ Object

Accepts path to a template relative to ‘lib/filemover/templates` along with a hash and renders a template using the amazing and magical Tilt.

Parameters:

  • template (String)

    the relative path to the template, from ‘lib/filemover/templates`.

  • data (Hash)

    the hash of values to render. The keys will be sent to the template as instance variables ‘@like_this`.



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/kreegerator/renderable.rb', line 17

def render(template, data)

  # META! Assign instance variables to self using the hash passed in.
  data.each { |key, value| instance_variable_set "@#{key}", value }

  # Get the absolute template location relative to our template basepath.
  template_location = File.join(template_path, template)

  # Let Tilt do the rest. Also pass in `self` as that's the reference to
  # the object that holds our new, metaprogrammed `@instance_variables`.
  Tilt.new(template_location).render(self)
end