From 7dba35c320b638c2391d4fb78dcd58906baa22eb Mon Sep 17 00:00:00 2001 From: Jeremy Lecour Date: Sun, 23 Jan 2022 15:50:01 +0100 Subject: [PATCH] =?UTF-8?q?utilisation=20d'un=20helper=20plut=C3=B4t=20qu'?= =?UTF-8?q?un=20partiel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/application_helper.rb | 16 ++++++++++++++++ app/views/shared/_colored_pill.html.erb | 3 --- app/views/users/index.html.erb | 16 ++++------------ 3 files changed, 20 insertions(+), 15 deletions(-) delete mode 100644 app/views/shared/_colored_pill.html.erb diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index de6be79..b58d5c3 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -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 diff --git a/app/views/shared/_colored_pill.html.erb b/app/views/shared/_colored_pill.html.erb deleted file mode 100644 index cc87348..0000000 --- a/app/views/shared/_colored_pill.html.erb +++ /dev/null @@ -1,3 +0,0 @@ --100 text-<%= (defined?(color) && color.presence) || "gray" %>-800"> - <%= yield %> - \ No newline at end of file diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index 41cdae3..911a883 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -53,24 +53,16 @@ <% 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 %> <% 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 %>