Class: RackDispatch::TemplateHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/rack_dispatch/template_handler.rb

Instance Method Summary collapse

Constructor Details

#initialize(path, status: 200, content_type: 'text/html', error: nil) ⇒ TemplateHandler

Returns a new instance of TemplateHandler.



3
4
5
6
7
8
# File 'lib/rack_dispatch/template_handler.rb', line 3

def initialize(path, status: 200, content_type: 'text/html', error: nil)
  @path = File.expand_path(File.join('templates', path), Dir.pwd)
  @status = Integer(status)
  @content_type = String(content_type)
  @error = error
end

Instance Method Details

#callObject



10
11
12
13
14
15
16
17
18
# File 'lib/rack_dispatch/template_handler.rb', line 10

def call
  [
  @status,
  {
    'Content-Type' => @content_type,
  },
  [ERB.new(File.read(@path)).result(OpenStruct.new(template_variables).instance_eval { binding })],
  ]
end