Browse Source

fa_icon_helper warn up when useless options

main
pvincent 5 months ago
parent
commit
75d8c3324f
  1. 36
      app/helpers/fa_icon_helper.rb
  2. 4
      app/views/scores/_score.html.erb
  3. 14
      config/initializers/rails_live_reload.rb

36
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

4
app/views/scores/_score.html.erb

@ -9,8 +9,8 @@
<td>
<% if action_name != "show" %>
<%= link_to score do %><%=fa_icon :eye, class: 'border rounded-2 mr-2' %>Show Score<% end %>
<%= link_to "Edit this score", edit_score_path(score), class: "rounded-lg py-3 ml-2 px-5 bg-gray-100 inline-block font-medium" %>
<%= link_to score do %><%=fa_icon :eye, stroke: :regular, size: '4x', class: 'border rounded-lg border-purple-800 m-1 p-2 bg-white' %>Show Score<% end %>
<%= link_to "Edit this score", edit_score_path(score), class: "rounded-xl border border-yellow-300 py-3 ml-2 px-5 bg-gray-100 inline-block font-medium" %>
<%= link_to "Edit this score", edit_score_path(score), class: "rounded-lg py-3 ml-2 px-5 bg-gray-100 inline-block font-medium" %>
<%= button_to "Destroy this score", score_path(score), method: :delete, class: "mt-2 rounded-lg py-3 px-5 bg-gray-100 font-medium" %>
<hr class="mt-6">

14
config/initializers/rails_live_reload.rb

@ -2,16 +2,16 @@
if defined?(RailsLiveReload) && Rails.env.development?
RailsLiveReload.configure do |config|
# Default watched folders & files
config.watch %r{app/views/.+\.(erb|haml|slim)$}
# Rk: prevent any reload for files ending with '.tailwind.css'
config.watch %r{(app|vendor)/(assets|javascript)/.+\.(css|js|html|png|jpg)(?<!tailwind\.css)$}, reload: :always
# HOT Constants
config.watch(%r{/\.env}, reload: :always)
# USEFUL for tailwind changes!!!!
config.watch %r{app/assets/builds/tailwind.css}, reload: :always
# HOT Constants
config.watch(%r{/\.env}, reload: :always)
# Rk: prevent any reload for files ending with '.tailwind.css'
config.watch %r{(app|vendor)/(assets|javascript)/.+\.(css|js|html|png|jpg)(?<!tailwind\.css)$}, reload: :always
# Default watched folders & files
config.watch %r{app/views/.+\.(erb|haml|slim)$}
end
end
Loading…
Cancel
Save