Skip to content

Commit 9dba069

Browse files
committed
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.
1 parent 13a8122 commit 9dba069

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

app/controllers/concerns/blacklight/catalog.rb

+6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ module Blacklight::Catalog
1616
if respond_to? :helper_method
1717
helper_method :sms_mappings, :has_search_parameters?
1818
helper_method :search_facet_path
19+
helper_method :display_home_content?
1920
end
2021

2122
record_search_parameters
@@ -292,4 +293,9 @@ def blacklight_advanced_search_form_search_service
292293
def blacklight_advanced_search_form_params
293294
{}
294295
end
296+
297+
# Should we display special "home" splash screen content, instead of search results?
298+
def display_home_content?
299+
!has_search_parameters?
300+
end
295301
end

app/views/catalog/index.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
view_config: conf) %>
99
<% end %>
1010

11-
<% unless has_search_parameters? %>
11+
<% if display_home_content? %>
1212
<%# if there are no input/search related params, display the "home" partial -%>
1313
<%= render 'home' %>
1414
<%= render 'shared/sitelinks_search_box' %>

spec/views/catalog/index.html.erb_spec.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# frozen_string_literal: true
22

33
RSpec.describe "catalog/index.html.erb" do
4-
describe "with no search parameters" do
4+
describe "with home content (no search parameters)" do
55
before do
6-
allow(view).to receive(:has_search_parameters?).and_return(false)
6+
allow(view).to receive(:display_home_content?).and_return(true)
77
allow(view).to receive(:blacklight_config).and_return(CatalogController.blacklight_config)
88
@response = instance_double(Blacklight::Solr::Response, empty?: true, total: 11, start: 1, limit_value: 10, aggregations: {})
99
end
@@ -17,9 +17,9 @@
1717
end
1818
end
1919

20-
describe "with search parameters" do
20+
describe "with results (search parameters)" do
2121
before do
22-
allow(view).to receive(:has_search_parameters?).and_return(true)
22+
allow(view).to receive(:display_home_content?).and_return(false)
2323
stub_template "catalog/_results_pagination.html.erb" => ""
2424
stub_template "catalog/_search_header.html.erb" => "header_content"
2525
allow(view).to receive(:blacklight_config).and_return(Blacklight::Configuration.new)

0 commit comments

Comments
 (0)