Skip to content

Commit

Permalink
Update "print entire guide" functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
jon-kirwan committed Dec 13, 2021
1 parent 01b5bb9 commit 3078c70
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 23 deletions.
40 changes: 35 additions & 5 deletions app/views/content_items/guide.html+print.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,52 @@
content_for :simple_header, true
content_for :extra_head_content do %>
<meta name="robots" content="noindex, nofollow">
<script>window.onload = function() { window.print(); }</script>
<% end %>

<div class="govuk-grid-row" id="guide-print">
<div class="govuk-grid-column-two-thirds">
<%= render 'govuk_publishing_components/components/title', { title: @content_item.title } %>
<%= render 'govuk_publishing_components/components/title', {
margin_bottom: 6,
title: @content_item.title,
} %>

<%= render 'govuk_publishing_components/components/lead_paragraph', {
margin_bottom: 6,
text: t("multi_page.printable_version"),
} %>

<%= render 'govuk_publishing_components/components/print_link', {
data_attributes: {
"track-category": "printButton",
"track-action": "clicked",
"track-label": t("components.print_link.text"),
module: "print-link"
},
margin_bottom: 8,
text: t("components.print_link.text"),
} %>

<% @content_item.parts.each_with_index do |part, index| %>
<section>
<h1 class="part-title">
<%= "#{index + 1}. #{part['title']}" %>
</h1>

<%= render 'govuk_publishing_components/components/govspeak',
content: part['body'].html_safe,
direction: page_text_direction,
disable_youtube_expansions: true %>
content: part['body'].html_safe,
direction: page_text_direction,
disable_youtube_expansions: true %>
</section>
<% end %>

<%= render 'govuk_publishing_components/components/print_link', {
data_attributes: {
"track-category": "printButton",
"track-action": "clicked",
"track-label": t("components.print_link.text"),
module: "print-link"
},
text: t("components.print_link.text")
} %>
</div>
</div>
5 changes: 4 additions & 1 deletion app/views/content_items/guide.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,11 @@

<% if @content_item.show_guide_navigation? %>
<%= render 'govuk_publishing_components/components/previous_and_next_navigation', @content_item.previous_and_next_navigation %>
<%= render 'govuk_publishing_components/components/print_link', href: @content_item.print_link, text: t("multi_page.print_entire_guide") %>
<% end %>

<div class="responsive-bottom-margin">
<a href="<%= @content_item.print_link %>" class="govuk-link govuk-link--no-visited-state govuk-body"><%= t("multi_page.print_entire_guide") %></a>
</div>
<% end %>
</div>

Expand Down
36 changes: 32 additions & 4 deletions app/views/content_items/travel_advice.html+print.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,30 @@
content_for :simple_header, true
content_for :extra_head_content do %>
<meta name="robots" content="noindex, nofollow">
<script>window.onload = function() { window.print(); }</script>
<% end %>

<div class="govuk-grid-row" id="travel-advice-print">
<div class="govuk-grid-column-two-thirds">
<%= render 'govuk_publishing_components/components/title', @content_item.title_and_context %>
<div class="govuk-!-margin-bottom-6">
<%= render 'govuk_publishing_components/components/title', @content_item.title_and_context %>
</div>

<%= render 'govuk_publishing_components/components/lead_paragraph', {
margin_bottom: 6,
text: t("multi_page.printable_version"),
} %>

<%= render 'govuk_publishing_components/components/print_link', {
data_attributes: {
"track-category": "printButton",
"track-action": "clicked",
"track-label": t("components.print_link.text"),
module: "print-link"
},
margin_bottom: 8,
text: t("components.print_link.text"),
} %>

<% @content_item.parts.each_with_index do |part, i| %>
<section>
<h1 class="part-title">
Expand All @@ -18,9 +36,19 @@
<%= render 'shared/travel_advice_summary', content_item: @content_item if i == 0 %>

<%= render 'govuk_publishing_components/components/govspeak',
content: part['body'].html_safe,
direction: page_text_direction %>
content: part['body'].html_safe,
direction: page_text_direction %>
</section>
<% end %>

<%= render 'govuk_publishing_components/components/print_link', {
data_attributes: {
"track-category": "printButton",
"track-action": "clicked",
"track-label": t("components.print_link.text"),
module: "print-link"
},
text: t("components.print_link.text")
} %>
</div>
</div>
14 changes: 6 additions & 8 deletions app/views/content_items/travel_advice.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,20 @@
canonical_url: @content_item.canonical_url,
title: @content_item.page_title,
body: @content_item.current_part_body
) %>
) %>
<% end %>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds travel-advice__header">
<%= render 'govuk_publishing_components/components/title', @content_item.title_and_context %>

<aside class="part-navigation-container" role="complementary">
<nav role="navigation" class="govuk-grid-row part-navigation" aria-label="Travel advice pages">
<%= render "govuk_publishing_components/components/contents_list", contents: @content_item.part_link_elements, underline_links: true %>
</nav>
<%= render "govuk_publishing_components/components/contents_list", aria_label: t("travel_advice.pages"), contents: @content_item.part_link_elements, underline_links: true %>

<%= render 'govuk_publishing_components/components/subscription_links',
email_signup_link: @content_item.email_signup_link,
email_signup_link_text: "Get email alerts",
feed_link: @content_item.feed_link %>
email_signup_link: @content_item.email_signup_link,
email_signup_link_text: "Get email alerts",
feed_link: @content_item.feed_link %>
</aside>
</div>
</div>
Expand Down Expand Up @@ -53,7 +51,7 @@
<%= render 'govuk_publishing_components/components/previous_and_next_navigation', @content_item.previous_and_next_navigation %>

<div class="responsive-bottom-margin">
<%= render 'govuk_publishing_components/components/print_link', href: @content_item.print_link, text: t("multi_page.print_entire_guide") %>
<a href="<%= @content_item.print_link %>" class="govuk-link govuk-link--no-visited-state govuk-body"><%= t("multi_page.print_entire_guide") %></a>
</div>
</div>
<%= render 'shared/sidebar_navigation' %>
Expand Down
6 changes: 5 additions & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ en:
show_all: show all
share_links:
share_this_page: Share this page
print_link:
text: "Print this page"
consultation:
and: and
another_website_html: This consultation %{closed} held on <a href="%{url}">another website</a>
Expand Down Expand Up @@ -427,7 +429,8 @@ en:
multi_page:
next_page: Next
previous_page: Previous
print_entire_guide: Print entire guide
print_entire_guide: View a printable version of the whole guide
printable_version: Printable version
publication:
details: Details
documents:
Expand Down Expand Up @@ -470,6 +473,7 @@ en:
avoid_all_travel_to_parts_html: The <abbr title="Foreign, Commonwealth and Development Office">FCDO</abbr> advise against all travel to parts of the country.
avoid_all_travel_to_whole_country_html: The <abbr title="Foreign, Commonwealth and Development Office">FCDO</abbr> advise against all travel to the whole country.
context: Foreign travel advice
pages: Travel advice pages
still_current_at: Still current at
summary: Summary
updated: Updated
Expand Down
2 changes: 1 addition & 1 deletion test/integration/guide_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class GuideTest < ActionDispatch::IntegrationTest

assert page.has_css?("h1", text: @content_item["details"]["parts"].first["title"])
assert page.has_css?(".gem-c-pagination")
assert page.has_css?('.gem-c-print-link a[href$="/print"]')
assert page.has_css?('.govuk-link.govuk-link--no-visited-state[href$="/print"]', text: "View a printable version of the whole guide")
end

test "draft access tokens are appended to part links within navigation" do
Expand Down
6 changes: 3 additions & 3 deletions test/integration/travel_advice_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class TravelAdviceTest < ActionDispatch::IntegrationTest
end

assert page.has_css?(".gem-c-pagination")
assert page.has_css?('.gem-c-print-link a[href$="/print"]')
assert page.has_css?('.govuk-link.govuk-link--no-visited-state[href$="/print"]', text: "View a printable version of the whole guide")
end

test "travel advice summary has latest updates and map" do
Expand Down Expand Up @@ -55,8 +55,8 @@ class TravelAdviceTest < ActionDispatch::IntegrationTest
assert_not page.has_css?(".map")
assert_not page.has_css?(".gem-c-metadata")

assert page.has_css?(".part-navigation li", text: first_part["title"])
assert_not page.has_css?(".part-navigation li a", text: first_part["title"])
assert page.has_css?(".part-navigation-container nav li", text: first_part["title"])
assert_not page.has_css?(".part-navigation-container nav li a", text: first_part["title"])
end

test "travel advice includes a discoverable atom feed link" do
Expand Down

0 comments on commit 3078c70

Please sign in to comment.