Last active
December 21, 2015 05:28
-
-
Save rposborne/6257024 to your computer and use it in GitHub Desktop.
A quick rails helper for creating bootstrap icons or fontawesome icons (v 2.3.2) It behaves as you would expect handling all HTML options.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#accepts array of string and symbols that will be prepended with 'icon-' | |
#any hashes will be passed into the content tag call and any additonal classes will be merge into the content_tag class as well | |
def bootstrap_icon(*args) | |
icon_words = [] | |
options = {} | |
args.each do |arg| | |
if arg.is_a?( String) || arg.is_a?(Symbol) | |
icon_words << arg | |
end | |
if arg.is_a?( Hash ) | |
options = options.merge arg | |
end | |
end | |
klasses = icon_words.map{|klass| "icon-#{klass}"} | |
options = options.merge( { class: [ klasses , options[:class].to_s].join(" ")} ) | |
content_tag(:i, "", options) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment