aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/helpers/prototype_helper.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2006-02-12 20:10:59 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2006-02-12 20:10:59 +0000
commit8dc4f4623354b65a639ac3c8981e1c362801d722 (patch)
treeeb67d25728e0fb63d752c2e429a72fbbf9ecee6e /actionpack/lib/action_view/helpers/prototype_helper.rb
parentebdb766e7956520e9e5a784e280a8f1916f50511 (diff)
downloadrails-8dc4f4623354b65a639ac3c8981e1c362801d722.tar.gz
rails-8dc4f4623354b65a639ac3c8981e1c362801d722.tar.bz2
rails-8dc4f4623354b65a639ac3c8981e1c362801d722.zip
Also support replace and replace_html and some refactoring in JavaScriptElementProxy [DHH]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3588 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib/action_view/helpers/prototype_helper.rb')
-rw-r--r--actionpack/lib/action_view/helpers/prototype_helper.rb34
1 files changed, 26 insertions, 8 deletions
diff --git a/actionpack/lib/action_view/helpers/prototype_helper.rb b/actionpack/lib/action_view/helpers/prototype_helper.rb
index f0d2b405d2..ae68e21624 100644
--- a/actionpack/lib/action_view/helpers/prototype_helper.rb
+++ b/actionpack/lib/action_view/helpers/prototype_helper.rb
@@ -501,9 +501,9 @@ module ActionView
# page.insert_html :bottom, :partial => 'person', :object => @person
#
# # Replace an existing person
- # page.replace_element 'person_45', :partial => 'person', :object => @person
+ # page.replace 'person_45', :partial => 'person', :object => @person
#
- def replace_element(id, *options_for_render)
+ def replace(id, *options_for_render)
call 'Element.replace', id, render(*options_for_render)
end
@@ -672,16 +672,34 @@ module ActionView
@generator << root
end
- private
- def method_missing(method, *arguments)
- method_chain = @generator.instance_variable_get("@lines")
+ def assign(variable, value)
+ append_to_function_chain! "#{variable} = #{@generator.send(:javascript_object_for, value)}"
+ end
- last_method = method_chain[-1]
- method_chain[-1] = last_method[0..-2] if last_method[-1..-1] == ";" # strip trailing ; from last method call
- method_chain[-1] += ".#{method}(#{@generator.send(:arguments_for_call, arguments)});"
+ def replace_html(*options_for_render)
+ call 'update', @generator.render(*options_for_render)
+ end
+ def replace(*options_for_render)
+ call 'replace', @generator.render(*options_for_render)
+ end
+
+ private
+ def call(function, *arguments)
+ append_to_function_chain!("#{function}(#{@generator.send(:arguments_for_call, arguments)})")
self
end
+
+ alias_method :method_missing, :call
+
+ def function_chain
+ @function_chain ||= @generator.instance_variable_get("@lines")
+ end
+
+ def append_to_function_chain!(call)
+ function_chain[-1] = function_chain[-1][0..-2] if function_chain[-1][-1..-1] == ";" # strip last ;
+ function_chain[-1] += ".#{call};"
+ end
end
end
end