Skip to content

Commit

Permalink
Allow the document title to use the full heading width if no document…
Browse files Browse the repository at this point in the history
… actions are available
  • Loading branch information
cbeer committed Mar 11, 2015
1 parent 881c06d commit ca42a5b
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 25 deletions.
4 changes: 2 additions & 2 deletions app/helpers/blacklight/component_helper_behavior.rb
Expand Up @@ -30,7 +30,7 @@ def render_nav_actions(options={}, &block)
def render_index_doc_actions(document, options={})
wrapping_class = options.delete(:wrapping_class) || "index-document-functions"
rendered = render_filtered_partials(blacklight_config.index.document_actions, { document: document }.merge(options))
content_tag("div", rendered, class: wrapping_class)
content_tag("div", rendered, class: wrapping_class) unless rendered.blank?
end

##
Expand All @@ -43,7 +43,7 @@ def render_index_doc_actions(document, options={})
def render_results_collection_tools(options = {})
wrapping_class = options.delete(:wrapping_class) || "search-widgets"
rendered = render_filtered_partials(blacklight_config.index.collection_actions, options)
content_tag("div", rendered, class: wrapping_class)
content_tag("div", rendered, class: wrapping_class) unless rendered.blank?
end

def render_filtered_partials(partials, options={}, &block)
Expand Down
37 changes: 20 additions & 17 deletions app/views/catalog/_index_header_default.html.erb
@@ -1,19 +1,22 @@
<%# header bar for doc items in index view -%>
<div class="documentHeader row">
<%# main title container for doc partial view
How many bootstrap columns need to be reserved
for bookmarks control depends on size.
-%>
<% document_actions = capture do %>
<% # bookmark functions for items/docs -%>
<%= render_index_doc_actions document, wrapping_class: "index-document-functions col-sm-3 col-lg-2" %>
<% end %>
<% # header bar for doc items in index view -%>
<div class="documentHeader row">
<h5 class="index_title <%= document_actions.present? ? "col-sm-9 col-lg-10" : "col-md-12" %>">
<% if counter = document_counter_with_offset(document_counter) %>
<span class="document-counter">
<%= t('blacklight.search.documents.counter', counter: counter) %>
</span>
<% end %>
<%= link_to_document document, document_show_link_field(document), counter: counter %>
</h5>
<%# main title container for doc partial view
How many bootstrap columns need to be reserved
for bookmarks control depends on size.
-%>
<h5 class="index_title col-sm-9 col-lg-10">
<% counter = document_counter_with_offset(document_counter) %>
<span class="document-counter">
<%= t('blacklight.search.documents.counter', :counter => counter) if counter %>
</span>
<%= link_to_document document, document_show_link_field(document), :counter => counter %>
</h5>
<% # bookmark functions for items/docs -%>
<%= render_index_doc_actions document, :wrapping_class => "index-document-functions col-sm-3 col-lg-2" %>
</div>
<%= document_actions %>
</div>
5 changes: 5 additions & 0 deletions spec/helpers/blacklight_helper_spec.rb
Expand Up @@ -144,6 +144,11 @@ def mock_document_app_helper_url *args
response = helper.render_index_doc_actions(document)
expect(response).to have_selector(".bookmark_toggle")
end

it "should be nil if no partials are renderable" do
allow(helper).to receive(:render_bookmarks_control?).and_return(false)
expect(helper.render_index_doc_actions(document)).to be_blank
end
end

describe "render_show_doc_actions" do
Expand Down
28 changes: 22 additions & 6 deletions spec/views/catalog/_index_header_default.html.erb_spec.rb
Expand Up @@ -9,15 +9,31 @@
Blacklight::Configuration.new
end

it "should render the document header" do
assign :response, double(:params => {})
allow(view).to receive(:current_search_session).and_return nil
allow(view).to receive(:search_session).and_return({})
before do
assign :response, double(params: {})
allow(view).to receive(:render_grouped_response?).and_return false
allow(view).to receive(:blacklight_config).and_return(blacklight_config)
allow(view).to receive(:render_bookmarks_control?).and_return false
render :partial => "catalog/index_header_default", :locals => {:document => document, :document_counter => 1}
allow(view).to receive(:current_search_session).and_return nil
allow(view).to receive(:search_session).and_return({})
end

it "should render the document header" do
allow(view).to receive(:render_index_doc_actions)
render partial: "catalog/index_header_default", locals: {document: document, document_counter: 1}
expect(rendered).to have_selector('.document-counter', text: "2")
end

it "should allow the title to take the whole space if no document tools are rendered" do
allow(view).to receive(:render_index_doc_actions)
render partial: "catalog/index_header_default", locals: {document: document, document_counter: 1}
expect(rendered).to have_selector '.index_title.col-md-12'
end

it "should give the document actions space if present" do
allow(view).to receive(:render_index_doc_actions).and_return("DOCUMENT ACTIONS")
render partial: "catalog/index_header_default", locals: {document: document, document_counter: 1}
expect(rendered).to have_selector '.index_title.col-sm-9'
expect(rendered).to have_content "DOCUMENT ACTIONS"
end

end

0 comments on commit ca42a5b

Please sign in to comment.