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 %>