Module: IconLink::ViewHelpers
- Defined in:
- lib/icon_link/view_helpers.rb
Instance Method Summary collapse
-
#icon_button_tag(title, options = {}) ⇒ Object
Creates a button tag with the given
titleto the givenurl. -
#icon_link_to(title, url, options = {}) ⇒ Object
Creates a link tag with the given
titleto the givenurl. -
#iconize(text, icon = nil) ⇒ Object
Adds icon to a given text.
Instance Method Details
#icon_button_tag(title, options = {}) ⇒ Object
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
("Example", icon: "comment-icon")
# => <button class="btn" type="submit"><i class="icon-comment"></i> Create model</button>
10 11 12 13 14 15 |
# File 'lib/icon_link/view_helpers.rb', line 10 def (title, ={}) [:type] ||= 'submit' .merge(icon: nil) do iconize(title, [:icon]) end end |
#icon_link_to(title, url, options = {}) ⇒ Object
Creates a link tag with the given title to the given url. Works like link_to, but takes an additional :icon option.
Examples
icon_link_to("Example", "http://www.example.com", icon: "comment-icon")
# => <a href="http://www.example.com" class="btn"><i class="icon-comment"></i> Title</a>
23 24 25 |
# File 'lib/icon_link/view_helpers.rb', line 23 def icon_link_to(title, url, = {}) link = link_to(iconize(title, [:icon]), url, .merge(icon: nil)) end |
#iconize(text, icon = nil) ⇒ Object
Adds icon to a given text
Examples
iconize("Example", icon: "comment-icon")
# => <i class="icon-comment"></i> Title
32 33 34 35 36 37 38 |
# File 'lib/icon_link/view_helpers.rb', line 32 def iconize(text, icon = nil) if icon.to_s.empty? text else content_tag(:i, nil, class: icon) + " " + text end end |