diff --git a/app/helpers/fa_icon_helper.rb b/app/helpers/fa_icon_helper.rb index 6c5d99b..f60d313 100644 --- a/app/helpers/fa_icon_helper.rb +++ b/app/helpers/fa_icon_helper.rb @@ -1,18 +1,42 @@ # Font Awesome Helper module FaIconHelper - # accept name without 'fa-' prefix, style: (solid by default), size:, class: and 'aria-hidden': + ## + # mandatory: + # name: without 'fa-' prefix + # might be a symbol, automatic conversion of undashed symbol + # for instance symbol :magnify_lens is converted to string 'magnify-lens' + # optional: + # stroke: [:solid|:regular|:brands] solid as default value + # size: [2x, 3x, ... ] + # class: extra classes, any tailwind keyword... + # aria-hidden: true as default value + # + # example: + # fa_icon(:user) + # fa_icon(:user, stroke: :regular) + # fa_icon(:user, size: '2x') + # fa_icon(:user, class: 'text-blue-500') + ## def fa_icon(name, html_options = {}) - html_options[:style] ||= :solid - html_options['aria-hidden'] ||= true + warn_useless_options html_options - content_class = "fa-#{to_dash(html_options[:style])} fa-#{to_dash(name)}" - content_class << " fa-#{to_dash(html_options[:size])}" if html_options.key? :size + icon = to_dash(name) + stroke = to_dash(html_options[:stroke] || :solid) + + content_class = "fa-#{icon} fa-#{stroke}" + content_class << " fa-#{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']) + tag.i(class: content_class, 'aria-hidden': html_options['aria-hidden'] || true) end private def to_dash(symbol) = symbol.to_s.dasherize + + def warn_useless_options(hash) + hash.except(:stroke, :size, :class, 'aria-hidden').each_key do |key| + SemanticLogger[Module.nesting[0]].warn "useless option <#{key}>, please consider removal for safety reason!" + end + end end diff --git a/app/views/scores/_score.html.erb b/app/views/scores/_score.html.erb index 4f753d5..b65c5af 100644 --- a/app/views/scores/_score.html.erb +++ b/app/views/scores/_score.html.erb @@ -9,8 +9,8 @@