Class: RackDispatch::TemplateDestination

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

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ TemplateDestination

Returns a new instance of TemplateDestination.



3
4
5
# File 'lib/rack_dispatch/template_destination.rb', line 3

def initialize(path)
  @path = File.expand_path(File.join('templates', String(path)), Dir.pwd) + '.liquid'
end

Instance Method Details

#call(request, response) ⇒ Object



7
8
9
10
# File 'lib/rack_dispatch/template_destination.rb', line 7

def call(request, response)
  response['Content-Type'] = 'text/html'
  response.write(render(request.params))
end

#render(data = {}) ⇒ Object



12
13
14
# File 'lib/rack_dispatch/template_destination.rb', line 12

def render(data = {})
  Liquid::Template.parse(File.read(@path)).render(data)
end