Class: Tipsy::View::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/tipsy/view/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request, response) ⇒ Base

Returns a new instance of Base.



7
8
9
10
11
# File 'lib/tipsy/view/base.rb', line 7

def initialize(request, response)
  @request  = request
  @response = response
  @lookup_context = Tipsy::View::Path.new        
end

Instance Attribute Details

#lookup_contextObject (readonly)

Returns the value of attribute lookup_context.



5
6
7
# File 'lib/tipsy/view/base.rb', line 5

def lookup_context
  @lookup_context
end

#requestObject (readonly)

Returns the value of attribute request.



5
6
7
# File 'lib/tipsy/view/base.rb', line 5

def request
  @request
end

#responseObject (readonly)

Returns the value of attribute response.



5
6
7
# File 'lib/tipsy/view/base.rb', line 5

def response
  @response
end

#templateObject (readonly)

Returns the value of attribute template.



5
6
7
# File 'lib/tipsy/view/base.rb', line 5

def template
  @template
end

#view_contextObject (readonly)

Returns the value of attribute view_context.



5
6
7
# File 'lib/tipsy/view/base.rb', line 5

def view_context
  @view_context
end

Instance Method Details

#renderObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/tipsy/view/base.rb', line 13

def render
  started   = Time.now
  @template = lookup_context.locate_template(current_path)       
  
  if template.nil?
    return generate_response(nil)
  end
  
  @view_context = Tipsy::View::Context.new(request, lookup_context, File.dirname(template), lookup_context)
  handler  = Tilt[template]
  tilt     = handler.new(template, nil, :outvar => '@output_buffer')      
  result   = tilt.render(view_context)
  
  unless view_context.layout == false
    layout = lookup_context.locate_layout(view_context.layout) 
    raise Tipsy::View::LayoutMissing.new("Missing layout '#{view_context.layout}'") and return if layout.nil?
    wrapped = Tilt[layout].new(layout, nil, :outvar => '@output_buffer')          
    result  = wrapped.render(view_context) do |*args|
      result
    end
    #puts "Rendered #{local_path(template)} within #{local_path(layout)} (#{time_diff(started, Time.now)}ms)"
  else
    #puts "Rendered #{local_path(template)} (#{time_diff(started, Time.now)}ms)"
  end
  
  generate_response(result)
  
end