Module: Kreegerator::Renderable
- Included in:
- IOS
- Defined in:
- lib/kreegerator/renderable.rb
Overview
This module uses the amazing Tilt library to give the ability to render a template in the ‘lib/filemover/templates` directory to any including class.
Instance Method Summary collapse
-
#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.
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.
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/kreegerator/renderable.rb', line 16 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 |