diff options
author | Joshua Peek <josh@joshpeek.com> | 2008-07-14 17:40:03 -0500 |
---|---|---|
committer | Joshua Peek <josh@joshpeek.com> | 2008-07-14 17:40:58 -0500 |
commit | 9dc258d6147c8dab772d1f041098a38389cd3e73 (patch) | |
tree | 01f14b0fbc7c74b0a87bfbcb0bb9a20835ecac9e /actionpack/lib/action_view/renderable_partial.rb | |
parent | 76df9fa0680d62ce41fa6f3b743c605101d101d2 (diff) | |
download | rails-9dc258d6147c8dab772d1f041098a38389cd3e73.tar.gz rails-9dc258d6147c8dab772d1f041098a38389cd3e73.tar.bz2 rails-9dc258d6147c8dab772d1f041098a38389cd3e73.zip |
Eager load Partial variable_name and counter_name. Tidy up render_partial_collection.
Diffstat (limited to 'actionpack/lib/action_view/renderable_partial.rb')
-rw-r--r-- | actionpack/lib/action_view/renderable_partial.rb | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/actionpack/lib/action_view/renderable_partial.rb b/actionpack/lib/action_view/renderable_partial.rb index 6a17b50a14..250b4e1624 100644 --- a/actionpack/lib/action_view/renderable_partial.rb +++ b/actionpack/lib/action_view/renderable_partial.rb @@ -3,16 +3,36 @@ module ActionView # NOTE: The template that this mixin is beening include into is frozen # So you can not set or modify any instance variables + def variable_name + @variable_name ||= name.gsub(/^_/, '').to_sym + end + + def counter_name + @counter_name ||= "#{variable_name}_counter".to_sym + end + + def freeze + # Eager load and freeze memoized methods + variable_name.freeze + counter_name.freeze + super + end + def render(view, local_assigns = {}) ActionController::Base.benchmark("Rendered #{path_without_format_and_extension}", Logger::DEBUG, false) do super end end - def render_partial(view, variable_name, object = nil, local_assigns = {}, as = nil) - object ||= view.controller.instance_variable_get("@#{variable_name}") if view.respond_to?(:controller) - local_assigns[:object] ||= local_assigns[variable_name] ||= object - local_assigns[as] ||= local_assigns[:object] if as + def render_partial(view, object = nil, local_assigns = {}, as = nil) + object ||= local_assigns[:object] || + local_assigns[variable_name] || + view.controller.instance_variable_get("@#{variable_name}") if view.respond_to?(:controller) + + # Ensure correct object is reassigned to other accessors + local_assigns[:object] = local_assigns[variable_name] = object + local_assigns[as] = object if as + render_template(view, local_assigns) end end |