Method: Padrino::Helpers::AssetTagHelpers#mail_to

Defined in:
padrino-helpers/lib/padrino-helpers/asset_tag_helpers.rb

#mail_to(email, caption = nil, mail_options = {}) ⇒ String

Creates a mail link element with given name and caption.

Examples:

mail_to "me@demo.com"
# Generates: <a href="mailto:me@demo.com">me@demo.com</a>

mail_to "me@demo.com", "My Email"
# Generates: <a href="mailto:me@demo.com">My Email</a>

Parameters:

  • email (String)

    The email address for the link.

  • caption (String) (defaults to: nil)

    The caption for the link.

  • mail_options (Hash) (defaults to: {})

    The options for the mail link. Accepts html options.

Options Hash (mail_options):

  • cc (String)

    The cc recipients.

  • bcc (String)

    The bcc recipients.

  • subject (String)

    The subject line.

  • body (String)

    The email body.

Returns:

  • (String)

    Mail link html tag with specified options.

[View source] [View on GitHub]

145
146
147
148
149
150
151
# File 'padrino-helpers/lib/padrino-helpers/asset_tag_helpers.rb', line 145

def mail_to(email, caption=nil, mail_options={})
  mail_options, html_options = mail_options.partition{ |key,_| [:cc, :bcc, :subject, :body].include?(key) }
  mail_query = Rack::Utils.build_query(Hash[mail_options]).gsub(/\+/, '%20').gsub('%40', '@')
  mail_href = "mailto:#{email}"
  mail_href << "?#{mail_query}" unless mail_query.empty?
  link_to((caption || email), mail_href, Hash[html_options])
end