Skip to content

Commit

Permalink
Add page count
Browse files Browse the repository at this point in the history
Add page_count to downloadable media so that it accurately reflects the size of the file
  • Loading branch information
dfeetenby authored and dfeetenby committed Nov 11, 2024
1 parent 7ba23cf commit 1397ea4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/views/markup/_downloadable_media.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 4 additions & 3 deletions config/initializers/markdown.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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, pdf_pages = *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
Expand Down
18 changes: 18 additions & 0 deletions spec/helpers/content_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1397ea4

Please sign in to comment.