Class: Alephant::Renderer
- Inherits:
-
Object
- Object
- Alephant::Renderer
- Defined in:
- lib/alephant/models/renderer.rb
Instance Attribute Summary collapse
-
#template_file ⇒ Object
readonly
Returns the value of attribute template_file.
Instance Method Summary collapse
-
#initialize(template_file, base_path, model) ⇒ Renderer
constructor
A new instance of Renderer.
- #render ⇒ Object
- #template ⇒ Object
Constructor Details
#initialize(template_file, base_path, model) ⇒ Renderer
Returns a new instance of Renderer.
8 9 10 11 12 13 14 |
# File 'lib/alephant/models/renderer.rb', line 8 def initialize(template_file, base_path, model) @logger = ::Alephant.logger @template_file = template_file @base_path = base_path @model = model @logger.info("Renderer.initialize: end with @base_path set to #{@base_path}") end |
Instance Attribute Details
#template_file ⇒ Object (readonly)
Returns the value of attribute template_file.
6 7 8 |
# File 'lib/alephant/models/renderer.rb', line 6 def template_file @template_file end |
Instance Method Details
#render ⇒ Object
16 17 18 19 20 |
# File 'lib/alephant/models/renderer.rb', line 16 def render @logger.info("Renderer.render: rendered template #{template_file}") Mustache.render(template, @model) end |
#template ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/alephant/models/renderer.rb', line 22 def template template_location = File.join(@base_path, 'templates', "#{template_file}.mustache") begin @logger.info("Renderer.template: #{template_location}") File.open(template_location).read rescue Exception => e @logger.error("Renderer.template: view template #{template_file} not found") raise Errors::ViewTemplateNotFound end end |