Skip to content

Commit

Permalink
Add PDF specific icon to attachment component
Browse files Browse the repository at this point in the history
- adds a specific icon for PDFs to the attachment component
- this change to distinguish PDFs in a standard way from other attachment types, now that custom preview icons for PDFs are being removed
  • Loading branch information
andysellick committed Apr 19, 2024
1 parent 474443e commit 48cc5f6
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

## Unreleased

* Add PDF specific icon to attachment component ([PR #3985](https://github.com/alphagov/govuk_publishing_components/pull/3985))
* Add the hidden attribute to mobile menu button ([PR #3975](https://github.com/alphagov/govuk_publishing_components/pull/3975))

## 38.0.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@
<%= render "govuk_publishing_components/components/attachment/thumbnail_document" %>
<% elsif attachment.spreadsheet? %>
<%= render "govuk_publishing_components/components/attachment/thumbnail_spreadsheet" %>
<% elsif attachment.pdf? %>
<%= render "govuk_publishing_components/components/attachment/thumbnail_pdf" %>
<% else %>
<%= render "govuk_publishing_components/components/attachment/thumbnail_generic" %>
<% end %>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<svg class="gem-c-attachment__thumbnail-image gem-c-attachment__thumbnail-image--pdf" version="1.1" viewBox="0 0 99 140">
<path d="M12,59h9v9h-9v-9ZM30,77v9h39v-9H30ZM30,104h57v-9H30v9ZM30,122h48v-9H30v9ZM12,86h9v-9h-9v9ZM12,122h9v-9h-9v9ZM12,104h9v-9h-9v9ZM30,68h57v-9H30v9ZM35.2,21c-.3-.2-.6-.4-1-.5s-.8-.2-1.3-.2h-2.6v5.5h2.6c.5,0,1,0,1.3-.2s.7-.3,1-.5c.3-.2.5-.5.7-.8s.2-.7.2-1.1h0c0-.5,0-.9-.2-1.2-.2-.3-.4-.6-.7-.8h0ZM52.4,21.9c-.4-.5-1-.9-1.6-1.1-.7-.3-1.5-.4-2.4-.4h-2.7v11.5h2.7c.9,0,1.7-.1,2.4-.4s1.2-.7,1.6-1.1c.4-.5.7-1.1.9-1.7.2-.7.3-1.4.3-2.1v-.7c0-.8,0-1.5-.3-2.1-.2-.6-.5-1.2-.9-1.7h0ZM87,12v27H12V12h75ZM39.8,23c0-.9-.1-1.6-.4-2.4-.3-.7-.7-1.4-1.2-1.9-.5-.5-1.2-1-1.9-1.2-.8-.3-1.6-.5-2.5-.5h-7.2v17.9h3.6v-6h3.2c.9,0,1.8-.1,2.6-.5.8-.3,1.4-.7,2-1.2.5-.5,1-1.2,1.3-1.9.3-.7.5-1.5.5-2.4h0ZM57.4,26c0-1.3-.2-2.6-.5-3.7s-.9-2-1.6-2.8c-.7-.8-1.6-1.4-2.7-1.8-1.1-.4-2.3-.6-3.8-.6h-6.6v17.9h6.6c1.5,0,2.7-.2,3.8-.6,1.1-.4,2-1,2.7-1.8.7-.8,1.3-1.7,1.6-2.8.4-1.1.5-2.3.5-3.7h0ZM72.4,17.1h-12.1v17.9h3.6v-7.5h7.8v-3.3h-7.8v-3.8h8.4s0-3.3,0-3.3Z"/>
</svg>
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,14 @@ examples:
content_type: application/pdf
file_size: 20000
thumbnail_url: "https://assets.publishing.service.gov.uk/government/uploads/system/uploads/attachment_data/file/791567/thumbnail_the_government_financial_reporting_review_web.pdf.png"
pdf_attachment:
data:
attachment:
title: "Department for Transport, temporary snow ploughs: guidance note"
url: https://assets.publishing.service.gov.uk/government/uploads/system/uploads/attachment_data/file/259634/temporary-snow-ploughs.pdf
filename: temporary-snow-ploughs.pdf
content_type: application/pdf
file_size: 20000
with_preview_link:
data:
attachment:
Expand Down
12 changes: 10 additions & 2 deletions lib/govuk_publishing_components/presenters/attachment_helper.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module GovukPublishingComponents
module Presenters
class AttachmentHelper
delegate :opendocument?, :document?, :spreadsheet?, to: :content_type
delegate :opendocument?, :document?, :spreadsheet?, :pdf?, to: :content_type

attr_reader :attachment_data

Expand Down Expand Up @@ -92,7 +92,7 @@ class SupportedContentType

TYPES = [
{ content_type: "application/msword", name: "MS Word Document", document: true }.freeze, # doc
{ content_type: "application/pdf", abbr: "PDF", name: "Portable Document Format", document: true }.freeze,
{ content_type: "application/pdf", abbr: "PDF", name: "Portable Document Format", pdf: true }.freeze,
{ content_type: "application/postscript", extension: ".ps", abbr: "PS", name: "PostScript" }.freeze,
{ content_type: "application/postscript", extension: ".eps", abbr: "EPS", name: "Encapsulated PostScript" }.freeze,
{ content_type: "application/rtf", abbr: "RTF", name: "Rich Text Format" }.freeze,
Expand Down Expand Up @@ -158,6 +158,10 @@ def document?
def spreadsheet?
content_type_data[:spreadsheet].present?
end

def pdf?
content_type_data[:pdf].present?
end
end

class UnsupportedContentType
Expand All @@ -182,6 +186,10 @@ def document?
def spreadsheet?
false
end

def pdf?
false
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/components/attachment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def component_name
assert_select "abbr.gem-c-attachment__abbr[title='Portable Document Format']", text: "PDF"
expect(rendered).to match(/2 KB/)
expect(rendered).to match(/2 pages/)
assert_thumbnail "document"
assert_thumbnail "pdf"
end

it "can show file type that doesn't have an abbreviation" do
Expand Down
20 changes: 20 additions & 0 deletions spec/lib/govuk_publishing_components/presenters/attachment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,26 @@
end
end

describe "#pdf?" do
it "returns true for content types specified as a pdf" do
attachment = described_class.new(
title: "test",
url: "test",
content_type: "application/pdf",
)
expect(attachment.pdf?).to be true
end

it "returns false for a content type not specified as a spreadsheet" do
attachment = described_class.new(
title: "test",
url: "test",
content_type: "text/plain",
)
expect(attachment.pdf?).to be false
end
end

describe "#reference" do
context "when reference details are provided" do
it "returns a well formatted reference string" do
Expand Down

0 comments on commit 48cc5f6

Please sign in to comment.