From 94374e75fb86bb62adde4a33e0d947a548f424cb Mon Sep 17 00:00:00 2001 From: dfeetenby Date: Mon, 11 Nov 2024 10:38:55 +0000 Subject: [PATCH] Add page count Add page_count to downloadable media so that it accurately reflects the size of the file --- app/views/markup/_downloadable_media.html.slim | 2 +- config/initializers/markdown.rb | 7 ++++--- spec/helpers/content_helper_spec.rb | 18 ++++++++++++++++++ 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/app/views/markup/_downloadable_media.html.slim b/app/views/markup/_downloadable_media.html.slim index b45ddb55..34cc6f70 100644 --- a/app/views/markup/_downloadable_media.html.slim +++ b/app/views/markup/_downloadable_media.html.slim @@ -23,4 +23,4 @@ section.gem-c-attachment class='govuk-!-display-none-print govuk-!-margin-bottom = ', ' span.gem-c-attachment__attribute - | 1 page + = page_count diff --git a/config/initializers/markdown.rb b/config/initializers/markdown.rb index a60cead8..f7c24ef6 100644 --- a/config/initializers/markdown.rb +++ b/config/initializers/markdown.rb @@ -12,19 +12,20 @@ def apply_all # 605 KB # //assets.ctfassets.net/xxx.pdf # //images.ctfassets.net/xxx.png + # 2 pages # {/download} # # @return [CustomPreprocessor] def download pattern = build_regexp('download') @output = output.gsub(pattern) do - file_title, file_size, pdf_url, thumb_url = *Regexp.last_match(1).strip.split("\n") - + file_title, file_size, pdf_url, thumb_url, page_count = *Regexp.last_match(1).strip.split("\n") download_template.render(nil, file_title: file_title, file_size: file_size, pdf_url: pdf_url, - thumb_url: thumb_url) + thumb_url: thumb_url, + page_count: page_count) end self end diff --git a/spec/helpers/content_helper_spec.rb b/spec/helpers/content_helper_spec.rb index 0c48234c..4b9a8d88 100644 --- a/spec/helpers/content_helper_spec.rb +++ b/spec/helpers/content_helper_spec.rb @@ -96,6 +96,24 @@ expect(html).to include 'title="This is a video title"' end end + + describe 'Downloads' do + let(:input) do + <<~MARKUP + {download} + title + size + pdf_url_text + thumb_url_text + 2 Pages + {/download} + MARKUP + end + + it 'has pages' do + expect(html).to include '2 Pages' + end + end end describe 'Not found error' do