Skip to content

Commit

Permalink
Merge pull request #919 from mschneider85/master
Browse files Browse the repository at this point in the history
Adding support for glyph helper custom classes
  • Loading branch information
seyhunak authored Jan 16, 2017
2 parents d3776dd + f165095 commit a62817e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,8 @@ Glyph:
<%= glyph(:pencil) %> <i class="icon-pencil"></i>
<%= glyph(:pencil, {tag: :span}) %> <span class="icon-pencil"></span>
<%= glyph(:pencil, {class: 'foo'}) %> <i class="icon-pencil foo"></i>
```

### I18n Internationalization Support
Expand All @@ -616,7 +618,7 @@ Please see CONTRIBUTERS.md for contributors list


## About Me
Senior Software Developer @INGBank
Senior Software Developer @INGBank
Istanbul / Turkey


Expand Down
9 changes: 6 additions & 3 deletions app/helpers/glyph_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +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.gsub('_','-') }
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
content_tag options[:tag], nil, :class => names
names.push options[:class] || ''
content_tag options[:tag], nil, class: names
end
end

0 comments on commit a62817e

Please sign in to comment.