utilisation d'un helper plutôt qu'un partiel

This commit is contained in:
Jérémy Lecour 2022-01-23 15:50:01 +01:00 committed by Jérémy Lecour
parent 78926f6a4c
commit 7dba35c320
3 changed files with 20 additions and 15 deletions

View File

@ -1,2 +1,18 @@
module ApplicationHelper
def colored_pill_tag(content_or_options_with_block = nil, options = nil, &block)
if block_given?
options = content_or_options_with_block if content_or_options_with_block.is_a?(Hash)
end
color = options.fetch(:color).presence || "gray"
classes = "px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-#{color}-100 text-#{color}-800"
if block_given?
content_tag(:span, class: classes, &block)
else
content_tag(:span, content_or_options_with_block, class: classes)
end
end
end

View File

@ -1,3 +0,0 @@
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-<%= (defined?(color) && color.presence) || "gray" %>-100 text-<%= (defined?(color) && color.presence) || "gray" %>-800">
<%= yield %>
</span>

View File

@ -53,24 +53,16 @@
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
<% if user.confirmed? %>
<%= render "shared/colored_pill", { color: "green" } do %>
Confirmed
<% end %>
<%= colored_pill_tag("Confirmed", color: "green") %>
<% else %>
<%= render "shared/colored_pill", { color: "yellow" } do %>
Unconfirmed
<% end %>
<%= colored_pill_tag("Unconfirmed", color: "yellow") %>
<% end %>
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
<% if user.admin? %>
<%= render "shared/colored_pill", { color: "green" } do %>
Yes
<% end %>
<%= colored_pill_tag("Yes", color: "green") %>
<% else %>
<%= render "shared/colored_pill", { color: "yellow" } do %>
No
<% end %>
<%= colored_pill_tag("No", color: "yellow") %>
<% end %>
</td>
<td class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">