From dfe0015c11dae575abab0faacb9c40242bd38700 Mon Sep 17 00:00:00 2001 From: pvincent Date: Mon, 24 Jun 2024 23:40:06 +0400 Subject: [PATCH] fa_icon desymbolize --- app/helpers/icon_helper.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/helpers/icon_helper.rb b/app/helpers/icon_helper.rb index c816db6..c2738a7 100644 --- a/app/helpers/icon_helper.rb +++ b/app/helpers/icon_helper.rb @@ -1,13 +1,18 @@ # Font Awesome Helper module IconHelper + # accept name without 'fa-' prefix, style: (solid by default), size:, class: and 'aria-hidden': def fa_icon(name, html_options = {}) html_options[:style] ||= :solid html_options['aria-hidden'] ||= true - content_class = "fa-#{html_options[:style].to_s.dasherize} fa-#{name.to_s.dasherize}" - content_class << " fa-#{html_options[:size].to_s.dasherize}" if html_options.key? :size + content_class = "fa-#{unsymbolize(html_options[:style])} fa-#{unsymbolize(name)}" + content_class << " fa-#{unsymbolize(html_options[:size])}" if html_options.key? :size content_class << " #{html_options[:class]}" if html_options.key? :class tag.i(class: content_class, 'aria-hidden': html_options['aria-hidden']) end + + private + + def unsymbolize(symbol) = symbol.to_s.dasherize end