Skip to content

Commit

Permalink
Merge pull request #2238 from alphagov/context-overview
Browse files Browse the repository at this point in the history
Add "overview:" to titles where an attachment has the same name
  • Loading branch information
maxgds authored Nov 8, 2021
2 parents cc72975 + 996a1ce commit ae08702
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 11 deletions.
23 changes: 23 additions & 0 deletions app/views/content_items/_context_and_title.html.erb
Original file line number Diff line number Diff line change
@@ -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"
%>
3 changes: 1 addition & 2 deletions app/views/content_items/consultation.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<%= render 'govuk_publishing_components/components/title', @content_item.title_and_context %>
<%= render 'context_and_title' %>
</div>
<%= render 'shared/translations' %>
</div>
Expand All @@ -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")) %>
Expand Down
7 changes: 1 addition & 6 deletions app/views/content_items/publication.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<%= 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' %>
</div>
<%= render 'shared/translations' %>

Expand All @@ -31,7 +27,6 @@
national_applicability: @content_item.national_applicability || {},
type: @content_item.schema_name
} %>

<div class="responsive-bottom-margin">
<%= render "attachments",
title: t("publication.documents", count: 5), # This should always be pluralised.
Expand Down
29 changes: 26 additions & 3 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -145,45 +150,53 @@ 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
national:
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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -253,6 +273,7 @@ en:
standard:
one: Standard
other: Standards
overview: Standard overview
statement_to_parliament:
one: Statement to Parliament
other: Statements to Parliament
Expand All @@ -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
Expand All @@ -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
Expand Down
18 changes: 18 additions & 0 deletions test/views/content_items/attachments.html.erb_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit ae08702

Please sign in to comment.