Skip to content

Commit

Permalink
Add before and after links slots to footer
Browse files Browse the repository at this point in the history
These slots don't have any functionality but allow arbitrary html to be
placed before/after the meta links
  • Loading branch information
peteryates committed Mar 26, 2024
1 parent 9485e09 commit 4aa6264
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/components/govuk_component/footer_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
<div class="<%= brand %>-footer__meta-item <%= brand %>-footer__meta-item--grow">
<% if meta_items.any? %>
<h2 class="<%= brand %>-visually-hidden"><%= meta_items_title %></h2>

<%= content_before_meta_links %>
<ul class="<%= brand %>-footer__inline-list">
<% @meta_items.each do |hyperlink| %>
<li class="<%= brand %>-footer__inline-list-item">
<%= hyperlink %>
</li>
<% end %>
</ul>
<%= content_after_meta_links %>
<% end %>
<% if meta_content.present? %>
Expand Down
2 changes: 2 additions & 0 deletions app/components/govuk_component/footer_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ class GovukComponent::FooterComponent < GovukComponent::Base
renders_one :meta_html
renders_one :meta
renders_one :navigation
renders_one :content_before_meta_links
renders_one :content_after_meta_links

attr_reader :meta_items, :meta_text, :meta_items_title, :meta_licence, :copyright_text, :copyright_url, :custom_container_classes

Expand Down
22 changes: 22 additions & 0 deletions spec/components/govuk_component/footer_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,28 @@
end
end

describe "content before and after meta items" do
let(:kwargs) { { meta_items: } }

subject! do
render_inline(GovukComponent::FooterComponent.new(**kwargs)) do |footer|
footer.with_content_before_meta_links { "before" }
footer.with_content_after_meta_links { "after" }
end
end

specify "renders the content before and after the meta item links" do
expect(rendered_content).to have_tag("div", with: { class: "govuk-footer__meta-item" }) do
with_text(/before/)
with_text(/after/)
end
end

specify "renders the content in the right order" do
expect(rendered_content).to have_tag(".govuk-footer__meta-item") { with_text(/before.*one.*two.*three.*after/m) }
end
end

describe "custom meta_licence text" do
let(:licence_text) { "Permission is hereby granted, free of charge, to any person obtaining a copy of this software" }
let(:kwargs) { { meta_licence: licence_text } }
Expand Down

0 comments on commit 4aa6264

Please sign in to comment.