Module: Viewaide::Helpers::LinkHelper

Included in:
Viewaide::Helpers
Defined in:
lib/viewaide/helpers/link_helper.rb

Instance Method Summary collapse

Instance Method Details

Generates a link that’s able to be styled like a button. This functions exactly like Rails’ #link_to but wraps the link text in a span and assigns a class of “btn”

Examples:

<%= link_button "Text", root_path %>
generates
<a href="/" class="btn"><span>Text</span></a>
<%= link_button "Text", root_path, :class => "extra" %>
generates
<a href="/" class="btn extra"><span>Text</span></a>

Parameters:

  • (*Args)

Returns:

  • (String)


20
21
22
23
24
25
# File 'lib/viewaide/helpers/link_helper.rb', line 20

def link_button(*args, &block)
  doc = Hpricot(link_to(*args, &block))
  doc.at("a").inner_html = "<span>#{doc.at("a").inner_html}</span>"
  (doc/:a).add_class("btn")
  doc.to_html
end

Generates a link to an email address. This functions exactly like Rails’ #link_to but changes the href to include “mailto:”

Examples:

<%= link_to_email "[email protected]" %>
generates
<a href="mailto:[email protected]">abc@def.com</a>
<%= link_to_email "[email protected]", "John Doe" %>
generates
<a href="mailto:[email protected]">John Doe</a>
<%= link_to_email "[email protected]", "John Doe", :class => "extra" %>
generates
<a href="mailto:[email protected]" class="extra">John Doe</a>

Parameters:

  • email_address (String)

    the email address for the link

  • (*Args)

Returns:

  • (String)


46
47
48
49
50
51
# File 'lib/viewaide/helpers/link_helper.rb', line 46

def link_to_email(email_address, *args)
  options = args.extract_options!
  link = args.first.is_a?(String) ? h(args.first) : email_address
  return link if email_address.blank?
  link_to link, "mailto:#{email_address}", options
end