1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Fixed partials handling

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1169 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
David Heinemeier Hansson 2005-04-16 16:06:29 +00:00
parent 0baf344457
commit 82456d9392
2 changed files with 24 additions and 4 deletions

View file

@ -264,6 +264,7 @@ module ActionView #:nodoc:
def evaluate_locals(local_assigns = {})
b = binding
local_assigns.stringify_keys!
local_assigns.each { |key, value| eval "#{key} = local_assigns[\"#{key}\"]", b }
@assigns.each { |key, value| instance_variable_set "@#{key}", value }
xml = Builder::XmlMarkup.new(:indent => 2)

View file

@ -31,11 +31,12 @@ module ActionView
#
# This will render the partial "advertisement/_ad.rhtml" regardless of which controller this is being called from.
module Partials
def render_partial(partial_path, object = nil, local_assigns = {})
def render_partial(partial_path, local_assigns = {}, deprecated_local_assigns = {})
path, partial_name = partial_pieces(partial_path)
object ||= controller.instance_variable_get("@#{partial_name}")
counter_name = partial_counter_name(partial_name)
local_assigns = local_assigns.merge(counter_name => 1) unless local_assigns.has_key?(counter_name)
object = extracting_object(partial_name, local_assigns, deprecated_local_assigns)
local_assigns = extract_local_assigns(local_assigns, deprecated_local_assigns)
add_counter_to_local_assigns!(partial_name, local_assigns)
render("#{path}/_#{partial_name}", { partial_name => object }.merge(local_assigns))
end
@ -69,5 +70,23 @@ module ActionView
def partial_counter_name(partial_name)
"#{partial_name.split('/').last}_counter"
end
def extracting_object(partial_name, local_assigns, deprecated_local_assigns)
if local_assigns.is_a?(Hash) || local_assigns.nil?
controller.instance_variable_get("@#{partial_name}")
else
# deprecated form where object could be passed in as second parameter
local_assigns
end
end
def extract_local_assigns(local_assigns, deprecated_local_assigns)
local_assigns.is_a?(Hash) ? local_assigns : deprecated_local_assigns
end
def add_counter_to_local_assigns!(partial_name, local_assigns)
counter_name = partial_counter_name(partial_name)
local_assigns[counter_name] = 1 unless local_assigns.has_key?(counter_name)
end
end
end