diff --git a/CHANGELOG.md b/CHANGELOG.md index f76b65b0b5..2e881711bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/app/views/govuk_publishing_components/components/_attachment.html.erb b/app/views/govuk_publishing_components/components/_attachment.html.erb index e97985e7b1..ba6d643050 100644 --- a/app/views/govuk_publishing_components/components/_attachment.html.erb +++ b/app/views/govuk_publishing_components/components/_attachment.html.erb @@ -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 %> diff --git a/app/views/govuk_publishing_components/components/attachment/_thumbnail_pdf.html.erb b/app/views/govuk_publishing_components/components/attachment/_thumbnail_pdf.html.erb new file mode 100644 index 0000000000..0e43bca1be --- /dev/null +++ b/app/views/govuk_publishing_components/components/attachment/_thumbnail_pdf.html.erb @@ -0,0 +1,3 @@ + + + diff --git a/app/views/govuk_publishing_components/components/docs/attachment.yml b/app/views/govuk_publishing_components/components/docs/attachment.yml index df63132397..ca23e144a9 100644 --- a/app/views/govuk_publishing_components/components/docs/attachment.yml +++ b/app/views/govuk_publishing_components/components/docs/attachment.yml @@ -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: diff --git a/lib/govuk_publishing_components/presenters/attachment_helper.rb b/lib/govuk_publishing_components/presenters/attachment_helper.rb index ab5e05e270..417c5f424a 100644 --- a/lib/govuk_publishing_components/presenters/attachment_helper.rb +++ b/lib/govuk_publishing_components/presenters/attachment_helper.rb @@ -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 @@ -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, @@ -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 @@ -182,6 +186,10 @@ def document? def spreadsheet? false end + + def pdf? + false + end end end end diff --git a/spec/components/attachment_spec.rb b/spec/components/attachment_spec.rb index c0d430eddd..659ff793e4 100644 --- a/spec/components/attachment_spec.rb +++ b/spec/components/attachment_spec.rb @@ -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 diff --git a/spec/lib/govuk_publishing_components/presenters/attachment_spec.rb b/spec/lib/govuk_publishing_components/presenters/attachment_spec.rb index 721c3746a1..8732a3cc17 100644 --- a/spec/lib/govuk_publishing_components/presenters/attachment_spec.rb +++ b/spec/lib/govuk_publishing_components/presenters/attachment_spec.rb @@ -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