Class: ActionView::PartialTemplate

Inherits:
Template show all
Defined in:
lib/action_view/partial_template.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Attributes inherited from Template

#extension, #filename, #handler, #locals, #method, #path, #path_without_extension

Instance Method Summary collapse

Methods inherited from Template

#base_path_for_exception, #method_key, #prepare!, #render_template, #source

Constructor Details

#initialize(view, partial_path, object = nil, locals = {}) ⇒ PartialTemplate

Returns a new instance of PartialTemplate.



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/action_view/partial_template.rb', line 6

def initialize(view, partial_path, object = nil, locals = {})
  @path, @variable_name = extract_partial_name_and_path(view, partial_path)
  super(view, @path, true, locals)
  add_object_to_local_assigns!(object)

  # This is needed here in order to compile template with knowledge of 'counter'
  initialize_counter
  
  # Prepare early. This is a performance optimization for partial collections
  prepare!
end

Instance Attribute Details

#objectObject (readonly)

Returns the value of attribute object.



4
5
6
# File 'lib/action_view/partial_template.rb', line 4

def object
  @object
end

#variable_nameObject (readonly)

Returns the value of attribute variable_name.



4
5
6
# File 'lib/action_view/partial_template.rb', line 4

def variable_name
  @variable_name
end

Instance Method Details

#counter=(num) ⇒ Object



35
36
37
# File 'lib/action_view/partial_template.rb', line 35

def counter=(num)
  @locals[@counter_name] = num
end

#renderObject



18
19
20
21
22
# File 'lib/action_view/partial_template.rb', line 18

def render
  ActionController::Base.benchmark("Rendered #{@path}", Logger::DEBUG, false) do
    @handler.render(self)
  end
end

#render_member(object) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/action_view/partial_template.rb', line 24

def render_member(object)
  @locals[:object] = @locals[@variable_name] = object
  
  template = render_template
  @locals[@counter_name] += 1
  @locals.delete(@variable_name)
  @locals.delete(:object)
  
  template
end