Skip to content

Commit

Permalink
Extract out overrideable Catalog#display_home_content? method
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jrochkind committed Jun 27, 2023
1 parent 13a8122 commit e664f6d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions app/controllers/concerns/blacklight/catalog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module Blacklight::Catalog
if respond_to? :helper_method
helper_method :sms_mappings, :has_search_parameters?
helper_method :search_facet_path
helper_method :display_home_content?
end

record_search_parameters
Expand Down
5 changes: 5 additions & 0 deletions app/helpers/blacklight/catalog_helper_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/views/catalog/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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' %>
Expand Down
8 changes: 4 additions & 4 deletions spec/views/catalog/index.html.erb_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand Down

0 comments on commit e664f6d

Please sign in to comment.