Class: Racket::ViewCache

Inherits:
Object
  • Object
show all
Defined in:
lib/racket/view_cache.rb

Overview

Handles rendering in Racket applications.

Instance Method Summary collapse

Constructor Details

#initialize(layout_base_dir, template_base_dir) ⇒ ViewCache

Returns a new instance of ViewCache.



27
28
29
30
31
32
# File 'lib/racket/view_cache.rb', line 27

def initialize(layout_base_dir, template_base_dir)
  @layout_base_dir = layout_base_dir
  @template_base_dir = template_base_dir
  @layouts_by_path = {}
  @templates_by_path = {}
end

Instance Method Details

#render(controller) ⇒ Hash

Renders a controller based on the request path and the variables set in the controller instance.

Parameters:

Returns:

  • (Hash)


39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/racket/view_cache.rb', line 39

def render(controller)
  template =
    find_template(controller.request.path, controller.controller_option(:default_view))
  if template
    output = Tilt.new(template).render(controller)
    layout =
      find_layout(controller.request.path, controller.controller_option(:default_layout))
    output = Tilt.new(layout).render(controller) { output } if layout
  else
    output = controller.racket.action_result
  end
  controller.response.write(output)
  controller.response.finish
end