module IconLink::ViewHelpers

Public Instance Methods

icon_button_tag(title, options={}) click to toggle source

Creates a button tag with the given title to the given url. Works like button_tag, but takes an additional :icon option. Type is set to submit by default.

Examples

icon_button_tag("Example", icon: "icon-comment")
# => <button class="btn" type="submit"><i class="icon-comment"></i> Create model</button>
# File lib/icon_link/view_helpers.rb, line 10
def icon_button_tag(title, options={})
  options[:type] ||= 'submit'
  button_tag options.merge(icon: nil) do
    iconize(title, options[:icon])
  end
end
icon_for(icon) click to toggle source

Returns <i class=“your-icon”></i>

Examples

icon_for("icon-comment")
# => <i class="icon-comment"></i>
# File lib/icon_link/view_helpers.rb, line 45
def icon_for(icon)
  content_tag(:i, nil, class: icon.to_s)
end
iconize(text, icon = nil) click to toggle source

Adds icon to a given text

Examples

iconize("Example", icon: "icon-comment")
# => <i class="icon-comment"></i> Title
# File lib/icon_link/view_helpers.rb, line 32
def iconize(text, icon = nil)
  if icon.to_s.empty?
    text
  else
    icon_for(icon) + " " + text
  end
end