diff options
author | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2013-04-04 17:20:37 -0700 |
---|---|---|
committer | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2013-04-04 17:20:37 -0700 |
commit | aa3b6837b250db0a0df4c9779e0370e55ef3eb7f (patch) | |
tree | 7c4f243869cbc28dffeb692896becda640fe4abe /actionpack/lib/action_view/helpers/url_helper.rb | |
parent | 9e4c25e1b8108494b90ae33b578e64e6bfaac8e8 (diff) | |
parent | 4bb26dd7b298b08f53c7e157ddc19dc7febcf37e (diff) | |
download | rails-aa3b6837b250db0a0df4c9779e0370e55ef3eb7f.tar.gz rails-aa3b6837b250db0a0df4c9779e0370e55ef3eb7f.tar.bz2 rails-aa3b6837b250db0a0df4c9779e0370e55ef3eb7f.zip |
Merge pull request #10065 from spohlenz/mail_to_block
Add block support for the mail_to helper
Diffstat (limited to 'actionpack/lib/action_view/helpers/url_helper.rb')
-rw-r--r-- | actionpack/lib/action_view/helpers/url_helper.rb | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/actionpack/lib/action_view/helpers/url_helper.rb b/actionpack/lib/action_view/helpers/url_helper.rb index 775d93ed39..a1468b6e90 100644 --- a/actionpack/lib/action_view/helpers/url_helper.rb +++ b/actionpack/lib/action_view/helpers/url_helper.rb @@ -439,18 +439,29 @@ module ActionView # mail_to "me@domain.com", "My email", cc: "ccaddress@domain.com", # subject: "This is an example email" # # => <a href="mailto:me@domain.com?cc=ccaddress@domain.com&subject=This%20is%20an%20example%20email">My email</a> - def mail_to(email_address, name = nil, html_options = {}) - email_address = ERB::Util.html_escape(email_address) - + # + # You can use a block as well if your link target is hard to fit into the name parameter. ERB example: + # + # <%= mail_to "me@domain.com" do %> + # <strong>Email me:</strong> <span>me@domain.com</span> + # <% end %> + # # => <a href="mailto:me@domain.com"> + # <strong>Email me:</strong> <span>me@domain.com</span> + # </a> + def mail_to(email_address, name = nil, html_options = {}, &block) + html_options, name = name, nil if block_given? + html_options ||= {} html_options.stringify_keys! + email_address = ERB::Util.html_escape(email_address) + extras = %w{ cc bcc body subject }.map { |item| option = html_options.delete(item) || next "#{item}=#{Rack::Utils.escape_path(option)}" }.compact extras = extras.empty? ? '' : '?' + ERB::Util.html_escape(extras.join('&')) - - content_tag "a", name || email_address.html_safe, html_options.merge("href" => "mailto:#{email_address}#{extras}".html_safe) + + content_tag(:a, name || email_address.html_safe, html_options.merge("href" => "mailto:#{email_address}#{extras}".html_safe), &block) end # True if the current request URI was generated by the given +options+. |