From fdf9492f8944b704d692044e894c523b316416b4 Mon Sep 17 00:00:00 2001 From: Tijmen Brommet Date: Wed, 14 Mar 2018 18:15:52 +0000 Subject: [PATCH] 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. --- app/controllers/content_items_controller.rb | 10 ---------- .../_breadcrumbs.html+taxonomy_navigation.erb | 5 ----- app/views/shared/_breadcrumbs.html.erb | 12 ++++++++++-- .../_related_items.html+taxonomy_navigation.erb | 15 --------------- app/views/shared/_related_items.html.erb | 14 +++++++++++++- ..._and_translations.html+taxonomy_navigation.erb | 2 -- app/views/shared/_title_and_translations.html.erb | 15 ++++++++++----- .../_translations.html+taxonomy_navigation.erb | 4 ---- app/views/shared/_translations.html.erb | 9 +++++++-- 9 files changed, 40 insertions(+), 46 deletions(-) delete mode 100644 app/views/shared/_breadcrumbs.html+taxonomy_navigation.erb delete mode 100644 app/views/shared/_related_items.html+taxonomy_navigation.erb delete mode 100644 app/views/shared/_title_and_translations.html+taxonomy_navigation.erb delete mode 100644 app/views/shared/_translations.html+taxonomy_navigation.erb diff --git a/app/controllers/content_items_controller.rb b/app/controllers/content_items_controller.rb index daa4c5bbb..69a963ae5 100644 --- a/app/controllers/content_items_controller.rb +++ b/app/controllers/content_items_controller.rb @@ -84,17 +84,7 @@ def set_expiry end def set_up_navigation - # Setting a variant on a request is a type of Rails Dark Magic that will - # use a convention to automagically load an alternative partial, view or - # layout. For example, if I set a variant of :taxonomy_navigation and we render - # a partial called _breadcrumbs.html.erb then Rails will attempt to load - # _breadcrumbs.html+taxonomy_navigation.erb instead. If this file doesn't exist, - # then it falls back to _breadcrumbs.html.erb. See: - # http://edgeguides.rubyonrails.org/4_1_release_notes.html#action-pack-variants @navigation = NavigationType.new(@content_item.content_item) - if @navigation.should_present_taxonomy_navigation? - request.variant = :taxonomy_navigation - end end def with_locale diff --git a/app/views/shared/_breadcrumbs.html+taxonomy_navigation.erb b/app/views/shared/_breadcrumbs.html+taxonomy_navigation.erb deleted file mode 100644 index 187e4a4e7..000000000 --- a/app/views/shared/_breadcrumbs.html+taxonomy_navigation.erb +++ /dev/null @@ -1,5 +0,0 @@ -<% if @content_item.taxon_breadcrumbs.any? %> - <%= render 'govuk_component/breadcrumbs', - breadcrumbs: @content_item.taxon_breadcrumbs, - collapse_on_mobile: true %> -<% end %> diff --git a/app/views/shared/_breadcrumbs.html.erb b/app/views/shared/_breadcrumbs.html.erb index eb4de2e35..e455f4dff 100644 --- a/app/views/shared/_breadcrumbs.html.erb +++ b/app/views/shared/_breadcrumbs.html.erb @@ -1,3 +1,11 @@ -<% if @content_item.breadcrumbs.any? %> - <%= render 'govuk_component/breadcrumbs', breadcrumbs: @content_item.breadcrumbs %> +<% if @navigation.should_present_taxonomy_navigation? %> + <% if @content_item.taxon_breadcrumbs.any? %> + <%= render 'govuk_component/breadcrumbs', + breadcrumbs: @content_item.taxon_breadcrumbs, + collapse_on_mobile: true %> + <% end %> +<% else %> + <% if @content_item.breadcrumbs.any? %> + <%= render 'govuk_component/breadcrumbs', breadcrumbs: @content_item.breadcrumbs %> + <% end %> <% end %> diff --git a/app/views/shared/_related_items.html+taxonomy_navigation.erb b/app/views/shared/_related_items.html+taxonomy_navigation.erb deleted file mode 100644 index 014934a96..000000000 --- a/app/views/shared/_related_items.html+taxonomy_navigation.erb +++ /dev/null @@ -1,15 +0,0 @@ -
- <% if @navigation.should_present_taxonomy_navigation? %> - <%= - render( - partial: 'govuk_component/taxonomy_sidebar', - locals: content_item.taxonomy_sidebar - ) %> - <% else %> - <%= - render( - partial: 'govuk_component/related_items', - locals: content_item.related_items - ) %> - <% end %> -
diff --git a/app/views/shared/_related_items.html.erb b/app/views/shared/_related_items.html.erb index 37cdf19df..014934a96 100644 --- a/app/views/shared/_related_items.html.erb +++ b/app/views/shared/_related_items.html.erb @@ -1,3 +1,15 @@
- <%= render partial: 'govuk_component/related_items', locals: content_item.related_items %> + <% if @navigation.should_present_taxonomy_navigation? %> + <%= + render( + partial: 'govuk_component/taxonomy_sidebar', + locals: content_item.taxonomy_sidebar + ) %> + <% else %> + <%= + render( + partial: 'govuk_component/related_items', + locals: content_item.related_items + ) %> + <% end %>
diff --git a/app/views/shared/_title_and_translations.html+taxonomy_navigation.erb b/app/views/shared/_title_and_translations.html+taxonomy_navigation.erb deleted file mode 100644 index a3190ef92..000000000 --- a/app/views/shared/_title_and_translations.html+taxonomy_navigation.erb +++ /dev/null @@ -1,2 +0,0 @@ -<%= render 'govuk_component/title', @content_item.title_and_context %> -<%= render 'shared/translations', translations: @content_item.available_translations %> diff --git a/app/views/shared/_title_and_translations.html.erb b/app/views/shared/_title_and_translations.html.erb index 55fa7c969..9af0b1f99 100644 --- a/app/views/shared/_title_and_translations.html.erb +++ b/app/views/shared/_title_and_translations.html.erb @@ -1,6 +1,11 @@ -
-
- <%= render 'govuk_component/title', @content_item.title_and_context %> +<% if @navigation.should_present_taxonomy_navigation? %> + <%= render 'govuk_component/title', @content_item.title_and_context %> + <%= render 'shared/translations', translations: @content_item.available_translations %> +<% else %> +
+
+ <%= render 'govuk_component/title', @content_item.title_and_context %> +
+ <%= render 'shared/translations' %>
- <%= render 'shared/translations' %> -
+<% end %> diff --git a/app/views/shared/_translations.html+taxonomy_navigation.erb b/app/views/shared/_translations.html+taxonomy_navigation.erb deleted file mode 100644 index c6b256a9b..000000000 --- a/app/views/shared/_translations.html+taxonomy_navigation.erb +++ /dev/null @@ -1,4 +0,0 @@ -<% if @content_item.available_translations.length > 1 %> - <%= render 'components/translation-nav', - translations: @content_item.available_translations %> -<% end %> diff --git a/app/views/shared/_translations.html.erb b/app/views/shared/_translations.html.erb index 84612dba9..3ed9e57c0 100644 --- a/app/views/shared/_translations.html.erb +++ b/app/views/shared/_translations.html.erb @@ -1,6 +1,11 @@ <% if @content_item.available_translations.length > 1 %> -
+ <% if @navigation.should_present_taxonomy_navigation? %> <%= render 'components/translation-nav', translations: @content_item.available_translations %> -
+ <% else %> +
+ <%= render 'components/translation-nav', + translations: @content_item.available_translations %> +
+ <% end %> <% end %>