0
module ActionView #:nodoc:
0
class PartialTemplate < Template #:nodoc:
0
attr_reader :variable_name, :object
0
def initialize(view, partial_path, object = nil, locals = {})
0
- @path, @variable_name = extract_partial_name_and_path(view, partial_path)
0
+ @view_controller = view.controller if view.respond_to?(:controller)
0
+ set_path_and_variable_name!(partial_path)
0
super(view, @path, true, locals)
0
add_object_to_local_assigns!(object)
0
# This is needed here in order to compile template with knowledge of 'counter'
0
# Prepare early. This is a performance optimization for partial collections
0
ActionController::Base.benchmark("Rendered #{@path}", Logger::DEBUG, false) do
0
def render_member(object)
0
@locals[:object] = @locals[@variable_name] = object
0
template = render_template
0
@locals[@counter_name] += 1
0
@locals.delete(@variable_name)
0
@locals.delete(:object)
0
@locals[@counter_name] = num
0
+ def add_object_to_local_assigns!(object)
0
+ @locals[@variable_name] ||=
0
+ if object.is_a?(ActionView::Base::ObjectWrapper)
0
+ end || @view_controller.instance_variable_get("@#{variable_name}")
0
- def add_object_to_local_assigns!(object)
0
- @locals[@variable_name] ||=
0
- if object.is_a?(ActionView::Base::ObjectWrapper)
0
- end || @view.controller.instance_variable_get("@#{variable_name}")
0
- def extract_partial_name_and_path(view, partial_path)
0
- path, partial_name = partial_pieces(view, partial_path)
0
- [File.join(path, "_#{partial_name}"), partial_name.split('/').last.split('.').first.to_sym]
0
- def partial_pieces(view, partial_path)
0
- if partial_path.include?('/')
0
- return File.dirname(partial_path), File.basename(partial_path)
0
- return view.controller.class.controller_path, partial_path
0
+ def set_path_and_variable_name!(partial_path)
0
+ if partial_path.include?('/')
0
+ @variable_name = File.basename(partial_path)
0
+ @path = "#{File.dirname(partial_path)}/_#{@variable_name}"
0
+ elsif @view_controller
0
+ @variable_name = partial_path
0
+ @path = "#{@view_controller.class.controller_path}/_#{@variable_name}"
0
+ @variable_name = partial_path
0
+ @path = "_#{@variable_name}"
0
+ @variable_name = @variable_name.sub(/\..*$/, '').to_sym
0
+ def initialize_counter!
0
+ @counter_name ||= "#{@variable_name}_counter".to_sym
0
+ @locals[@counter_name] = 0
0
- def initialize_counter
0
- @counter_name ||= "#{@variable_name}_counter".to_sym
0
- @locals[@counter_name] = 0
Comments
No one has commented yet.