aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/helpers/text_helper.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-06-16 06:00:18 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-06-16 06:00:18 +0000
commit5b3bc3139a1b15054f26092eb95a5fbc8fdc07aa (patch)
tree9e098012ea0a05c0b4a2fdb8518c06543e8d71ae /actionpack/lib/action_view/helpers/text_helper.rb
parenta3659d583586d45c5f48fdd103ff8c797cecfafe (diff)
downloadrails-5b3bc3139a1b15054f26092eb95a5fbc8fdc07aa.tar.gz
rails-5b3bc3139a1b15054f26092eb95a5fbc8fdc07aa.tar.bz2
rails-5b3bc3139a1b15054f26092eb95a5fbc8fdc07aa.zip
Added a third parameter to TextHelper#auto_link called href_options for specifying additional tag options on the links generated #1401 [tyler.kovacs@gmail.com]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1432 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib/action_view/helpers/text_helper.rb')
-rw-r--r--actionpack/lib/action_view/helpers/text_helper.rb13
1 files changed, 8 insertions, 5 deletions
diff --git a/actionpack/lib/action_view/helpers/text_helper.rb b/actionpack/lib/action_view/helpers/text_helper.rb
index 0abd8e79fa..a65a979343 100644
--- a/actionpack/lib/action_view/helpers/text_helper.rb
+++ b/actionpack/lib/action_view/helpers/text_helper.rb
@@ -1,3 +1,5 @@
+require File.dirname(__FILE__) + '/tag_helper'
+
module ActionView
module Helpers #:nodoc:
# Provides a set of methods for working with text strings that can help unburden the level of inline Ruby code in the
@@ -116,11 +118,11 @@ module ActionView
# auto_link("Go to http://www.rubyonrails.com and say hello to david@loudthinking.com") =>
# Go to <a href="http://www.rubyonrails.com">http://www.rubyonrails.com</a> and
# say hello to <a href="mailto:david@loudthinking.com">david@loudthinking.com</a>
- def auto_link(text, link = :all)
+ def auto_link(text, link = :all, href_options = {})
case link
- when :all then auto_link_urls(auto_link_email_addresses(text))
+ when :all then auto_link_urls(auto_link_email_addresses(text), href_options)
when :email_addresses then auto_link_email_addresses(text)
- when :urls then auto_link_urls(text)
+ when :urls then auto_link_urls(text, href_options)
end
end
@@ -191,13 +193,14 @@ module ActionView
end
# Turns all urls into clickable links.
- def auto_link_urls(text)
+ def auto_link_urls(text, href_options = {})
text.gsub(/(<\w+.*?>|[^=!:'"\/]|^)((?:http[s]?:\/\/)|(?:www\.))([^\s<]+\/?)([[:punct:]]|\s|<|$)/) do
all, a, b, c, d = $&, $1, $2, $3, $4
if a =~ /<a\s/i # don't replace URL's that are already linked
all
else
- %(#{a}<a href="#{b=="www."?"http://www.":b}#{c}">#{b}#{c}</a>#{d})
+ extra_options = tag_options(href_options.stringify_keys) || ""
+ %(#{a}<a href="#{b=="www."?"http://www.":b}#{c}"#{extra_options}>#{b}#{c}</a>#{d})
end
end
end