Class: Alephant::Renderer

Inherits:
Object
  • Object
show all
Defined in:
lib/alephant/models/renderer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_fileObject (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

#renderObject



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

#templateObject



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