Skip to content

Commit c0736b7

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 c0736b7

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

app/helpers/blacklight/catalog_helper_behavior.rb

+5
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,11 @@ def document_index_view_type query_params = params || {}
206206
end
207207
end
208208

209+
# Should we display special "home" splash screen content, instead of search results?
210+
def display_splash_content?
211+
!has_search_parameters?
212+
end
213+
209214
private
210215

211216
# @param [String] format

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_splash_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 splash 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_splash_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_splash_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)