From b305756d9f5e92d0e1cf41c1036139a510882f1f Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Fri, 18 Feb 2005 14:06:36 +0000 Subject: Added TextHelper#auto_link, TextHelper#auto_link_urls, and TextHelper#auto_link_email_addresses to turn those elements into ahrefs git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@661 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/lib/action_view/helpers/text_helper.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'actionpack/lib/action_view') diff --git a/actionpack/lib/action_view/helpers/text_helper.rb b/actionpack/lib/action_view/helpers/text_helper.rb index cb5a4578ee..5002291cf2 100644 --- a/actionpack/lib/action_view/helpers/text_helper.rb +++ b/actionpack/lib/action_view/helpers/text_helper.rb @@ -96,6 +96,24 @@ 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') + end + # Turns all links into words, like "else" to "else". def strip_links(text) text.gsub(/(.*)<\/a>/m, '\1') -- cgit v1.2.3