Skip to content

Instantly share code, notes, and snippets.

@rposborne
Last active December 21, 2015 05:28
Show Gist options
  • Save rposborne/6257024 to your computer and use it in GitHub Desktop.
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.
#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