Skip to content

Commit 8211b73

Browse files
committed
Allow setting custom licence HTML in footer
There is already an attribute to set custom licence text, however this does not allow including links or a logo, meaning it's not possible to internatialise the footer without removing these items. Allow passing in `licence_meta_html` as a block to be included instead of the default licence content.
1 parent 5dd1637 commit 8211b73

File tree

3 files changed

+46
-12
lines changed

3 files changed

+46
-12
lines changed

app/components/govuk_component/footer_component.html.erb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@
3232
</div>
3333
<% end %>
3434

35-
<% if meta_licence.nil? %>
35+
<% if meta_licence_content.nil? %>
3636
<svg aria-hidden="true" focusable="false" class="<%= brand %>-footer__licence-logo" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 483.2 195.7" height="17" width="41">
3737
<path fill="currentColor" d="M421.5 142.8V.1l-50.7 32.3v161.1h112.4v-50.7zm-122.3-9.6A47.12 47.12 0 0 1 221 97.8c0-26 21.1-47.1 47.1-47.1 16.7 0 31.4 8.7 39.7 21.8l42.7-27.2A97.63 97.63 0 0 0 268.1 0c-36.5 0-68.3 20.1-85.1 49.7A98 98 0 0 0 97.8 0C43.9 0 0 43.9 0 97.8s43.9 97.8 97.8 97.8c36.5 0 68.3-20.1 85.1-49.7a97.76 97.76 0 0 0 149.6 25.4l19.4 22.2h3v-87.8h-80l24.3 27.5zM97.8 145c-26 0-47.1-21.1-47.1-47.1s21.1-47.1 47.1-47.1 47.2 21 47.2 47S123.8 145 97.8 145" />
3838
</svg>
3939

4040
<%= tag.span(default_licence, class: "#{brand}-footer__licence-description") %>
41-
<% elsif meta_licence.present? %>
42-
<%= tag.span(meta_licence, class: "#{brand}-footer__licence-description") %>
41+
<% elsif meta_licence_content.present? %>
42+
<%= tag.span(meta_licence_content, class: "#{brand}-footer__licence-description") %>
4343
<% end %>
4444
</div>
4545

app/components/govuk_component/footer_component.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class GovukComponent::FooterComponent < GovukComponent::Base
66
renders_one :navigation
77
renders_one :content_before_meta_items
88
renders_one :content_after_meta_items
9+
renders_one :meta_licence_html
910

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

@@ -47,6 +48,10 @@ def meta_content
4748
meta_html || meta_text
4849
end
4950

51+
def meta_licence_content
52+
meta_licence_html || meta_licence
53+
end
54+
5055
def meta_classes
5156
["#{brand}-footer__meta"].append(@custom_meta_classes)
5257
end

spec/components/govuk_component/footer_component_spec.rb

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -139,19 +139,48 @@
139139
end
140140
end
141141

142-
describe "custom meta_licence text" do
143-
let(:licence_text) { "Permission is hereby granted, free of charge, to any person obtaining a copy of this software" }
144-
let(:kwargs) { { meta_licence: licence_text } }
142+
describe "custom licence content" do
145143
let(:licence_selector) { [selector, ".govuk-footer__licence-description"].join(" ") }
146144

147-
specify "the custom licence text should be rendered" do
148-
expect(rendered_content).to have_tag(licence_selector, text: licence_text)
145+
describe "meta_licence" do
146+
let(:licence_text) { "Permission is hereby granted, free of charge, to any person obtaining a copy of this software" }
147+
let(:kwargs) { { meta_licence: licence_text } }
148+
149+
specify "the custom licence text should be rendered" do
150+
expect(rendered_content).to have_tag(licence_selector, text: licence_text)
151+
end
152+
153+
specify "the licence SVG is not rendered" do
154+
expect(rendered_content).to have_tag("footer", with: { class: "govuk-footer" }) do
155+
with_tag("div", with: { class: "govuk-footer__meta" }) do
156+
without_tag("svg")
157+
end
158+
end
159+
end
149160
end
150161

151-
specify "the licence SVG is not rendered" do
152-
expect(rendered_content).to have_tag("footer", with: { class: "govuk-footer" }) do
153-
with_tag("div", with: { class: "govuk-footer__meta" }) do
154-
without_tag("svg")
162+
describe "meta_licence_html" do
163+
let(:custom_text) { "Some licence HTML" }
164+
let(:custom_tag) { "strong" }
165+
let(:custom_html) { helper.content_tag(custom_tag, custom_text) }
166+
167+
subject! do
168+
render_inline(GovukComponent::FooterComponent.new(**kwargs)) do |component|
169+
component.with_meta_licence_html { custom_html }
170+
end
171+
end
172+
173+
specify "the custom licence custom HTML is rendered" do
174+
expect(rendered_content).to have_tag(licence_selector) do
175+
with_tag(custom_tag, text: Regexp.new(custom_text))
176+
end
177+
end
178+
179+
specify "the licence SVG is not rendered" do
180+
expect(rendered_content).to have_tag("footer", with: { class: "govuk-footer" }) do
181+
with_tag("div", with: { class: "govuk-footer__meta" }) do
182+
without_tag("svg")
183+
end
155184
end
156185
end
157186
end

0 commit comments

Comments
 (0)