public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
allow options to be passed to email address auto generation

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

[#1418 state:committed]
Andrew Kaspick (author)
Wed Nov 19 10:55:27 -0800 2008
NZKoz (committer)
Mon Dec 01 10:27:03 -0800 2008
commit  bda55f82c687920807f606a2b024f1882094ef1e
tree    953bce745ee12b86bf471814ff7adf54548da393
parent  25f6524b89900378d08de9ec45757813dbb650cf
...
370
371
372
373
374
 
 
375
376
377
...
559
560
561
562
 
563
564
565
...
568
569
570
571
 
572
573
574
...
370
371
372
 
 
373
374
375
376
377
...
559
560
561
 
562
563
564
565
...
568
569
570
 
571
572
573
574
0
@@ -370,8 +370,8 @@ module ActionView
0
         options.reverse_merge!(:link => :all, :html => {})
0
 
0
         case options[:link].to_sym
0
-          when :all                         then auto_link_email_addresses(auto_link_urls(text, options[:html], &block), &block)
0
-          when :email_addresses             then auto_link_email_addresses(text, &block)
0
+          when :all                         then auto_link_email_addresses(auto_link_urls(text, options[:html], &block), options[:html], &block)
0
+          when :email_addresses             then auto_link_email_addresses(text, options[:html], &block)
0
           when :urls                        then auto_link_urls(text, options[:html], &block)
0
         end
0
       end
0
@@ -559,7 +559,7 @@ module ActionView
0
 
0
         # Turns all email addresses into clickable links.  If a block is given,
0
         # each email is yielded and the result is used as the link text.
0
-        def auto_link_email_addresses(text)
0
+        def auto_link_email_addresses(text, html_options = {})
0
           body = text.dup
0
           text.gsub(/([\w\.!#\$%\-+.]+@[A-Za-z0-9\-]+(\.[A-Za-z0-9\-]+)+)/) do
0
             text = $1
0
@@ -568,7 +568,7 @@ module ActionView
0
               text
0
             else
0
               display_text = (block_given?) ? yield(text) : text
0
-              %{<a href="mailto:#{text}">#{display_text}</a>}
0
+              mail_to text, display_text, html_options
0
             end
0
           end
0
         end
...
262
263
264
 
 
 
 
 
265
266
267
...
362
363
364
365
 
366
367
368
...
262
263
264
265
266
267
268
269
270
271
272
...
367
368
369
 
370
371
372
373
0
@@ -262,6 +262,11 @@ class TextHelperTest < ActionView::TestCase
0
     email2_result = %{<a href="mailto:#{email2_raw}">#{email2_raw}</a>}
0
     assert_equal email2_result, auto_link(email2_raw)
0
 
0
+    email3_raw    = '+david@loudthinking.com'
0
+    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>}
0
+    assert_equal email3_result, auto_link(email3_raw, :all, :encode => :hex)
0
+    assert_equal email3_result, auto_link(email3_raw, :email_addresses, :encode => :hex)
0
+
0
     link2_raw    = 'www.rubyonrails.com'
0
     link2_result = generate_result(link2_raw, "http://#{link2_raw}")
0
     assert_equal %(Go to #{link2_result}), auto_link("Go to #{link2_raw}", :urls)
0
@@ -362,7 +367,7 @@ class TextHelperTest < ActionView::TestCase
0
   end
0
 
0
   def test_auto_link_with_options_hash
0
-    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>.',
0
+    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>.',
0
       auto_link("Welcome to my new blog at http://www.myblog.com/. Please e-mail me at me@email.com.",
0
                 :link => :all, :html => { :class => "menu", :target => "_blank" })
0
   end

Comments