Class: Tipsy::View::Base
- Inherits:
-
Object
- Object
- Tipsy::View::Base
- Defined in:
- lib/tipsy/view/base.rb
Instance Attribute Summary collapse
-
#lookup_context ⇒ Object
readonly
Returns the value of attribute lookup_context.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#template ⇒ Object
readonly
Returns the value of attribute template.
-
#view_context ⇒ Object
readonly
Returns the value of attribute view_context.
Instance Method Summary collapse
-
#initialize(request, response) ⇒ Base
constructor
A new instance of Base.
- #render ⇒ Object
Constructor Details
Instance Attribute Details
#lookup_context ⇒ Object (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 |
#request ⇒ Object (readonly)
Returns the value of attribute request.
5 6 7 |
# File 'lib/tipsy/view/base.rb', line 5 def request @request end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
5 6 7 |
# File 'lib/tipsy/view/base.rb', line 5 def response @response end |
#template ⇒ Object (readonly)
Returns the value of attribute template.
5 6 7 |
# File 'lib/tipsy/view/base.rb', line 5 def template @template end |
#view_context ⇒ Object (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
#render ⇒ Object
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 |