From 1dfdad96fe1bf0f47a3bbdf214f816896ad4346b Mon Sep 17 00:00:00 2001 From: Dan Rice Date: Sun, 14 Feb 2016 21:58:23 -0500 Subject: [PATCH] Add a helper for fixed-width icons --- app/helpers/icon_helper.rb | 15 +++++++++++++++ test/helpers/icon_helper_test.rb | 13 +++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 app/helpers/icon_helper.rb create mode 100644 test/helpers/icon_helper_test.rb diff --git a/app/helpers/icon_helper.rb b/app/helpers/icon_helper.rb new file mode 100644 index 00000000..3fb817fa --- /dev/null +++ b/app/helpers/icon_helper.rb @@ -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 diff --git a/test/helpers/icon_helper_test.rb b/test/helpers/icon_helper_test.rb new file mode 100644 index 00000000..5ab2e43f --- /dev/null +++ b/test/helpers/icon_helper_test.rb @@ -0,0 +1,13 @@ +require 'test_helper' + +class IconHelperTest < ActionView::TestCase + include IconHelper + + test 'icon_fw generates fixed-width class' do + assert_equal '', icon_fw('gear') + end + + test 'icon_fw accepts an additional class' do + assert_equal '', icon_fw('gear', class: 'myclass') + end +end