Skip to content

Instantly share code, notes, and snippets.

@illoyd
Last active August 29, 2015 14:12
Show Gist options
  • Save illoyd/5aeddfddc013d9eac63c to your computer and use it in GitHub Desktop.
Save illoyd/5aeddfddc013d9eac63c to your computer and use it in GitHub Desktop.
Bootstrap and Rails Helpers
##
# Prefix a string with an icon
def iconify(label, icon, options = {})
"#{ icon(icon, options) } #{ label }".strip.html_safe
end
##
# Create a label
def llabel(text, kind = :default)
content_tag(:span, text, class: [ 'label', "label-#{ kind }" ].compact)
end
##
# Create a font-awesome icon
def icon( kind = :blank, options = {} )
kind = ICONS.fetch(kind, kind.to_s.gsub(/_/, '-'))
options[:class] = [ 'fa', "fa-#{kind}", options[:class] ].compact
content_tag(:i, '', options)
end
def favorite_icon(toggle)
icon(toggle ? :star : 'star-o')
end
##
# Create a Glyphicon icon
def icon( kind = :blank, options = {} )
kind = ICONS.fetch(kind, kind.to_s.gsub(/_/, '-'))
options[:class] = [ 'glyphicon', "glyphicon-#{kind}", options[:class] ].compact
content_tag(:i, '', options)
end
def favorite_icon(toggle)
icon(toggle ? :star : 'star-empty')
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment