diff --git a/Gemfile.lock b/Gemfile.lock index b014b46..e7f0194 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -7,85 +7,86 @@ PATH GEM remote: http://rubygems.org/ specs: - actionmailer (3.2.0) - actionpack (= 3.2.0) - mail (~> 2.4.0) - actionpack (3.2.0) - activemodel (= 3.2.0) - activesupport (= 3.2.0) + actionmailer (3.2.11) + actionpack (= 3.2.11) + mail (~> 2.4.4) + actionpack (3.2.11) + activemodel (= 3.2.11) + activesupport (= 3.2.11) builder (~> 3.0.0) erubis (~> 2.7.0) - journey (~> 1.0.0) + journey (~> 1.0.4) rack (~> 1.4.0) - rack-cache (~> 1.1) + rack-cache (~> 1.2) rack-test (~> 0.6.1) - sprockets (~> 2.1.2) - activemodel (3.2.0) - activesupport (= 3.2.0) + sprockets (~> 2.2.1) + activemodel (3.2.11) + activesupport (= 3.2.11) builder (~> 3.0.0) - activerecord (3.2.0) - activemodel (= 3.2.0) - activesupport (= 3.2.0) - arel (~> 3.0.0) + activerecord (3.2.11) + activemodel (= 3.2.11) + activesupport (= 3.2.11) + arel (~> 3.0.2) tzinfo (~> 0.3.29) - activeresource (3.2.0) - activemodel (= 3.2.0) - activesupport (= 3.2.0) - activesupport (3.2.0) + activeresource (3.2.11) + activemodel (= 3.2.11) + activesupport (= 3.2.11) + activesupport (3.2.11) i18n (~> 0.6) multi_json (~> 1.0) - arel (3.0.0) - builder (3.0.0) + arel (3.0.2) + builder (3.0.4) erubis (2.7.0) hike (1.2.1) - i18n (0.6.0) - journey (1.0.0) - json (1.6.5) - mail (2.4.1) + i18n (0.6.1) + journey (1.0.4) + json (1.7.6) + mail (2.4.4) i18n (>= 0.4.0) mime-types (~> 1.16) treetop (~> 1.4.8) metaclass (0.0.1) - mime-types (1.17.2) - mocha (0.10.3) + mime-types (1.19) + mocha (0.13.1) metaclass (~> 0.0.1) - multi_json (1.0.4) + multi_json (1.5.0) polyglot (0.3.3) - rack (1.4.1) - rack-cache (1.1) + rack (1.4.4) + rack-cache (1.2) rack (>= 0.4) rack-ssl (1.3.2) rack - rack-test (0.6.1) + rack-test (0.6.2) rack (>= 1.0) - rails (3.2.0) - actionmailer (= 3.2.0) - actionpack (= 3.2.0) - activerecord (= 3.2.0) - activeresource (= 3.2.0) - activesupport (= 3.2.0) + rails (3.2.11) + actionmailer (= 3.2.11) + actionpack (= 3.2.11) + activerecord (= 3.2.11) + activeresource (= 3.2.11) + activesupport (= 3.2.11) bundler (~> 1.0) - railties (= 3.2.0) - railties (3.2.0) - actionpack (= 3.2.0) - activesupport (= 3.2.0) + railties (= 3.2.11) + railties (3.2.11) + actionpack (= 3.2.11) + activesupport (= 3.2.11) rack-ssl (~> 1.3.2) rake (>= 0.8.7) rdoc (~> 3.4) - thor (~> 0.14.6) - rake (0.9.2.2) + thor (>= 0.14.6, < 2.0) + rake (10.0.3) rdoc (3.12) json (~> 1.4) - sprockets (2.1.2) + sprockets (2.2.2) hike (~> 1.2) + multi_json (~> 1.0) rack (~> 1.0) tilt (~> 1.1, != 1.3.0) - thor (0.14.6) + thor (0.16.0) tilt (1.3.3) - treetop (1.4.10) + treetop (1.4.12) polyglot polyglot (>= 0.3.1) - tzinfo (0.3.31) + tzinfo (0.3.35) PLATFORMS ruby diff --git a/lib/prototype-rails/javascript_helper.rb b/lib/prototype-rails/javascript_helper.rb index 39806d9..4260fd7 100644 --- a/lib/prototype-rails/javascript_helper.rb +++ b/lib/prototype-rails/javascript_helper.rb @@ -32,6 +32,7 @@ def button_to_function(name, *args, &block) function = block_given? ? update_page(&block) : args[0] || '' onclick = "#{"#{html_options[:onclick]}; " if html_options[:onclick]}#{function};" + onclick = onclick.html_safe if html_options[:onclick].html_safe? tag(:input, html_options.merge(:type => 'button', :value => name, :onclick => onclick)) end @@ -58,6 +59,8 @@ def link_to_function(name, *args, &block) function = block_given? ? update_page(&block) : args[0] || '' onclick = "#{"#{html_options[:onclick]}; " if html_options[:onclick]}#{function}; return false;" + onclick = onclick.html_safe if html_options[:onclick].html_safe? + href = html_options[:href] || '#' content_tag(:a, name, html_options.merge(:href => href, :onclick => onclick)) diff --git a/test/javascript_helper_test.rb b/test/javascript_helper_test.rb index c79b067..3d99794 100644 --- a/test/javascript_helper_test.rb +++ b/test/javascript_helper_test.rb @@ -29,6 +29,16 @@ def test_link_to_function_with_rjs_block assert_dom_equal %(Greet me!), html end + def test_link_to_function_with_html_safe_onclick + assert_dom_equal %(Greeting), + link_to_function( "Greeting", onclick: "alert('Hello world!')".html_safe) + end + + def test_link_to_function_without_html_safe_onclick + assert_dom_equal %(Greeting), + link_to_function( "Greeting", onclick: "alert('Hello world!')") + end + def test_link_to_function_with_rjs_block_and_options html = link_to_function( "Greet me!", :class => "updater" ) do |page| page.replace_html 'header', "

Greetings

" @@ -52,10 +62,20 @@ def test_button_to_function_with_rjs_block assert_dom_equal %(), html end + def test_button_to_function_with_html_safe_onclick + assert_dom_equal %(), + button_to_function( "Greeting", onclick: "alert('Hello world!')".html_safe) + end + + def test_button_to_function_without_html_safe_onclick + assert_dom_equal %(), + button_to_function( "Greeting", onclick: "alert('Hello world!')") + end + def test_button_to_function_with_rjs_block_and_options html = button_to_function( "Greet me!", :class => "greeter" ) do |page| page.replace_html 'header', "

Greetings

" end assert_dom_equal %(), html end -end \ No newline at end of file +end