Add a helper for fixed-width icons

This commit is contained in:
Dan Rice 2016-02-14 21:58:23 -05:00
parent 73a6925054
commit 1dfdad96fe
2 changed files with 28 additions and 0 deletions

View file

@ -0,0 +1,15 @@
module IconHelper
include FontAwesome::Sass::Rails::ViewHelpers
def icon_fw(icon, text = nil, html_options = {})
text, html_options = nil, text if text.is_a?(Hash)
if html_options.key?(:class)
html_options[:class] = "fa-fw #{html_options[:class]}"
else
html_options[:class] = "fa-fw"
end
icon(icon, text, html_options)
end
end

View file

@ -0,0 +1,13 @@
require 'test_helper'
class IconHelperTest < ActionView::TestCase
include IconHelper
test 'icon_fw generates fixed-width class' do
assert_equal '<i class="fa fa-gear fa-fw"></i>', icon_fw('gear')
end
test 'icon_fw accepts an additional class' do
assert_equal '<i class="fa fa-gear fa-fw myclass"></i>', icon_fw('gear', class: 'myclass')
end
end