From f217098787f4fbd2c27a2382936147569f51da20 Mon Sep 17 00:00:00 2001 From: Leena Gupte Date: Wed, 9 Oct 2024 15:50:11 +0100 Subject: [PATCH 1/4] Add yaml content for landing page links These links will power a side navigation block that will appear on some landing pages. The side navigation for all of the landing pages will have the same links, so rather than adding a links list to the YAML for every landing page, a shared one will be used. This is done for expediency and does not reflect how the links will eventually be handled by the CMS. The side navigation have been nested inside a links folder to logically separate them from the content items, and in case we need another list of common links. --- lib/data/landing_page_content_items/landing_page.yaml | 6 ++++++ .../landing_page_content_items/links/side_navigation.yaml | 4 ++++ spec/fixtures/landing_page.yaml | 6 ++++++ spec/fixtures/landing_page/links/side_navigation.yaml | 4 ++++ 4 files changed, 20 insertions(+) create mode 100644 lib/data/landing_page_content_items/links/side_navigation.yaml create mode 100644 spec/fixtures/landing_page/links/side_navigation.yaml diff --git a/lib/data/landing_page_content_items/landing_page.yaml b/lib/data/landing_page_content_items/landing_page.yaml index 71b09fc203..c80e92e6e0 100644 --- a/lib/data/landing_page_content_items/landing_page.yaml +++ b/lib/data/landing_page_content_items/landing_page.yaml @@ -162,3 +162,9 @@ blocks: - href: "/youtube-share-link" text: "YouTube" icon: "youtube" +- type: two_column_layout + theme: one_third_two_thirds + blocks: + - type: side_navigation + - type: govspeak + content:

On the right

diff --git a/lib/data/landing_page_content_items/links/side_navigation.yaml b/lib/data/landing_page_content_items/links/side_navigation.yaml new file mode 100644 index 0000000000..2dc3915f72 --- /dev/null +++ b/lib/data/landing_page_content_items/links/side_navigation.yaml @@ -0,0 +1,4 @@ +- text: Landing Page + href: "/landing-page" +- text: Sub Page 1 + href: "/landing-page/sub-page-1" diff --git a/spec/fixtures/landing_page.yaml b/spec/fixtures/landing_page.yaml index 3a8e810f6a..5cd88f935f 100644 --- a/spec/fixtures/landing_page.yaml +++ b/spec/fixtures/landing_page.yaml @@ -145,3 +145,9 @@ blocks: - type: govspeak inverse: true content:

Title 2 govspeak title goes here

+- type: two_column_layout + theme: one_third_two_thirds + blocks: + - type: side_navigation + - type: govspeak + content:

On the right

diff --git a/spec/fixtures/landing_page/links/side_navigation.yaml b/spec/fixtures/landing_page/links/side_navigation.yaml new file mode 100644 index 0000000000..6195bec55d --- /dev/null +++ b/spec/fixtures/landing_page/links/side_navigation.yaml @@ -0,0 +1,4 @@ +- text: Landing Page + href: "/landing-page" +- text: Sub Page 1 + href: "/sub-page-1" From 0525e4784500770b79fc11d00a913aaa1a37f18e Mon Sep 17 00:00:00 2001 From: Leena Gupte Date: Wed, 9 Oct 2024 16:27:34 +0100 Subject: [PATCH 2/4] Add a model for the side navigation block This model reads in the same list of links for each landing page. This model will need to be modified to read side navigation links from the links hash in the content item, assuming that's where they will end up, when they become available. --- app/models/block/side_navigation.rb | 10 ++++++++++ spec/models/block/side_navigation_spec.rb | 18 ++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 app/models/block/side_navigation.rb create mode 100644 spec/models/block/side_navigation_spec.rb diff --git a/app/models/block/side_navigation.rb b/app/models/block/side_navigation.rb new file mode 100644 index 0000000000..ba510c9e4f --- /dev/null +++ b/app/models/block/side_navigation.rb @@ -0,0 +1,10 @@ +module Block + class SideNavigation < Block::Base + LINKS_FILE_PATH = "lib/data/landing_page_content_items/links/side_navigation.yaml".freeze + + def links + file_path = Rails.root.join(LINKS_FILE_PATH) + YAML.load(File.read(file_path)) + end + end +end diff --git a/spec/models/block/side_navigation_spec.rb b/spec/models/block/side_navigation_spec.rb new file mode 100644 index 0000000000..9a0ef10c91 --- /dev/null +++ b/spec/models/block/side_navigation_spec.rb @@ -0,0 +1,18 @@ +RSpec.describe Block::SideNavigation do + let(:block_hash) do + { "type" => "side_navigation" } + end + + before do + stub_const("Block::SideNavigation::LINKS_FILE_PATH", "spec/fixtures/landing_page/links/side_navigation.yaml") + end + + describe "#links" do + it "returns all of the side navigation links" do + links = described_class.new(block_hash).links + expect(links.count).to eq(2) + expect(links.first["text"]).to eq("Landing Page") + expect(links.first["href"]).to eq("/landing-page") + end + end +end From 276583ccfcd16a4aa64c80cfe1eec506c3104e2a Mon Sep 17 00:00:00 2001 From: Leena Gupte Date: Wed, 9 Oct 2024 16:29:43 +0100 Subject: [PATCH 3/4] Add view to display side navigation The view to use the contents_list helper method to determine the active link. --- app/views/landing_page/blocks/_side_navigation.html.erb | 1 + 1 file changed, 1 insertion(+) create mode 100644 app/views/landing_page/blocks/_side_navigation.html.erb diff --git a/app/views/landing_page/blocks/_side_navigation.html.erb b/app/views/landing_page/blocks/_side_navigation.html.erb new file mode 100644 index 0000000000..7ac80dbb2f --- /dev/null +++ b/app/views/landing_page/blocks/_side_navigation.html.erb @@ -0,0 +1 @@ +<%= render "govuk_publishing_components/components/contents_list", contents: contents_list(request.path, block.links) %> \ No newline at end of file From f899118d833e0e122489a857735a8a3b6c1555e2 Mon Sep 17 00:00:00 2001 From: Matt Hill Date: Thu, 17 Oct 2024 11:05:35 +0100 Subject: [PATCH 4/4] Configure contents-list component as navigation --- .../landing_page/blocks/_side_navigation.html.erb | 6 +++++- lib/data/landing_page_content_items/landing_page.yaml | 11 +++-------- spec/fixtures/landing_page.yaml | 11 +++-------- 3 files changed, 11 insertions(+), 17 deletions(-) diff --git a/app/views/landing_page/blocks/_side_navigation.html.erb b/app/views/landing_page/blocks/_side_navigation.html.erb index 7ac80dbb2f..bf06b74d55 100644 --- a/app/views/landing_page/blocks/_side_navigation.html.erb +++ b/app/views/landing_page/blocks/_side_navigation.html.erb @@ -1 +1,5 @@ -<%= render "govuk_publishing_components/components/contents_list", contents: contents_list(request.path, block.links) %> \ No newline at end of file +<%= render "govuk_publishing_components/components/contents_list", { + alternative_line_style: block.data["alternative_line_style"], + title: block.data["title"], + contents: contents_list(request.path, block.links) +} %> \ No newline at end of file diff --git a/lib/data/landing_page_content_items/landing_page.yaml b/lib/data/landing_page_content_items/landing_page.yaml index c80e92e6e0..e4227db577 100644 --- a/lib/data/landing_page_content_items/landing_page.yaml +++ b/lib/data/landing_page_content_items/landing_page.yaml @@ -123,8 +123,9 @@ blocks: - type: two_column_layout theme: one_third_two_thirds blocks: - - type: govspeak - content:

Left content!

+ - type: side_navigation + title: Alternate title + alternative_line_style: true - type: blocks_container blocks: - type: card @@ -162,9 +163,3 @@ blocks: - href: "/youtube-share-link" text: "YouTube" icon: "youtube" -- type: two_column_layout - theme: one_third_two_thirds - blocks: - - type: side_navigation - - type: govspeak - content:

On the right

diff --git a/spec/fixtures/landing_page.yaml b/spec/fixtures/landing_page.yaml index 5cd88f935f..b34accb74b 100644 --- a/spec/fixtures/landing_page.yaml +++ b/spec/fixtures/landing_page.yaml @@ -123,8 +123,9 @@ blocks: - type: two_column_layout theme: one_third_two_thirds blocks: - - type: govspeak - content:

Left content!

+ - type: side_navigation + title: Alternate title + alternative_line_style: true - type: blocks_container blocks: - type: card @@ -145,9 +146,3 @@ blocks: - type: govspeak inverse: true content:

Title 2 govspeak title goes here

-- type: two_column_layout - theme: one_third_two_thirds - blocks: - - type: side_navigation - - type: govspeak - content:

On the right