d92ff1b8d3f16034c35b2d1d115b227e6412a191
[depot.git] / renderable_partial.rb
1 module ActionView
2 # NOTE: The template that this mixin is being included into is frozen
3 # so you cannot set or modify any instance variables
4 module RenderablePartial #:nodoc:
5 extend ActiveSupport::Memoizable
6
7 def variable_name
8 name.sub(/\A_/, '').to_sym
9 end
10 memoize :variable_name
11
12 def counter_name
13 "#{variable_name}_counter".to_sym
14 end
15 memoize :counter_name
16
17 def render(view, local_assigns = {})
18 if defined? ActionController
19 ActionController::Base.benchmark("Rendered #{path_without_format_and_extension}", Logger::DEBUG, false) do
20 super
21 end
22 else
23 super
24 end
25 end
26
27 def render_partial(view, object = nil, local_assigns = {}, as = nil)
28 object ||= local_assigns[:object] ||
29 local_assigns[variable_name]
30
31 if view.respond_to?(:controller)
32 ivar = :"@#{variable_name}"
33 object ||=
34 if view.controller.instance_variable_defined?(ivar)
35 ActiveSupport::Deprecation::DeprecatedObjectProxy.new(
36 view.controller.instance_variable_get(ivar),
37 "#{ivar} will no longer be implicitly assigned to #{variable_name}")
38 end
39 end
40
41 # Ensure correct object is reassigned to other accessors
42 local_assigns[:object] = local_assigns[variable_name] = object
43 local_assigns[as] = object if as
44
45 render_template(view, local_assigns)
46 end
47 end
48 end