Skip to content

Commit

Permalink
Add #view_label helper for rendering the display label for a search r…
Browse files Browse the repository at this point in the history
…esults view option
  • Loading branch information
cbeer committed Mar 10, 2015
1 parent 881c06d commit 56c27c0
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
11 changes: 11 additions & 0 deletions app/helpers/blacklight/configuration_helper_behavior.rb
Expand Up @@ -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.
#
Expand Down
6 changes: 3 additions & 3 deletions app/views/catalog/_view_type_group.html.erb
Expand Up @@ -3,9 +3,9 @@
<span class="sr-only"><%= t('blacklight.search.view_title') %></span>
<div class="view-type-group btn-group">
<% 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 %>
<span class="caption"><%= t(:"blacklight.search.view.#{view}", default: blacklight_config.view[view].title || view.to_s) %></span>
<%= 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 %>
<span class="caption"><%= view_label(view) %></span>
<% end %>
<% end %>
</div>
Expand Down
9 changes: 9 additions & 0 deletions spec/helpers/configuration_helper_spec.rb
Expand Up @@ -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"
Expand Down
4 changes: 4 additions & 0 deletions spec/views/catalog/_view_type_group.html.erb_spec.rb
Expand Up @@ -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

Expand Down

0 comments on commit 56c27c0

Please sign in to comment.