From 7a3e125e36cc055d129e9038764b3cf8d01b26cc Mon Sep 17 00:00:00 2001 From: Chris Beer Date: Thu, 15 Sep 2016 06:06:31 -0400 Subject: [PATCH] Pull layout information up from templates to layouts --- .../concerns/blacklight/catalog.rb | 4 ++ .../concerns/blacklight/controller.rb | 7 ++- app/views/catalog/index.html.erb | 20 ++++--- app/views/catalog/show.html.erb | 10 ++-- app/views/layouts/blacklight.html.erb | 54 +++++-------------- app/views/layouts/blacklight/base.html.erb | 43 +++++++++++++++ app/views/layouts/catalog_result.html.erb | 11 ++++ spec/views/catalog/index.html.erb_spec.rb | 9 ++-- 8 files changed, 94 insertions(+), 64 deletions(-) create mode 100644 app/views/layouts/blacklight/base.html.erb create mode 100644 app/views/layouts/catalog_result.html.erb diff --git a/app/controllers/concerns/blacklight/catalog.rb b/app/controllers/concerns/blacklight/catalog.rb index 9a5540a9cf..23b2336209 100644 --- a/app/controllers/concerns/blacklight/catalog.rb +++ b/app/controllers/concerns/blacklight/catalog.rb @@ -276,4 +276,8 @@ def start_new_search_session? def suggestions_service Blacklight::SuggestSearch.new(params, repository).suggestions end + + def determine_layout + action_name == 'show' ? 'catalog_result' : super + end end diff --git a/app/controllers/concerns/blacklight/controller.rb b/app/controllers/concerns/blacklight/controller.rb index ec34f8be90..d4a9c0946b 100644 --- a/app/controllers/concerns/blacklight/controller.rb +++ b/app/controllers/concerns/blacklight/controller.rb @@ -30,6 +30,8 @@ module Blacklight::Controller define_callbacks :logging_in_user set_callback :logging_in_user, :before, :transfer_guest_user_actions_to_current_user + + layout :determine_layout end def default_catalog_controller @@ -166,5 +168,8 @@ def access_denied redirect_to new_user_session_url(:referer => request.fullpath) end - + + def determine_layout + 'blacklight' + end end diff --git a/app/views/catalog/index.html.erb b/app/views/catalog/index.html.erb index 29dfe15859..c0af2dbe12 100644 --- a/app/views/catalog/index.html.erb +++ b/app/views/catalog/index.html.erb @@ -1,13 +1,11 @@ - +<% end %> -
- <% unless has_search_parameters? %> - <%# if there are no input/search related params, display the "home" partial -%> - <%= render 'home' %> - <%= render 'shared/sitelinks_search_box' %> - <% else %> - <%= render 'search_results' %> - <% end %> -
+<% unless has_search_parameters? %> + <%# if there are no input/search related params, display the "home" partial -%> + <%= render 'home' %> + <%= render 'shared/sitelinks_search_box' %> +<% else %> + <%= render 'search_results' %> +<% end %> diff --git a/app/views/catalog/show.html.erb b/app/views/catalog/show.html.erb index 6ab3fcc94b..addecd3c5c 100644 --- a/app/views/catalog/show.html.erb +++ b/app/views/catalog/show.html.erb @@ -1,7 +1,5 @@ -
- <%= render_document_main_content_partial %> -
+<% content_for(:sidebar) do %> + <%= render_document_sidebar_partial %> +<% end %> - +<%= render_document_main_content_partial %> diff --git a/app/views/layouts/blacklight.html.erb b/app/views/layouts/blacklight.html.erb index 3ca0e59e00..546abf2953 100644 --- a/app/views/layouts/blacklight.html.erb +++ b/app/views/layouts/blacklight.html.erb @@ -1,43 +1,17 @@ - - - - - +<% content_for(:content) do %> + <% if content_for? :sidebar %> + - - - - - - - - - - - <%= render_page_title %> - <%= opensearch_description_tag application_name, opensearch_catalog_url(:format => 'xml') %> - <%= favicon_link_tag %> - <%= stylesheet_link_tag "application", media: "all" %> - <%= javascript_include_tag "application" %> - <%= csrf_meta_tags %> - <%= content_for(:head) %> - - - <%= render :partial => 'shared/header_navbar' %> - -
- <%= content_tag :h1, application_name, class: 'sr-only application-heading' %> - - <%= render :partial=>'/flash_msg', layout: 'shared/flash_messages' %> - -
+
+ <%= yield %> +
+ <% else %> +
<%= yield %> -
-
+ + <% end %> +<% end %> - <%= render :partial => 'shared/footer' %> - <%= render partial: 'shared/ajax_modal' %> - - +<%= render template: "layouts/blacklight/base" %> diff --git a/app/views/layouts/blacklight/base.html.erb b/app/views/layouts/blacklight/base.html.erb new file mode 100644 index 0000000000..63cecbb69c --- /dev/null +++ b/app/views/layouts/blacklight/base.html.erb @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + <%= render_page_title %> + <%= opensearch_description_tag application_name, opensearch_catalog_url(format: 'xml') %> + <%= favicon_link_tag %> + <%= stylesheet_link_tag "application", media: "all" %> + <%= javascript_include_tag "application" %> + <%= csrf_meta_tags %> + <%= content_for(:head) %> + + + <%= render partial: 'shared/header_navbar' %> + +
+ <%= content_tag :h1, application_name, class: 'sr-only application-heading' %> + + <%= render partial: '/flash_msg', layout: 'shared/flash_messages' %> + +
+ <%= content_for?(:content) ? yield(:content) : yield %> +
+
+ + <%= render partial: 'shared/footer' %> + <%= render partial: 'shared/ajax_modal' %> + + diff --git a/app/views/layouts/catalog_result.html.erb b/app/views/layouts/catalog_result.html.erb new file mode 100644 index 0000000000..39df953ef8 --- /dev/null +++ b/app/views/layouts/catalog_result.html.erb @@ -0,0 +1,11 @@ +<% content_for(:content) do %> +
+ <%= yield %> +
+ +
+ <%= content_for(:sidebar) %> +
+<% end %> + +<%= render template: "layouts/blacklight/base" %> diff --git a/spec/views/catalog/index.html.erb_spec.rb b/spec/views/catalog/index.html.erb_spec.rb index 8ffa3688f9..f6592a5a7f 100644 --- a/spec/views/catalog/index.html.erb_spec.rb +++ b/spec/views/catalog/index.html.erb_spec.rb @@ -7,15 +7,12 @@ allow(view).to receive(:has_search_parameters?).and_return(false) allow(view).to receive(:blacklight_config).and_return(Blacklight::Configuration.new) end - it "renders the sidebar and content panes" do - render - expect(rendered).to match /id="sidebar"/ - expect(rendered).to match /id="content"/ - end + let(:sidebar) { view.content_for(:sidebar) } + it "renders the search_sidebar partial" do stub_template "catalog/_search_sidebar.html.erb" => "sidebar_content" render - expect(rendered).to match /sidebar_content/ + expect(sidebar).to match /sidebar_content/ end end