From fe9e508ddd416fd2a89372d4e637cc08fc9e913d Mon Sep 17 00:00:00 2001 From: Jonathan Rochkind Date: Tue, 27 Jun 2023 11:53:07 -0400 Subject: [PATCH] Extract out overrideable Catalog#display_home_content? method It was previously hard-coded into catalog/index.html.erb that if you has_search_parameters?, you display search results, and otherwise you display "home" splash content. But my app never wants to display home splash content. It wants to always display search results (with no search parameters, that would be: all results). Other apps may want to have different criteria for when to display home splash screen results. By making the logic rely on new extracted `display_home_content?` method, we provide an override hook point to easily customize this choice without having to override the template (with it's future compatibility and maintainance issues). The default defintion of display_home_content? is `!has_search_parameters?` for complete backwards compatibility with previous logic. --- app/helpers/blacklight/catalog_helper_behavior.rb | 5 +++++ app/views/catalog/index.html.erb | 2 +- spec/views/catalog/index.html.erb_spec.rb | 8 ++++---- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/helpers/blacklight/catalog_helper_behavior.rb b/app/helpers/blacklight/catalog_helper_behavior.rb index f9b234178e..361e6b4b2c 100644 --- a/app/helpers/blacklight/catalog_helper_behavior.rb +++ b/app/helpers/blacklight/catalog_helper_behavior.rb @@ -206,6 +206,11 @@ def document_index_view_type query_params = params || {} end end + # Should we display special "home" splash screen content, instead of search results? + def display_splash_content? + !has_search_parameters? + end + private # @param [String] format diff --git a/app/views/catalog/index.html.erb b/app/views/catalog/index.html.erb index cd09b7d7c5..40998a2817 100644 --- a/app/views/catalog/index.html.erb +++ b/app/views/catalog/index.html.erb @@ -8,7 +8,7 @@ view_config: conf) %> <% end %> -<% unless has_search_parameters? %> +<% if display_splash_content? %> <%# if there are no input/search related params, display the "home" partial -%> <%= render 'home' %> <%= render 'shared/sitelinks_search_box' %> diff --git a/spec/views/catalog/index.html.erb_spec.rb b/spec/views/catalog/index.html.erb_spec.rb index 5fc046900f..fc0c7992f6 100644 --- a/spec/views/catalog/index.html.erb_spec.rb +++ b/spec/views/catalog/index.html.erb_spec.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true RSpec.describe "catalog/index.html.erb" do - describe "with no search parameters" do + describe "with splash content (no search parameters)" do before do - allow(view).to receive(:has_search_parameters?).and_return(false) + allow(view).to receive(:display_splash_content?).and_return(true) allow(view).to receive(:blacklight_config).and_return(CatalogController.blacklight_config) @response = instance_double(Blacklight::Solr::Response, empty?: true, total: 11, start: 1, limit_value: 10, aggregations: {}) end @@ -17,9 +17,9 @@ end end - describe "with search parameters" do + describe "with results (search parameters)" do before do - allow(view).to receive(:has_search_parameters?).and_return(true) + allow(view).to receive(:display_splash_content?).and_return(false) stub_template "catalog/_results_pagination.html.erb" => "" stub_template "catalog/_search_header.html.erb" => "header_content" allow(view).to receive(:blacklight_config).and_return(Blacklight::Configuration.new)