Skip to content

Commit

Permalink
The rubygem partial displays the latest release date
Browse files Browse the repository at this point in the history
  • Loading branch information
heyapricot committed Feb 20, 2024
1 parent b0c03a4 commit d7c5d86
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/assets/stylesheets/modules/gems.css
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
float: right;
text-align: right; } }

.gems__gem__version {
.gems__gem__version, .gems__gem__latest__release__date {
margin-left: 10px;
font-style: italic;
font-weight: 300;
Expand Down
5 changes: 3 additions & 2 deletions app/controllers/searches_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ class SearchesController < ApplicationController

def show
return unless params[:query].is_a?(String)
@error_msg, @gems = ElasticSearcher.new(params[:query], page: @page).search
@error_msg, @elastic_results = ElasticSearcher.new(params[:query], page: @page).search

return unless @gems
return unless @elastic_results
@gems = Rubygem.where(id: @elastic_results.map(&:id)).with_versions
set_total_pages if @gems.total_count > Gemcutter::SEARCH_MAX_PAGES * Rubygem.default_per_page
exact_match = Rubygem.name_is(params[:query]).first
@yanked_gem = exact_match unless exact_match&.indexed_versions?
Expand Down
4 changes: 4 additions & 0 deletions app/helpers/rubygems_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ def show_all_versions_link?(rubygem)
rubygem.versions_count > 5 || rubygem.yanked_versions?
end

def latest_release_date(rubygem)
(rubygem.latest_version || rubygem.versions&.last)&.built_at&.strftime("%B %d, %Y")
end

def latest_version_number(rubygem)
return rubygem.version if rubygem.respond_to?(:version)
(rubygem.latest_version || rubygem.versions.last)&.number
Expand Down
7 changes: 6 additions & 1 deletion app/views/rubygems/_rubygem.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
<span class="gems__gem__info">
<h2 class="gems__gem__name">
<%= rubygem.name %>
<span class="gems__gem__version"><%= latest_version_number(rubygem) %></span>
<span class="gems__gem__version">
<%= latest_version_number(rubygem) %>
</span>
<span class="gems__gem__latest__release__date">
<%= "released #{latest_release_date(rubygem)}" %>
</span>
</h2>
<p class="gems__gem__desc t-text"><%= short_info(rubygem) %></p>
</span>
Expand Down
4 changes: 2 additions & 2 deletions app/views/searches/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<% @subtitle = t('.subtitle', :query => content_tag(:em, h(params[:query]))) %>

<header class="gems__header push--s">
<p class="gems__meter"><%= page_entries_info(@gems, :entry_name => 'gem').html_safe %></p>
<p class="gems__meter"><%= page_entries_info(@elastic_results, :entry_name => 'gem').html_safe %></p>
</header>

<%= render partial: 'aggregations', locals: { gems: @gems } %>
Expand All @@ -44,7 +44,7 @@
<% if @gems.present? %>
<%= render partial: 'rubygems/rubygem', collection: @gems %>
<%= paginate @gems %>
<%= paginate @elastic_results %>
<% end %>
<% end %>
<% end %>

0 comments on commit d7c5d86

Please sign in to comment.