fa_icon_helper warn up when useless options
This commit is contained in:
@@ -1,18 +1,42 @@
|
|||||||
# Font Awesome Helper
|
# Font Awesome Helper
|
||||||
module FaIconHelper
|
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 = {})
|
def fa_icon(name, html_options = {})
|
||||||
html_options[:style] ||= :solid
|
warn_useless_options html_options
|
||||||
html_options['aria-hidden'] ||= true
|
|
||||||
|
|
||||||
content_class = "fa-#{to_dash(html_options[:style])} fa-#{to_dash(name)}"
|
icon = to_dash(name)
|
||||||
content_class << " fa-#{to_dash(html_options[:size])}" if html_options.key? :size
|
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
|
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
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def to_dash(symbol) = symbol.to_s.dasherize
|
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
|
end
|
||||||
|
|||||||
@@ -9,8 +9,8 @@
|
|||||||
|
|
||||||
<td>
|
<td>
|
||||||
<% if action_name != "show" %>
|
<% if action_name != "show" %>
|
||||||
<%= link_to score do %><%=fa_icon :eye, class: 'border rounded-2 mr-2' %>Show Score<% end %>
|
<%= 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-lg py-3 ml-2 px-5 bg-gray-100 inline-block font-medium" %>
|
<%= 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" %>
|
<%= 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" %>
|
<%= 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">
|
<hr class="mt-6">
|
||||||
|
|||||||
@@ -2,16 +2,16 @@
|
|||||||
|
|
||||||
if defined?(RailsLiveReload) && Rails.env.development?
|
if defined?(RailsLiveReload) && Rails.env.development?
|
||||||
RailsLiveReload.configure do |config|
|
RailsLiveReload.configure do |config|
|
||||||
# Default watched folders & files
|
# HOT Constants
|
||||||
config.watch %r{app/views/.+\.(erb|haml|slim)$}
|
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
|
|
||||||
|
|
||||||
# USEFUL for tailwind changes!!!!
|
# USEFUL for tailwind changes!!!!
|
||||||
config.watch %r{app/assets/builds/tailwind.css}, reload: :always
|
config.watch %r{app/assets/builds/tailwind.css}, reload: :always
|
||||||
|
|
||||||
# HOT Constants
|
# Rk: prevent any reload for files ending with '.tailwind.css'
|
||||||
config.watch(%r{/\.env}, reload: :always)
|
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
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user