Class: Telegram::Controller::Renderer

Inherits:
Object
  • Object
show all
Defined in:
lib/telegram/controller/renderer.rb

Instance Method Summary collapse

Constructor Details

#initialize(controller:, action:) ⇒ Renderer

Returns a new instance of Renderer.



15
16
17
# File 'lib/telegram/controller/renderer.rb', line 15

def initialize(controller:, action:)
  @controller, @action = controller, action
end

Instance Method Details

#render(opts = {}) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/telegram/controller/renderer.rb', line 20

def render opts = {}
  options = normalize_options(opts)
  view    = Controller::ViewObject.new(@controller.expose_instance_variables)
  template_file_name, response_format = resolve_template(options)

  template_body = File.read template_file_name
  template      = Erubis::Eruby.new(template_body)
  response_body = template.evaluate(view)

  [response_body, response_format]
end