From d7c5d86d36edc298fbca828afdd3cde7fa112e61 Mon Sep 17 00:00:00 2001 From: Alvaro Sanchez Date: Tue, 20 Feb 2024 17:03:53 -0600 Subject: [PATCH] The rubygem partial displays the latest release date --- app/assets/stylesheets/modules/gems.css | 2 +- app/controllers/searches_controller.rb | 5 +++-- app/helpers/rubygems_helper.rb | 4 ++++ app/views/rubygems/_rubygem.html.erb | 7 ++++++- app/views/searches/show.html.erb | 4 ++-- 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/app/assets/stylesheets/modules/gems.css b/app/assets/stylesheets/modules/gems.css index 26da7e39922..6404e551e1a 100644 --- a/app/assets/stylesheets/modules/gems.css +++ b/app/assets/stylesheets/modules/gems.css @@ -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; diff --git a/app/controllers/searches_controller.rb b/app/controllers/searches_controller.rb index 6cf5b058b32..e88fbc6cf37 100644 --- a/app/controllers/searches_controller.rb +++ b/app/controllers/searches_controller.rb @@ -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? diff --git a/app/helpers/rubygems_helper.rb b/app/helpers/rubygems_helper.rb index 7898a9e9475..18b95ae576d 100644 --- a/app/helpers/rubygems_helper.rb +++ b/app/helpers/rubygems_helper.rb @@ -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 diff --git a/app/views/rubygems/_rubygem.html.erb b/app/views/rubygems/_rubygem.html.erb index c3a4f8f714e..fa55655646d 100644 --- a/app/views/rubygems/_rubygem.html.erb +++ b/app/views/rubygems/_rubygem.html.erb @@ -2,7 +2,12 @@

<%= rubygem.name %> - <%= latest_version_number(rubygem) %> + + <%= latest_version_number(rubygem) %> + + + <%= "released #{latest_release_date(rubygem)}" %> +

<%= short_info(rubygem) %>

diff --git a/app/views/searches/show.html.erb b/app/views/searches/show.html.erb index 59b0c68a537..a21288cb636 100644 --- a/app/views/searches/show.html.erb +++ b/app/views/searches/show.html.erb @@ -25,7 +25,7 @@ <% @subtitle = t('.subtitle', :query => content_tag(:em, h(params[:query]))) %>
-

<%= page_entries_info(@gems, :entry_name => 'gem').html_safe %>

+

<%= page_entries_info(@elastic_results, :entry_name => 'gem').html_safe %>

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