diff --git a/actionpack/lib/action_view/helpers/text_helper.rb b/actionpack/lib/action_view/helpers/text_helper.rb
index ae65a1c2bd..26a8b74faa 100644
--- a/actionpack/lib/action_view/helpers/text_helper.rb
+++ b/actionpack/lib/action_view/helpers/text_helper.rb
@@ -96,22 +96,19 @@ module ActionView
# We can't really help what's not there
end
- # Turns all urls and email addresses into clickable links. Example:
- # "Go to http://www.rubyonrails.com and say hello to david@loudthinking.com" =>
- # Go to http://www.rubyonrails.com and
- # say hello to david@loudthinking.com
- def auto_link(text)
- auto_link_urls(auto_link_email_addresses(text))
- end
-
- # Turns all urls into clickable links.
- def auto_link_urls(text)
- text.gsub(/([^=>\3\4\5\6\7')
- end
-
- # Turns all email addresses into clickable links.
- def auto_link_email_addresses(text)
- text.gsub(/([\w\.!#\$%\-+.]+@[A-Za-z0-9\-]+(\.[A-Za-z0-9\-]+)+)/, '\1')
+ # Turns all urls and email addresses into clickable links. The +link+ parameter can limit what should be linked.
+ # Options are :all (default), :email_addresses, and :urls.
+ #
+ # Example:
+ # auto_link("Go to http://www.rubyonrails.com and say hello to david@loudthinking.com") =>
+ # Go to http://www.rubyonrails.com and
+ # say hello to david@loudthinking.com
+ def auto_link(text, link = :all)
+ case link
+ when :all then auto_link_urls(auto_link_email_addresses(text))
+ when :email_addresses then auto_link_email_addresses(text)
+ when :urls then auto_link_urls(text)
+ end
end
# Turns all links into words, like "else" to "else".
@@ -124,6 +121,16 @@ module ActionView
def escape_regexp(text)
text.gsub(/([\\|?+*\/\)\(])/) { |m| "\\#{$1}" }
end
+
+ # Turns all urls into clickable links.
+ def auto_link_urls(text)
+ text.gsub(/([^=>\3\4\5\6\7')
+ end
+
+ # Turns all email addresses into clickable links.
+ def auto_link_email_addresses(text)
+ text.gsub(/([\w\.!#\$%\-+.]+@[A-Za-z0-9\-]+(\.[A-Za-z0-9\-]+)+)/, '\1')
+ end
end
end
end
\ No newline at end of file