Skip to content

Commit

Permalink
DRY up classes/socials with a helper
Browse files Browse the repository at this point in the history
  • Loading branch information
dgmstuart committed Apr 12, 2024
1 parent 67d322a commit d2d6b3f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
14 changes: 14 additions & 0 deletions app/helpers/map_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

module MapHelper
def map_update_control_link(text, query, selected:, url:)
link_to text, query, {
class: (:selected if selected),
data: {
action: "map#update:prevent map-menu#choose:prevent",
map_target: "updateControl",
url:
}
}
end
end
13 changes: 6 additions & 7 deletions app/views/maps/classes.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@
<ul>
<% DAYNAMES.each do |day| %>
<li>
<%= link_to day.pluralize,
{ day: day },
{
class: (:selected if day == @day),
data: { action: "map#update:prevent map-menu#choose:prevent", map_target: "updateControl", url: map_classes_path(day, format: :json) }
}
%>
<%= map_update_control_link(
day.pluralize,
{ day: },
selected: day == @day,
url: map_classes_path(day, format: :json)
) %>
</li>
<% end %>
</ul>
Expand Down
11 changes: 5 additions & 6 deletions app/views/maps/socials.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@
<ul>
<% @map_dates.listing_dates.each do |date| %>
<li>
<%= link_to I18n.l(date, format: :listing_date),
<%= map_update_control_link(
I18n.l(date, format: :listing_date),
{ date: date.to_fs(:db) },
{
class: (:selected if date == @map_dates.selected_date),
data: { action: "map#update:prevent map-menu#choose:prevent", map_target: "updateControl", url: map_socials_path(date.to_fs(:db), format: :json) }
}
%>
selected: date == @map_dates.selected_date,
url: map_socials_path(date.to_fs(:db), format: :json)
) %>
</li>
<% end %>
</ul>
Expand Down

0 comments on commit d2d6b3f

Please sign in to comment.