Skip to content

Commit fdf9492

Browse files
committed
Stop using request variants to determine layout
This removes the code for the taxonomy_navigation requests variants and uses `if` statements in the views instead. This makes it clearer what's going on. It shouldn't make any change in the pages. I suspect that most of these `if` statements aren't actually meaningful and can be removed. That's for a follow up PR.
1 parent 26ac019 commit fdf9492

9 files changed

+40
-46
lines changed

app/controllers/content_items_controller.rb

-10
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,7 @@ def set_expiry
8484
end
8585

8686
def set_up_navigation
87-
# Setting a variant on a request is a type of Rails Dark Magic that will
88-
# use a convention to automagically load an alternative partial, view or
89-
# layout. For example, if I set a variant of :taxonomy_navigation and we render
90-
# a partial called _breadcrumbs.html.erb then Rails will attempt to load
91-
# _breadcrumbs.html+taxonomy_navigation.erb instead. If this file doesn't exist,
92-
# then it falls back to _breadcrumbs.html.erb. See:
93-
# http://edgeguides.rubyonrails.org/4_1_release_notes.html#action-pack-variants
9487
@navigation = NavigationType.new(@content_item.content_item)
95-
if @navigation.should_present_taxonomy_navigation?
96-
request.variant = :taxonomy_navigation
97-
end
9888
end
9989

10090
def with_locale

app/views/shared/_breadcrumbs.html+taxonomy_navigation.erb

-5
This file was deleted.
+10-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1-
<% if @content_item.breadcrumbs.any? %>
2-
<%= render 'govuk_component/breadcrumbs', breadcrumbs: @content_item.breadcrumbs %>
1+
<% if @navigation.should_present_taxonomy_navigation? %>
2+
<% if @content_item.taxon_breadcrumbs.any? %>
3+
<%= render 'govuk_component/breadcrumbs',
4+
breadcrumbs: @content_item.taxon_breadcrumbs,
5+
collapse_on_mobile: true %>
6+
<% end %>
7+
<% else %>
8+
<% if @content_item.breadcrumbs.any? %>
9+
<%= render 'govuk_component/breadcrumbs', breadcrumbs: @content_item.breadcrumbs %>
10+
<% end %>
311
<% end %>

app/views/shared/_related_items.html+taxonomy_navigation.erb

-15
This file was deleted.
+13-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
11
<div class="column-third add-title-margin">
2-
<%= render partial: 'govuk_component/related_items', locals: content_item.related_items %>
2+
<% if @navigation.should_present_taxonomy_navigation? %>
3+
<%=
4+
render(
5+
partial: 'govuk_component/taxonomy_sidebar',
6+
locals: content_item.taxonomy_sidebar
7+
) %>
8+
<% else %>
9+
<%=
10+
render(
11+
partial: 'govuk_component/related_items',
12+
locals: content_item.related_items
13+
) %>
14+
<% end %>
315
</div>

app/views/shared/_title_and_translations.html+taxonomy_navigation.erb

-2
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
<div class="grid-row">
2-
<div class="column-two-thirds">
3-
<%= render 'govuk_component/title', @content_item.title_and_context %>
1+
<% if @navigation.should_present_taxonomy_navigation? %>
2+
<%= render 'govuk_component/title', @content_item.title_and_context %>
3+
<%= render 'shared/translations', translations: @content_item.available_translations %>
4+
<% else %>
5+
<div class="grid-row">
6+
<div class="column-two-thirds">
7+
<%= render 'govuk_component/title', @content_item.title_and_context %>
8+
</div>
9+
<%= render 'shared/translations' %>
410
</div>
5-
<%= render 'shared/translations' %>
6-
</div>
11+
<% end %>

app/views/shared/_translations.html+taxonomy_navigation.erb

-4
This file was deleted.
+7-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
<% if @content_item.available_translations.length > 1 %>
2-
<div class="column-third">
2+
<% if @navigation.should_present_taxonomy_navigation? %>
33
<%= render 'components/translation-nav',
44
translations: @content_item.available_translations %>
5-
</div>
5+
<% else %>
6+
<div class="column-third">
7+
<%= render 'components/translation-nav',
8+
translations: @content_item.available_translations %>
9+
</div>
10+
<% end %>
611
<% end %>

0 commit comments

Comments
 (0)