-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Render featured attachments directly
This extends the attachments partial to render attachments directly using the new 'attachments' metadata in the payload (see RFC 116) [1]. Publications have one set of featured attachments, while consultations can have up to three. For the tests, I decided to test both the legacy and the new behaviours in the same test block, noting that there's no other way to group these related tests together. The new 'attachment' CSS class replicates the 30px bottom margin that legacy pre-rendered attachments have in Govspeak [2]. [1] https://github.com/alphagov/govuk-rfcs/blob/master/rfc-116-store-attachment-data-in-content-items.md [2] https://github.com/alphagov/govuk_publishing_components/blob/6ee40d5f1c2b3d81d98db0923ab96cf454d34ff0/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_attachment.scss#L22
- Loading branch information
Ben Thorner
committed
Mar 25, 2020
1 parent
c6ed5d8
commit 7e27ae2
Showing
10 changed files
with
86 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.attachment { | ||
margin-bottom: govuk-spacing(6); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module ContentItem | ||
module Attachments | ||
def attachment_details(attachment_id) | ||
content_item["details"]["attachments"].find do |attachment| | ||
attachment["id"] == attachment_id | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,23 @@ | ||
<% attachment_title_id = "#{title.parameterize}-title" %> | ||
|
||
<% if legacy_pre_rendered_documents.present? %> | ||
<% if legacy_pre_rendered_documents.present? || attachments.any? %> | ||
<%= render 'govuk_publishing_components/components/heading', | ||
id: attachment_title_id, | ||
text: title, | ||
mobile_top_margin: true %> | ||
|
||
<div aria-labelledby="<%= attachment_title_id %>"> | ||
<%= render 'govuk_publishing_components/components/govspeak', | ||
content: legacy_pre_rendered_documents.html_safe, | ||
direction: page_text_direction %> | ||
<% if legacy_pre_rendered_documents.present? %> | ||
<%= render 'govuk_publishing_components/components/govspeak', | ||
content: legacy_pre_rendered_documents.html_safe, | ||
direction: page_text_direction %> | ||
<% else %> | ||
<% attachments.each do |attachment_id| %> | ||
<div class="attachment"> | ||
<%= render 'govuk_publishing_components/components/attachment', | ||
attachment: @content_item.attachment_details(attachment_id) %> | ||
</div> | ||
<% end %> | ||
<% end %> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters