Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Move detailed guide document #4610

Draft
wants to merge 27 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
3a5dddc
Update README.md and govuk_examples.yml
sairamya93 Jan 22, 2025
bf5b454
Add route and controller for detailed_guide
sairamya93 Jan 22, 2025
b312608
Add Detailed guide view
sairamya93 Jan 23, 2025
77b4f43
Modify detailed_guide view
sairamya93 Jan 23, 2025
e173f3b
Add model and presenter for detailed_guide
sairamya93 Jan 23, 2025
75461c1
Add GOV.UK Personalisation helper and concern
sairamya93 Jan 31, 2025
72ca37c
Modify View page
sairamya93 Jan 31, 2025
bec8955
Add shared partial - email subscribe and unsubscribe flash.html
sairamya93 Jan 31, 2025
de3f030
Add locales for email-description
sairamya93 Jan 31, 2025
a5d2e6c
Add locales for detailed_guide
sairamya93 Jan 31, 2025
b5c5fd6
Modify DetailedGuide model to add Updatable and Organisations
sairamya93 Jan 31, 2025
73cb0b2
Modify View - To update publisher metadata
sairamya93 Jan 31, 2025
503ce82
Add National Applicability concern and test
sairamya93 Feb 3, 2025
509a44f
Add partial - single page notification button
sairamya93 Feb 3, 2025
c2a68c7
Add SinglePageNotificationButton concern and test
sairamya93 Feb 3, 2025
a5b03dc
Modify detailed guide model - Add SinglePageNotificationButton and m…
sairamya93 Feb 3, 2025
7d86aad
Add history_notice partial
sairamya93 Feb 3, 2025
540365c
Add political concern and tests
sairamya93 Feb 3, 2025
ffbab9a
Modify detailed_guide model - Add political concern
sairamya93 Feb 3, 2025
f80ea3c
Add back to top component,stylesheet,yaml and test files
sairamya93 Feb 6, 2025
01298de
Add contents-list-with-body component,stylesheet,yaml and test files
sairamya93 Feb 6, 2025
cb0f0db
Modify detailed guide model - Include ContentsList
sairamya93 Feb 6, 2025
761b160
Add published-dates-with-notification-button shared partial and style…
sairamya93 Feb 6, 2025
0930e1f
Add contents list concern
sairamya93 Feb 6, 2025
7e43e8c
Update View - Replace Govspeak_body method
sairamya93 Feb 6, 2025
36601b1
Add locales - common.email_and_print_link
sairamya93 Feb 6, 2025
646fde5
Add request tests for detailed guide
sairamya93 Feb 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ Transaction start pages:
* https://www.gov.uk/vehicle-tax
* https://www.gov.uk/find-a-job

### Detailed Guide

* https://www.gov.uk/guidance/guidance-on-devolution

### Help

* https://www.gov.uk/help/browsers
Expand Down
15 changes: 15 additions & 0 deletions app/assets/stylesheets/components/_back-to-top.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@import "govuk_publishing_components/individual_component_support";

.app-c-back-to-top {
display: inline-block;
margin-bottom: govuk-spacing(2);
margin-left: govuk-spacing(3);
margin-right: govuk-spacing(3);
}

.app-c-back-to-top__icon {
float: left;
margin-right: .3em;
width: .8em;
height: .968em;
}
49 changes: 49 additions & 0 deletions app/assets/stylesheets/components/_contents-list-with-body.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
@import "govuk_publishing_components/individual_component_support";

.app-c-contents-list-with-body__link-container {
margin: 0 auto;
padding: 0;

@include govuk-media-query($from: tablet) {
max-width: 1024px;
}

.app-c-back-to-top {
margin-left: 0;
margin-right: 0;
}
}

.app-c-contents-list-with-body__link-wrapper {
padding-bottom: govuk-spacing(2);

.app-c-back-to-top {
padding-bottom: govuk-spacing(2);
}
}

.app-c-contents-list-with-body__link-wrapper.sticky-element--stuck-to-window {
background-color: govuk-colour("light-grey");
bottom: -1px; // 'Fix' for anomalous 1px margin which sporadically appears below this element.
left: 0;
margin: 0;
padding: 0;
padding-left: 0;
position: fixed;
width: 100%;
z-index: 10;

@include govuk-media-query($from: tablet) {
padding-left: govuk-spacing(2);
}

.app-c-back-to-top {
margin-bottom: 0;
padding: govuk-spacing(3);
width: 66%;

@include govuk-media-query($from: tablet) {
padding: govuk-spacing(4);
}
}
}
17 changes: 17 additions & 0 deletions app/assets/stylesheets/views/_published-dates-button-group.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@import "govuk_publishing_components/individual_component_support";

.published-dates-button-group {
@include govuk-media-query($from: tablet) {
display: flex;
flex-direction: row;
}
}

.published-dates-button-group form {
@include govuk-media-query($until: tablet) {
margin-bottom: govuk-spacing(3);
}
@include govuk-media-query($from: tablet) {
margin-right: govuk-spacing(4);
}
}
2 changes: 2 additions & 0 deletions app/controllers/content_items_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class ContentItemsController < ApplicationController
include GovukPersonalisation::ControllerConcern

before_action :set_locale, if: -> { request.format.html? }

private
Expand Down
3 changes: 3 additions & 0 deletions app/controllers/detailed_guide_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class DetailedGuideController < ContentItemsController
def show; end
end
15 changes: 15 additions & 0 deletions app/helpers/govuk_personalisation_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module GovukPersonalisationHelper
def email_subscription_success_banner_heading(account_flash, locale = nil)
if account_flash.include?("email-subscription-success")
sanitize(t("email.subscribe_title", locale:))
elsif account_flash.include?("email-unsubscribe-success")
sanitize(t("email.unsubscribe_title", locale:))
elsif account_flash.include?("email-subscription-already-subscribed")
sanitize(t("email.already_subscribed_title", locale:))
end
end

def show_email_subscription_success_banner?(account_flash)
account_flash.include?("email-subscription-success") || account_flash.include?("email-unsubscribe-succe ss") || account_flash.include?("email-subscription-already-subscribed")
end
end
108 changes: 108 additions & 0 deletions app/models/concerns/contents_list.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
module ContentsList
extend ActiveSupport::Concern

MINIMUM_CHARACTER_COUNT = 415
MINIMUM_CHARACTER_COUNT_IF_IMAGE_PRESENT = 224
MINIMUM_TABLE_ROW_COUNT = 13
MINIMUM_TABLE_ROW_COUNT_IF_IMAGE_PRESENT = 6

included do
def contents
@contents ||=
if show_contents_list?
contents_items.each { |item| item[:href] = "##{item[:id]}" }
else
[]
end
end

def contents_items
extract_headings_with_ids
end

def show_contents_list?
return true if contents_items.present?
return false if no_first_item?

first_item_size_requirements_met?(character_count, table_row_count)
end
end

private

def first_item_size_requirements_met?(char_count, table_row_count)
first_item_character_count > char_count || first_item_table_rows > table_row_count
end

def character_count
first_item_has_image? ? MINIMUM_CHARACTER_COUNT_IF_IMAGE_PRESENT : MINIMUM_CHARACTER_COUNT
end

def table_row_count
first_item_has_image? ? MINIMUM_TABLE_ROW_COUNT_IF_IMAGE_PRESENT : MINIMUM_TABLE_ROW_COUNT
end

def extract_headings_with_ids
headings = parsed_body.css("h2").map do |heading|
id = heading.attribute("id")
{ text: heading.text.gsub(/:$/, ""), id: id.value } if id
end
headings.compact
end

def first_item_content
element = first_item
first_item_text = ""
allowed_elements = %w[p ul ol]

until element.name == "h2"
first_item_text += element.text if element.name.in?(allowed_elements)
element = element.next_element
break if element.nil?
end
first_item_text
end

def first_item_character_count
@first_item_character_count ||= first_item_content.length
end

def find_first_table
element = first_item

until element.name == "h2"
return element if element.name == "table"

element = element.next_element
break if element.nil?
end
end

def first_item_table_rows
@table ||= find_first_table
@table.present? ? @table.css("tr").count : 0
end

def first_item_has_image?
element = first_item

until element.name == "h2"
return true if element.name == "div" && element["class"] == "img"

element = element.next_element
return false if element.nil?
end
end

def parsed_body
@parsed_body ||= Nokogiri::HTML(body)
end

def first_item
parsed_body.css("h2").first.try(:next_element)
end

def no_first_item?
first_item.nil?
end
end
9 changes: 9 additions & 0 deletions app/models/concerns/national_applicability.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module NationalApplicability
extend ActiveSupport::Concern

included do
def national_applicability
content_store_hash.dig("details", "national_applicability")&.deep_symbolize_keys
end
end
end
32 changes: 32 additions & 0 deletions app/models/concerns/political.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module Political
extend ActiveSupport::Concern

included do
def historically_political?
political? && historical?
end

def publishing_government
content_store_hash.dig(
"links", "government", 0, "title"
)
end
end

private

def political?
content_store_hash.dig("details", "political")
end

def historical?
government_current = content_store_hash.dig(
"links", "government", 0, "details", "current"
)

# Treat no government as not historical
return false if government_current.nil?

!government_current
end
end
17 changes: 17 additions & 0 deletions app/models/concerns/single_page_notification_button.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module SinglePageNotificationButton
extend ActiveSupport::Concern

# Add the content id of the publication, detailed_guide or consultation that should be exempt from having the single page notification button
EXEMPTION_LIST = %w[
c5c8d3cd-0dc2-4ca3-8672-8ca0a6e92165
70bd3a76-6606-45dd-9fb5-2b95f8667b4d
a457220c-915c-4cb1-8e41-9191fba42540
5f9c6c15-7631-11e4-a3cb-005056011aef
].freeze

included do
def display_single_page_notification_button?
!(EXEMPTION_LIST.include? content_store_response["content_id"]) && I18n.locale == :en
end
end
end
8 changes: 8 additions & 0 deletions app/models/detailed_guide.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class DetailedGuide < ContentItem
include ContentsList
include NationalApplicability
include Organisations
include Political
include SinglePageNotificationButton
include Updatable
end
2 changes: 2 additions & 0 deletions app/presenters/detailed_guide_presenter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class DetailedGuidePresenter < ContentItemPresenter
end
11 changes: 11 additions & 0 deletions app/views/components/_back_to_top.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<% add_app_component_stylesheet("back-to-top") %>
<%
text ||= t("content_item.contents", default: "Contents")
%>
<a class="govuk-link app-c-back-to-top govuk-!-display-none-print"
href="<%= href %>">
<svg class="app-c-back-to-top__icon" xmlns="http://www.w3.org/2000/svg" width="13" height="17" viewBox="0 0 13 17" aria-hidden="true" focusable="false">
<path fill="currentColor" d="M6.5 0L0 6.5 1.4 8l4-4v12.7h2V4l4.3 4L13 6.4z" />
</svg>
<%= text %>
</a>
29 changes: 29 additions & 0 deletions app/views/components/_contents_list_with_body.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<% add_app_component_stylesheet("contents-list-with-body") %>
<% block = yield %>
<% unless block.empty? %>
<%
contents ||= []
sticky_attr = "sticky-element-container" if contents.any?
%>
<%= tag.div(
id: "contents",
class: "app-c-contents-list-with-body",
data: {
module: sticky_attr,
},
) do %>
<% if contents.any? %>
<div class="responsive-bottom-margin">
<%= render "govuk_publishing_components/components/contents_list", contents: contents %>
</div>
<% end %>
<%= block %>
<% if contents.any? %>
<div data-sticky-element class="app-c-contents-list-with-body__link-wrapper">
<div class="app-c-contents-list-with-body__link-container">
<%= render "components/back_to_top", href: "#contents" %>
</div>
</div>
<% end %>
<% end %>
<% end %>
17 changes: 17 additions & 0 deletions app/views/components/docs/back_to_top.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Back to top link
description: An anchor link intended to allow users to return to the top of the content.
shared_accessibility_criteria:
- link
examples:
default:
data:
href: "#contents"
with_different_text:
data:
href: "#contents"
text: "Back to top"
right_to_left:
data:
href: "#contents"
context:
right_to_left: true
Loading
Loading