Skip to content

Commit 27d9c1e

Browse files
authored
Allow setting custom licence HTML in footer (#590)
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. If this change seems sensible, I can attempt to update the documentation.
2 parents 31dd357 + 96cceed commit 27d9c1e

File tree

5 files changed

+63
-12
lines changed

5 files changed

+63
-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

guide/content/components/footer.slim

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ p The footer provides copyright, licensing and other information about your
5151
code: footer_with_custom_copyright_and_licence,
5252
data: footer_copyright_and_licence_arguments)
5353

54+
== render('/partials/example.*',
55+
caption: "Footer with custom licence HTML",
56+
code: footer_with_custom_licence_html) do
57+
58+
markdown:
59+
The `meta_licence_html` slot allows replacing the licence information with any custom HTML.
60+
5461
== render('/partials/example.*',
5562
caption: "Footer with navigation",
5663
code: footer_with_navigation)

guide/lib/examples/footer_helpers.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,16 @@ def footer_copyright_and_licence_arguments
6666
FOOTER_COPYRIGHT_AND_LICENCE
6767
end
6868

69+
def footer_with_custom_licence_html
70+
<<~FOOTER
71+
= govuk_footer do |footer|
72+
- footer.with_meta_licence_html do
73+
|> Some custom HTML for the licence,
74+
perhaps with a
75+
= govuk_footer_link_to("link", "https://x-govuk.github.io/")
76+
FOOTER
77+
end
78+
6979
def footer_with_navigation
7080
<<~FOOTER_WITH_NAVIGATION
7181
= govuk_footer do |footer|

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)