Skip to content
This repository
Browse code

allow options to be passed to email address auto generation

Signed-off-by: Michael Koziarski <michael@koziarski.com>

[#1418 state:committed]
  • Loading branch information...
commit bda55f82c687920807f606a2b024f1882094ef1e 1 parent 25f6524
Andrew Kaspick authored November 19, 2008 NZKoz committed December 01, 2008
8  actionpack/lib/action_view/helpers/text_helper.rb
@@ -370,8 +370,8 @@ def auto_link(text, *args, &block)#link = :all, href_options = {}, &block)
370 370
         options.reverse_merge!(:link => :all, :html => {})
371 371
 
372 372
         case options[:link].to_sym
373  
-          when :all                         then auto_link_email_addresses(auto_link_urls(text, options[:html], &block), &block)
374  
-          when :email_addresses             then auto_link_email_addresses(text, &block)
  373
+          when :all                         then auto_link_email_addresses(auto_link_urls(text, options[:html], &block), options[:html], &block)
  374
+          when :email_addresses             then auto_link_email_addresses(text, options[:html], &block)
375 375
           when :urls                        then auto_link_urls(text, options[:html], &block)
376 376
         end
377 377
       end
@@ -559,7 +559,7 @@ def auto_link_urls(text, html_options = {})
559 559
 
560 560
         # Turns all email addresses into clickable links.  If a block is given,
561 561
         # each email is yielded and the result is used as the link text.
562  
-        def auto_link_email_addresses(text)
  562
+        def auto_link_email_addresses(text, html_options = {})
563 563
           body = text.dup
564 564
           text.gsub(/([\w\.!#\$%\-+.]+@[A-Za-z0-9\-]+(\.[A-Za-z0-9\-]+)+)/) do
565 565
             text = $1
@@ -568,7 +568,7 @@ def auto_link_email_addresses(text)
568 568
               text
569 569
             else
570 570
               display_text = (block_given?) ? yield(text) : text
571  
-              %{<a href="mailto:#{text}">#{display_text}</a>}
  571
+              mail_to text, display_text, html_options
572 572
             end
573 573
           end
574 574
         end
7  actionpack/test/template/text_helper_test.rb
@@ -262,6 +262,11 @@ def test_auto_linking
262 262
     email2_result = %{<a href="mailto:#{email2_raw}">#{email2_raw}</a>}
263 263
     assert_equal email2_result, auto_link(email2_raw)
264 264
 
  265
+    email3_raw    = '+david@loudthinking.com'
  266
+    email3_result = %{<a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;+%64%61%76%69%64@%6c%6f%75%64%74%68%69%6e%6b%69%6e%67.%63%6f%6d">#{email3_raw}</a>}
  267
+    assert_equal email3_result, auto_link(email3_raw, :all, :encode => :hex)
  268
+    assert_equal email3_result, auto_link(email3_raw, :email_addresses, :encode => :hex)
  269
+
265 270
     link2_raw    = 'www.rubyonrails.com'
266 271
     link2_result = generate_result(link2_raw, "http://#{link2_raw}")
267 272
     assert_equal %(Go to #{link2_result}), auto_link("Go to #{link2_raw}", :urls)
@@ -362,7 +367,7 @@ def test_auto_link_with_block
362 367
   end
363 368
 
364 369
   def test_auto_link_with_options_hash
365  
-    assert_dom_equal 'Welcome to my new blog at <a href="http://www.myblog.com/" class="menu" target="_blank">http://www.myblog.com/</a>. Please e-mail me at <a href="mailto:me@email.com">me@email.com</a>.',
  370
+    assert_dom_equal 'Welcome to my new blog at <a href="http://www.myblog.com/" class="menu" target="_blank">http://www.myblog.com/</a>. Please e-mail me at <a href="mailto:me@email.com" class="menu" target="_blank">me@email.com</a>.',
366 371
       auto_link("Welcome to my new blog at http://www.myblog.com/. Please e-mail me at me@email.com.",
367 372
                 :link => :all, :html => { :class => "menu", :target => "_blank" })
368 373
   end

0 notes on commit bda55f8

Please sign in to comment.
Something went wrong with that request. Please try again.