Skip to content

Commit

Permalink
return empty string if no class set
Browse files Browse the repository at this point in the history
adding example for custom class definition
  • Loading branch information
mschneider85 committed Jan 14, 2017
1 parent 07e9ac2 commit f165095
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/helpers/glyph_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ module GlyphHelper
# # => <i class="icon-thumbs-up pull-left"></i>
# glyph(:lock, {tag: :span})
# # => <span class="icon-lock"></span>
# glyph(:lock, {class: 'foo'})
# # => <i class="icon-lock foo"></i>
def glyph(*names)
options = names.last.kind_of?(Hash) ? names.pop : {}
names.map! { |name| name.to_s.tr('_', '-') }
names.map! do |name|
name =~ /pull-(?:left|right)/ ? name : "glyphicon glyphicon-#{name}"
end
options[:tag] = options[:tag] ||= :i
names.push options[:class]
names.push options[:class] || ''
content_tag options[:tag], nil, class: names
end
end

0 comments on commit f165095

Please sign in to comment.