Class: Proforma::HtmlRenderer::ObjectWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/proforma/html_renderer/object_writer.rb

Overview

Each object should have its own ERB template. This class understands the connection of objects and templates and knows how to render the template for the respective object passed in.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(names_by_class: {}, writer: Writer.new) ⇒ ObjectWriter

Returns a new instance of ObjectWriter.



20
21
22
23
# File 'lib/proforma/html_renderer/object_writer.rb', line 20

def initialize(names_by_class: {}, writer: Writer.new)
  @names_by_class = names_by_class
  @writer         = writer
end

Instance Attribute Details

#names_by_classObject (readonly)

Returns the value of attribute names_by_class.



18
19
20
# File 'lib/proforma/html_renderer/object_writer.rb', line 18

def names_by_class
  @names_by_class
end

#writerObject (readonly)

Returns the value of attribute writer.



18
19
20
# File 'lib/proforma/html_renderer/object_writer.rb', line 18

def writer
  @writer
end

Instance Method Details

#render(object, options = {}) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/proforma/html_renderer/object_writer.rb', line 25

def render(object, options = {})
  writer.render(
    resolve_name(object),
    object: object,
    options: options
  )
end