Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ignoring onclick html_safe for link_to_function/button_to_function #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 48 additions & 47 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions lib/prototype-rails/javascript_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
Expand Down
22 changes: 21 additions & 1 deletion test/javascript_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ def test_link_to_function_with_rjs_block
assert_dom_equal %(<a href="#" onclick="Element.update(&quot;header&quot;, &quot;\\u003Ch1\\u003EGreetings\\u003C/h1\\u003E&quot;);; return false;">Greet me!</a>), html
end

def test_link_to_function_with_html_safe_onclick
assert_dom_equal %(<a href="#" onclick="alert('Hello world!'); ; return false;">Greeting</a>),
link_to_function( "Greeting", onclick: "alert('Hello world!')".html_safe)
end

def test_link_to_function_without_html_safe_onclick
assert_dom_equal %(<a href="#" onclick="alert(&#x27;Hello world!&#x27;); ; return false;">Greeting</a>),
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', "<h1>Greetings</h1>"
Expand All @@ -52,10 +62,20 @@ def test_button_to_function_with_rjs_block
assert_dom_equal %(<input type="button" onclick="Element.update(&quot;header&quot;, &quot;\\u003Ch1\\u003EGreetings\\u003C/h1\\u003E&quot;);;" value="Greet me!" />), html
end

def test_button_to_function_with_html_safe_onclick
assert_dom_equal %(<input type="button" onclick="alert('Hello world!'); ;" value="Greeting" />),
button_to_function( "Greeting", onclick: "alert('Hello world!')".html_safe)
end

def test_button_to_function_without_html_safe_onclick
assert_dom_equal %(<input type="button" onclick="alert(&#x27;Hello world!&#x27;); ;" value="Greeting" />),
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', "<h1>Greetings</h1>"
end
assert_dom_equal %(<input type="button" class="greeter" onclick="Element.update(&quot;header&quot;, &quot;\\u003Ch1\\u003EGreetings\\u003C\/h1\\u003E&quot;);;" value="Greet me!" />), html
end
end
end