From 56c27c0e879ba2852b8cf059c36108fe959ab048 Mon Sep 17 00:00:00 2001 From: Chris Beer Date: Tue, 10 Mar 2015 15:15:12 -0700 Subject: [PATCH] Add #view_label helper for rendering the display label for a search results view option --- .../blacklight/configuration_helper_behavior.rb | 11 +++++++++++ app/views/catalog/_view_type_group.html.erb | 6 +++--- spec/helpers/configuration_helper_spec.rb | 9 +++++++++ spec/views/catalog/_view_type_group.html.erb_spec.rb | 4 ++++ 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/app/helpers/blacklight/configuration_helper_behavior.rb b/app/helpers/blacklight/configuration_helper_behavior.rb index 06241f8e9d..9a2f8941a2 100644 --- a/app/helpers/blacklight/configuration_helper_behavior.rb +++ b/app/helpers/blacklight/configuration_helper_behavior.rb @@ -96,6 +96,17 @@ def facet_field_label field ) end + def view_label view + view_config = blacklight_config.view[view] + field_label( + :"blacklight.search.view_title.#{view}", + :"blacklight.search.view.#{view}", + view_config.label, + view_config.title, + view.to_s.humanize + ) + end + ## # Look up the label for a solr field. # diff --git a/app/views/catalog/_view_type_group.html.erb b/app/views/catalog/_view_type_group.html.erb index 5fd47b376e..52d38856e5 100644 --- a/app/views/catalog/_view_type_group.html.erb +++ b/app/views/catalog/_view_type_group.html.erb @@ -3,9 +3,9 @@ <%= t('blacklight.search.view_title') %>
<% document_index_views.each do |view, config| %> - <%= link_to url_for(params.merge(:view => view)), :title => t(:"blacklight.search.view_title.#{view}", default: [:"blacklight.search.view.#{view}", blacklight_config.view[view].title || view.to_s]), :class => "btn btn-default view-type-#{ view.to_s.parameterize } #{"active" if document_index_view_type == view}" do %> - <%= render_view_type_group_icon view %> - <%= t(:"blacklight.search.view.#{view}", default: blacklight_config.view[view].title || view.to_s) %> + <%= link_to url_for(params.merge(view: view)), title: view_label(view), class: "btn btn-default view-type-#{ view.to_s.parameterize } #{"active" if document_index_view_type == view}" do %> + <%= render_view_type_group_icon view %> + <%= view_label(view) %> <% end %> <% end %>
diff --git a/spec/helpers/configuration_helper_spec.rb b/spec/helpers/configuration_helper_spec.rb index 667be83e65..ecaa15d3cf 100644 --- a/spec/helpers/configuration_helper_spec.rb +++ b/spec/helpers/configuration_helper_spec.rb @@ -137,6 +137,15 @@ end end + describe "#view_label" do + it "should look up the label to display for the view" do + allow(blacklight_config).to receive(:view).and_return({ "my_view" => double(label: "some label", title: nil) }) + allow(helper).to receive(:field_label).with(:"blacklight.search.view_title.my_view", :"blacklight.search.view.my_view", "some label", nil, "My view") + + helper.view_label "my_view" + end + end + describe "#field_label" do it "should look up the label as an i18n string" do allow(helper).to receive(:t).with(:some_key, default: []).and_return "my label" diff --git a/spec/views/catalog/_view_type_group.html.erb_spec.rb b/spec/views/catalog/_view_type_group.html.erb_spec.rb index 1631a5a1d2..00a2464096 100644 --- a/spec/views/catalog/_view_type_group.html.erb_spec.rb +++ b/spec/views/catalog/_view_type_group.html.erb_spec.rb @@ -7,6 +7,10 @@ end before do + allow(view).to receive(:view_label) do |view| + view.to_s + end + allow(view).to receive_messages(how_sort_and_per_page?: true, blacklight_config: blacklight_config) end