Permalink
Browse files

Added access to nested attributes in RJS (closes #4548) [richcollins@…

…gmail.com]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5004 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent bf8b101 commit 1d4d037b0d74fbc3c1cad1c192a6ea7278aff081 @dhh dhh committed Sep 4, 2006
View
@@ -1,5 +1,12 @@
*SVN*
+* Added access to nested attributes in RJS #4548 [richcollins@gmail.com]. Examples:
+
+ page['foo']['style'] # => $('foo').style;
+ page['foo']['style']['color'] # => $('blank_slate').style.color;
+ page['foo']['style']['color'] = 'red' # => $('blank_slate').style.color = 'red';
+ page['foo']['style'].color = 'red' # => $('blank_slate').style.color = 'red';
+
* Fixed that AssetTagHelper#image_tag and others using compute_public_path should not modify the incoming source argument (closes #5102) [eule@space.ch]
* Deprecated the auto-appending of .png to AssetTagHelper#image_tag calls that doesn't have an extension [DHH]
@@ -777,6 +777,21 @@ def initialize(generator, id)
super(generator, "$(#{id.to_json})")
end
+ # Allows access of element attributes through +attribute+. Examples:
+ #
+ # page['foo']['style'] # => $('foo').style;
+ # page['foo']['style']['color'] # => $('blank_slate').style.color;
+ # page['foo']['style']['color'] = 'red' # => $('blank_slate').style.color = 'red';
+ # page['foo']['style'].color = 'red' # => $('blank_slate').style.color = 'red';
+ def [](attribute)
+ append_to_function_chain!(attribute)
+ self
+ end
+
+ def []=(variable, value)
+ assign(variable, value)
+ end
+
def replace_html(*options_for_render)
call 'update', @generator.send(:render, *options_for_render)
end
@@ -262,6 +262,16 @@ def test_element_proxy_one_deep
@generator['hello'].hide
assert_equal %($("hello").hide();), @generator.to_s
end
+
+ def test_element_proxy_variable_access
+ @generator['hello']['style']
+ assert_equal %($("hello").style;), @generator.to_s
+ end
+
+ def test_element_proxy_variable_access_with_assignment
+ @generator['hello']['style']['color'] = 'red'
+ assert_equal %($("hello").style.color = "red";), @generator.to_s
+ end
def test_element_proxy_assignment
@generator['hello'].width = 400

0 comments on commit 1d4d037

Please sign in to comment.