Extract methods in order links component

This commit is contained in:
Javi Martín
2021-06-27 17:01:18 +02:00
parent 5137913565
commit cdd1e04550
2 changed files with 24 additions and 4 deletions

View File

@@ -1,10 +1,8 @@
<ul class="no-bullet submenu order-links">
<% valid_orders.each do |order| %>
<li class="inline-block">
<%= link_to current_path_with_query_params(order: order, page: 1), class: order == current_order ? "is-active" : "" do %>
<%= content_tag(order == current_order ? :h2 : :span) do %>
<%= t("#{i18n_namespace}.orders.#{order}") %>
<% end %>
<%= link_to link_path(order), class: html_class(order) do %>
<%= content_tag tag_name(order), link_text(order) %>
<% end %>
</li>
<% end %>

View File

@@ -5,4 +5,26 @@ class Shared::OrderLinksComponent < ApplicationComponent
def initialize(i18n_namespace)
@i18n_namespace = i18n_namespace
end
private
def html_class(order)
"is-active" if order == current_order
end
def tag_name(order)
if order == current_order
:h2
else
:span
end
end
def link_path(order)
current_path_with_query_params(order: order, page: 1)
end
def link_text(order)
t("#{i18n_namespace}.orders.#{order}")
end
end