From 996a1cec3117655ef26184985e972f66ae1269f6 Mon Sep 17 00:00:00 2001 From: Max Harden Date: Tue, 5 Oct 2021 08:54:41 +0100 Subject: [PATCH] Add "overview" to publication titles when parent and attachment titles match. --- .../content_items/_context_and_title.html.erb | 23 +++++++++++++++ app/views/content_items/consultation.html.erb | 3 +- app/views/content_items/publication.html.erb | 7 +---- config/locales/en.yml | 29 +++++++++++++++++-- .../attachments.html.erb_test.rb | 18 ++++++++++++ 5 files changed, 69 insertions(+), 11 deletions(-) create mode 100644 app/views/content_items/_context_and_title.html.erb diff --git a/app/views/content_items/_context_and_title.html.erb b/app/views/content_items/_context_and_title.html.erb new file mode 100644 index 000000000..b3cc6adc6 --- /dev/null +++ b/app/views/content_items/_context_and_title.html.erb @@ -0,0 +1,23 @@ +<% context_string = t("content_item.schema_name.#{@content_item.document_type}", count: 1) %> + +<% @content_item&.featured_attachments.each do |fa| %> + <% return if !@content_item.attachment_details(fa).present? %> + <% if @content_item.attachment_details(fa)['title'] == @content_item.title %> + <% content_for :title do %> + <%= t("content_item.schema_name.#{@content_item.document_type}.overview", count: 1) %>: <%= @content_item.title %> + <% end %> + <% + context_string = t("content_item.schema_name.#{@content_item.document_type}.overview", count: 1) << ":" + context_inside = true + %> + <% break %> + <% end %> +<% end %> + +<%= render 'govuk_publishing_components/components/title', + context: context_string, + context_locale: t_locale_fallback("content_item.schema_name.#{@content_item.document_type}", count: 1), + context_inside: context_inside ||= false, + title: @content_item.title, + average_title_length: "long" + %> diff --git a/app/views/content_items/consultation.html.erb b/app/views/content_items/consultation.html.erb index fb0602d97..a9a62231b 100644 --- a/app/views/content_items/consultation.html.erb +++ b/app/views/content_items/consultation.html.erb @@ -6,7 +6,7 @@
- <%= render 'govuk_publishing_components/components/title', @content_item.title_and_context %> + <%= render 'context_and_title' %>
<%= render 'shared/translations' %>
@@ -21,7 +21,6 @@ national_applicability: @content_item.national_applicability || {}, type: @content_item.schema_name } %> - <% if @content_item.unopened? %> <% content_item_unopened = capture do %> <%= raw(t("consultation.opens")) %> diff --git a/app/views/content_items/publication.html.erb b/app/views/content_items/publication.html.erb index 59beec67f..30917a961 100644 --- a/app/views/content_items/publication.html.erb +++ b/app/views/content_items/publication.html.erb @@ -6,11 +6,7 @@
- <%= render 'govuk_publishing_components/components/title', - context: t("content_item.schema_name.#{@content_item.document_type}", count: 1), - context_locale: t_locale_fallback("content_item.schema_name.#{@content_item.document_type}", count: 1), - title: @content_item.title, - average_title_length: "long" %> + <%= render 'context_and_title' %>
<%= render 'shared/translations' %> @@ -31,7 +27,6 @@ national_applicability: @content_item.national_applicability || {}, type: @content_item.schema_name } %> -
<%= render "attachments", title: t("publication.documents", count: 5), # This should always be pluralised. diff --git a/config/locales/en.yml b/config/locales/en.yml index 3599e6717..2041ea8f8 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -88,6 +88,7 @@ en: closed_consultation: one: Closed consultation other: Closed consultations + overview: Closed consultation overview cma_case: one: Competition and Markets Authority case other: Competition and Markets Authority cases @@ -100,21 +101,25 @@ en: consultation_outcome: one: Consultation outcome other: Consultation outcomes + overview: Consultation outcome overview corporate_information_page: one: Information page other: Information pages corporate_report: one: Corporate report other: Corporate reports + overview: Corporate reports overview correspondence: one: Correspondence other: Correspondences + overview: Correspondence overview countryside_stewardship_grant: one: Countryside Stewardship grant other: Countryside Stewardship grants decision: one: Decision other: Decisions + overview: Decision overview detailed_guide: one: Guidance other: Guidance @@ -145,36 +150,43 @@ en: foi_release: one: FOI release other: FOI releases + overview: FOI release overview form: one: Form other: Forms + overview: Forms overview government_response: one: Government response other: Government responses guidance: one: Guidance other: Guidance + overview: Guidance overview impact_assessment: one: Impact assessment other: Impact assessments + overview: Impact assessment overview imported: one: imported - awaiting type other: imported - awaiting type independent_report: one: Independent report other: Independent reports + overview: Independent report overview international_development_fund: one: International development funding other: International development funding international_treaty: one: International treaty other: International treaties + overview: International treaty overview maib_report: one: Marine Accident Investigation Branch report other: Marine Accident Investigation Branch reports map: one: Map other: Maps + overview: Map overview medical_safety_alert: one: Alerts and recalls for drugs and medical devices other: Alerts and recalls for drugs and medical devices @@ -182,8 +194,9 @@ en: one: National statistics announcement other: National statistics announcements national_statistics: - one: National Statistics - other: National Statistics + one: National statistics + other: National statistics + overview: National statistics overview national_statistics_announcement: one: National statistics announcement other: National statistics announcements @@ -196,18 +209,21 @@ en: notice: one: Notice other: Notices + overview: Notice overview official: one: Official statistics announcement other: Official statistics announcements official_statistics: one: Official Statistics - other: Official Statistics + other: Official statistics + overview: Official statistics overview official_statistics_announcement: one: Official statistics announcement other: Official statistics announcements open_consultation: one: Open consultation other: Open consultations + overview: Open consultation overview oral_statement: one: Oral statement to Parliament other: Oral statements to Parliament @@ -217,12 +233,14 @@ en: policy_paper: one: Policy paper other: Policy papers + overview: Policy paper overview press_release: one: Press release other: Press releases promotional: one: Promotional material other: Promotional material + overview: Promotional material overview publication: one: Publication other: Publications @@ -232,9 +250,11 @@ en: regulation: one: Regulation other: Regulations + overview: Regulation overview research: one: Research and analysis other: Research and analysis + overview: Research and analysis overview residential_property_tribunal_decision: one: Residential property tribunal decision other: Residential property tribunal decisions @@ -253,6 +273,7 @@ en: standard: one: Standard other: Standards + overview: Standard overview statement_to_parliament: one: Statement to Parliament other: Statements to Parliament @@ -265,6 +286,7 @@ en: statutory_guidance: one: Statutory guidance other: Statutory guidance + overview: Statutory guidance overview take_part: one: Take part other: Take part @@ -277,6 +299,7 @@ en: transparency: one: Transparency data other: Transparency data + overview: Transparency data overview utaac_decision: one: Administrative appeals tribunal decision other: Administrative appeals tribunal decisions diff --git a/test/views/content_items/attachments.html.erb_test.rb b/test/views/content_items/attachments.html.erb_test.rb index 913d549ba..b89a04659 100644 --- a/test/views/content_items/attachments.html.erb_test.rb +++ b/test/views/content_items/attachments.html.erb_test.rb @@ -43,4 +43,22 @@ class ContentItemsAttachmentsTest < ActionView::TestCase assert_includes rendered, "gem-c-govspeak" assert_includes rendered, "some html" end + + test "renders overview title when attachment title matches parent" do + @content_item = PublicationPresenter.new( + { "document_type" => "correspondence", + "title" => "Matching", + "details" => { "attachments" => [{ "id" => "attachment_id", + "title" => "Matching", + "url" => "some/url" }], + "featured_attachments" => %w[attachment_id] } }, + "/publication", + ApplicationController.new.view_context, + ) + render( + partial: "content_items/context_and_title", + ) + + assert_includes rendered, "Correspondence overview:" + end end