Skip to content

Commit

Permalink
Pull layout information up from templates to layouts
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed Sep 15, 2016
1 parent 57e8728 commit 7a3e125
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 64 deletions.
4 changes: 4 additions & 0 deletions app/controllers/concerns/blacklight/catalog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 6 additions & 1 deletion app/controllers/concerns/blacklight/controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -166,5 +168,8 @@ def access_denied

redirect_to new_user_session_url(:referer => request.fullpath)
end


def determine_layout
'blacklight'
end
end
20 changes: 9 additions & 11 deletions app/views/catalog/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
<section id="sidebar" class="<%= sidebar_classes %>">
<% content_for(:sidebar) do %>
<%= render 'search_sidebar' %>
</section>
<% end %>
<section id="content" class="<%= main_content_classes %>">
<% 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 %>
</section>
<% 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 %>
10 changes: 4 additions & 6 deletions app/views/catalog/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<section id="content" class="<%= show_content_classes %>">
<%= render_document_main_content_partial %>
</section>
<% content_for(:sidebar) do %>
<%= render_document_sidebar_partial %>
<% end %>
<section id="sidebar" class="<%= show_sidebar_classes %>">
<%= render_document_sidebar_partial %>
</section>
<%= render_document_main_content_partial %>
54 changes: 14 additions & 40 deletions app/views/layouts/blacklight.html.erb
Original file line number Diff line number Diff line change
@@ -1,43 +1,17 @@
<!DOCTYPE html>
<html lang="en" class="no-js">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<% content_for(:content) do %>
<% if content_for? :sidebar %>
<section id="sidebar" class="<%= sidebar_classes %>">
<%= content_for(:sidebar) %>
</section>

<!-- Mobile viewport optimization h5bp.com/ad -->
<meta name="HandheldFriendly" content="True">
<meta name="viewport" content="width=device-width,initial-scale=1.0">

<!-- Internet Explorer use the highest version available -->
<meta http-equiv="X-UA-Compatible" content="IE=edge">

<!-- Mobile IE allows us to activate ClearType technology for smoothing fonts for easy reading -->
<!--[if IEMobile]>
<meta http-equiv="cleartype" content="on">
<![endif]-->

<title><%= render_page_title %></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) %>
</head>
<body class="<%= render_body_class %>">
<%= render :partial => 'shared/header_navbar' %>

<div id="main-container" class="<%= container_classes %>">
<%= content_tag :h1, application_name, class: 'sr-only application-heading' %>
<%= render :partial=>'/flash_msg', layout: 'shared/flash_messages' %>

<div class="row">
<section id="content" class="<%= main_content_classes %>">
<%= yield %>
</section>
<% else %>
<section class="col-md-12">
<%= yield %>
</div>
</div>
</section>
<% end %>
<% end %>
<%= render :partial => 'shared/footer' %>
<%= render partial: 'shared/ajax_modal' %>
</body>
</html>
<%= render template: "layouts/blacklight/base" %>
43 changes: 43 additions & 0 deletions app/views/layouts/blacklight/base.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!DOCTYPE html>
<html lang="en" class="no-js">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<!-- Mobile viewport optimization h5bp.com/ad -->
<meta name="HandheldFriendly" content="True">
<meta name="viewport" content="width=device-width,initial-scale=1.0">

<!-- Internet Explorer use the highest version available -->
<meta http-equiv="X-UA-Compatible" content="IE=edge">

<!-- Mobile IE allows us to activate ClearType technology for smoothing fonts for easy reading -->
<!--[if IEMobile]>
<meta http-equiv="cleartype" content="on">
<![endif]-->

<title><%= render_page_title %></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) %>
</head>
<body class="<%= render_body_class %>">
<%= render partial: 'shared/header_navbar' %>

<div id="main-container" class="<%= container_classes %>">
<%= content_tag :h1, application_name, class: 'sr-only application-heading' %>
<%= render partial: '/flash_msg', layout: 'shared/flash_messages' %>

<div class="row">
<%= content_for?(:content) ? yield(:content) : yield %>
</div>
</div>

<%= render partial: 'shared/footer' %>
<%= render partial: 'shared/ajax_modal' %>
</body>
</html>
11 changes: 11 additions & 0 deletions app/views/layouts/catalog_result.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<% content_for(:content) do %>
<section class="<%= show_content_classes %>">
<%= yield %>
</section>

<section class="<%= show_sidebar_classes %>">
<%= content_for(:sidebar) %>
</section>
<% end %>
<%= render template: "layouts/blacklight/base" %>
9 changes: 3 additions & 6 deletions spec/views/catalog/index.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 7a3e125

Please sign in to comment.