@@ -439,18 +439,29 @@ def link_to_if(condition, name, options = {}, html_options = {}, &block)
439
439
# mail_to "me@domain.com", "My email", cc: "ccaddress@domain.com",
440
440
# subject: "This is an example email"
441
441
# # => <a href="mailto:me@domain.com?cc=ccaddress@domain.com&subject=This%20is%20an%20example%20email">My email</a>
442
- def mail_to ( email_address , name = nil , html_options = { } )
443
- email_address = ERB ::Util . html_escape ( email_address )
444
-
442
+ #
443
+ # You can use a block as well if your link target is hard to fit into the name parameter. ERB example:
444
+ #
445
+ # <%= mail_to "me@domain.com" do %>
446
+ # <strong>Email me:</strong> <span>me@domain.com</span>
447
+ # <% end %>
448
+ # # => <a href="mailto:me@domain.com">
449
+ # <strong>Email me:</strong> <span>me@domain.com</span>
450
+ # </a>
451
+ def mail_to ( email_address , name = nil , html_options = { } , &block )
452
+ html_options , name = name , nil if block_given?
453
+ html_options ||= { }
445
454
html_options . stringify_keys!
446
455
456
+ email_address = ERB ::Util . html_escape ( email_address )
457
+
447
458
extras = %w{ cc bcc body subject } . map { |item |
448
459
option = html_options . delete ( item ) || next
449
460
"#{ item } =#{ Rack ::Utils . escape_path ( option ) } "
450
461
} . compact
451
462
extras = extras . empty? ? '' : '?' + ERB ::Util . html_escape ( extras . join ( '&' ) )
452
-
453
- content_tag "a" , name || email_address . html_safe , html_options . merge ( "href" => "mailto:#{ email_address } #{ extras } " . html_safe )
463
+
464
+ content_tag ( :a , name || email_address . html_safe , html_options . merge ( "href" => "mailto:#{ email_address } #{ extras } " . html_safe ) , & block )
454
465
end
455
466
456
467
# True if the current request URI was generated by the given +options+.
0 commit comments