Skip to content

Commit

Permalink
Merge pull request #4264 from alphagov/landing-pages-side-navigation-…
Browse files Browse the repository at this point in the history
…scaffold

Scaffold for Side Navigation block on landing pages
  • Loading branch information
matthillco authored Oct 17, 2024
2 parents 736bf7b + f899118 commit 27872dc
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 4 deletions.
10 changes: 10 additions & 0 deletions app/models/block/side_navigation.rb
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions app/views/landing_page/blocks/_side_navigation.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<%= 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)
} %>
5 changes: 3 additions & 2 deletions lib/data/landing_page_content_items/landing_page.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,9 @@ blocks:
- type: two_column_layout
theme: one_third_two_thirds
blocks:
- type: govspeak
content: <p>Left content!</p>
- type: side_navigation
title: Alternate title
alternative_line_style: true
- type: blocks_container
blocks:
- type: card
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- text: Landing Page
href: "/landing-page"
- text: Sub Page 1
href: "/landing-page/sub-page-1"
5 changes: 3 additions & 2 deletions spec/fixtures/landing_page.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,9 @@ blocks:
- type: two_column_layout
theme: one_third_two_thirds
blocks:
- type: govspeak
content: <p>Left content!</p>
- type: side_navigation
title: Alternate title
alternative_line_style: true
- type: blocks_container
blocks:
- type: card
Expand Down
4 changes: 4 additions & 0 deletions spec/fixtures/landing_page/links/side_navigation.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- text: Landing Page
href: "/landing-page"
- text: Sub Page 1
href: "/sub-page-1"
18 changes: 18 additions & 0 deletions spec/models/block/side_navigation_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 27872dc

Please sign in to comment.