Skip to content

Commit

Permalink
allow options to be passed to email address auto generation
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Koziarski <michael@koziarski.com>

[rails#1418 state:committed]
  • Loading branch information
akaspick authored and NZKoz committed Dec 1, 2008
1 parent 25f6524 commit bda55f8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
8 changes: 4 additions & 4 deletions actionpack/lib/action_view/helpers/text_helper.rb
Expand Up @@ -370,8 +370,8 @@ def auto_link(text, *args, &block)#link = :all, href_options = {}, &block)
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
Expand Down Expand Up @@ -559,7 +559,7 @@ def auto_link_urls(text, html_options = {})

# 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
Expand All @@ -568,7 +568,7 @@ def auto_link_email_addresses(text)
text
else
display_text = (block_given?) ? yield(text) : text
%{<a href="mailto:#{text}">#{display_text}</a>}
mail_to text, display_text, html_options
end
end
end
Expand Down
7 changes: 6 additions & 1 deletion actionpack/test/template/text_helper_test.rb
Expand Up @@ -262,6 +262,11 @@ def test_auto_linking
email2_result = %{<a href="mailto:#{email2_raw}">#{email2_raw}</a>}
assert_equal email2_result, auto_link(email2_raw)

email3_raw = '+david@loudthinking.com'
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>}
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)
Expand Down Expand Up @@ -362,7 +367,7 @@ def test_auto_link_with_block
end

def test_auto_link_with_options_hash
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>.',
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>.',
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
Expand Down

0 comments on commit bda55f8

Please sign in to comment.