From 3ccb5c500186941f1f64b9df50e3b26f33cafbab Mon Sep 17 00:00:00 2001 From: Andrew Kaspick Date: Wed, 19 Nov 2008 12:55:27 -0600 Subject: [PATCH] allow options to be passed to email address auto generation --- actionpack/lib/action_view/helpers/text_helper.rb | 8 ++++---- actionpack/test/template/text_helper_test.rb | 7 ++++++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/actionpack/lib/action_view/helpers/text_helper.rb b/actionpack/lib/action_view/helpers/text_helper.rb index 510c1a6..e4b02b3 100644 --- a/actionpack/lib/action_view/helpers/text_helper.rb +++ b/actionpack/lib/action_view/helpers/text_helper.rb @@ -380,8 +380,8 @@ module ActionView options.reverse_merge!(:link => :all, :html => {}) case options[:link].to_sym - when :all then auto_link_email_addresses(auto_link_urls(text, options[:html], &block), &block) - when :email_addresses then auto_link_email_addresses(text, &block) + when :all then auto_link_email_addresses(auto_link_urls(text, options[:html], &block), options[:html], &block) + when :email_addresses then auto_link_email_addresses(text, options[:html], &block) when :urls then auto_link_urls(text, options[:html], &block) end end @@ -569,7 +569,7 @@ module ActionView # Turns all email addresses into clickable links. If a block is given, # each email is yielded and the result is used as the link text. - def auto_link_email_addresses(text) + def auto_link_email_addresses(text, html_options = {}) body = text.dup text.gsub(/([\w\.!#\$%\-+.]+@[A-Za-z0-9\-]+(\.[A-Za-z0-9\-]+)+)/) do text = $1 @@ -578,7 +578,7 @@ module ActionView text else display_text = (block_given?) ? yield(text) : text - %{#{display_text}} + mail_to text, display_text, html_options end end end diff --git a/actionpack/test/template/text_helper_test.rb b/actionpack/test/template/text_helper_test.rb index 3e7a8f3..a6200fb 100644 --- a/actionpack/test/template/text_helper_test.rb +++ b/actionpack/test/template/text_helper_test.rb @@ -262,6 +262,11 @@ class TextHelperTest < ActionView::TestCase email2_result = %{#{email2_raw}} assert_equal email2_result, auto_link(email2_raw) + email3_raw = '+david@loudthinking.com' + email3_result = %{#{email3_raw}} + assert_equal email3_result, auto_link(email3_raw, :all, :encode => :hex) + assert_equal email3_result, auto_link(email3_raw, :email_addresses, :encode => :hex) + link2_raw = 'www.rubyonrails.com' link2_result = generate_result(link2_raw, "http://#{link2_raw}") assert_equal %(Go to #{link2_result}), auto_link("Go to #{link2_raw}", :urls) @@ -362,7 +367,7 @@ class TextHelperTest < ActionView::TestCase end def test_auto_link_with_options_hash - assert_dom_equal 'Welcome to my new blog at http://www.myblog.com/. Please e-mail me at me@email.com.', + assert_dom_equal 'Welcome to my new blog at http://www.myblog.com/. Please e-mail me at me@email.com.', auto_link("Welcome to my new blog at http://www.myblog.com/. Please e-mail me at me@email.com.", :link => :all, :html => { :class => "menu", :target => "_blank" }) end -- 1.5.4.3