Skip to content

Commit d2f4a13

Browse files
committed
refactor: use helper for recently shipping list
1 parent b7b4dfa commit d2f4a13

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

app/helpers/application_helper.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,16 @@
11
module ApplicationHelper
2+
# Format a list of repos as "repo1, repo2 and repo3" with links
3+
def recently_shipping_list(repos)
4+
links = repos.map do |repo|
5+
content_tag(:strong) { link_to(repo.name, repo.html_url, target: "_blank", rel: "noopener") }
6+
end
7+
8+
if links.size == 1
9+
links.first
10+
elsif links.size == 2
11+
safe_join(links, " and ")
12+
else
13+
safe_join([safe_join(links[0...-1], ", "), links.last], " and ")
14+
end
15+
end
216
end

app/views/pages/home.html.erb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,8 @@
2020

2121
<% if @recently_active_repos.any? %>
2222
<p class="intro-tagline mt-2">
23-
Recently shipping <%= @recently_active_repos.each_with_index.map { |repo, i|
24-
separator = i == 0 ? "" : (i == @recently_active_repos.size - 1 ? " and " : ", ")
25-
"#{separator}<strong>#{link_to repo.name, repo.html_url, target: "_blank", rel: "noopener"}</strong>"
26-
}.join.html_safe %> (latest: <%= @recently_active_repos.first.detailed_time_ago %>).
23+
Recently shipping <%= recently_shipping_list(@recently_active_repos) %>
24+
(latest: <%= @recently_active_repos.first.detailed_time_ago %>).
2725
</p>
2826
<% end %>
2927
</div>

0 commit comments

Comments
 (0)