-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from DFE-Digital/footer
Add the footer component
- Loading branch information
Showing
7 changed files
with
284 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<footer class="govuk-footer " role="contentinfo"> | ||
<div class="govuk-width-container "> | ||
<% if content.present? %> | ||
<%= content %> | ||
<% end %> | ||
<div class="govuk-footer__meta"> | ||
<div class="govuk-footer__meta-item govuk-footer__meta-item--grow"> | ||
<% if @meta_links.any? %> | ||
<%= @meta_heading %> | ||
<ul class="govuk-footer__inline-list"> | ||
<% @meta_links.each do |meta_link| %> | ||
<li class="govuk-footer__inline-list-item"> | ||
<%= meta_link %> | ||
</li> | ||
<% end %> | ||
</ul> | ||
<% end %> | ||
<svg aria-hidden="true" focusable="false" class="govuk-footer__licence-logo" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 483.2 195.7" height="17" width="41"> | ||
<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" /> | ||
</svg> | ||
<span class="govuk-footer__licence-description"> | ||
<%= @licence %> | ||
</span> | ||
</div> | ||
<div class="govuk-footer__meta-item"> | ||
<%= @copyright %> | ||
</div> | ||
</div> | ||
</div> | ||
</footer> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
class GovukComponent::Footer < ViewComponent::Base | ||
attr_accessor :meta, :licence, :copyright | ||
|
||
def initialize(meta_links: nil, meta_heading: default_meta_heading, licence: nil, copyright_text: default_copright_text, copyright_url: default_copyright_url) | ||
@meta_links = build_meta_links(meta_links) | ||
@meta_heading = raw(tag.h2(meta_heading, class: 'govuk-visually-hidden')) | ||
@licence = licence || default_licence | ||
@copyright = build_copyright(copyright_text, copyright_url) | ||
end | ||
|
||
private | ||
|
||
def build_meta_links(links) | ||
return [] if links.blank? | ||
|
||
fail(ArgumentError, 'meta links must be a hash') unless links.is_a?(Hash) | ||
|
||
links.map { |text, href| raw(link_to(text, href, class: %w(govuk-footer__link))) } | ||
end | ||
|
||
def default_meta_heading | ||
'Supporting links' | ||
end | ||
|
||
def default_licence | ||
link = link_to("Open Government Licence v3.0", "https://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/") | ||
|
||
raw(%(All content is available under the #{link}, except where otherwise stated)) | ||
end | ||
|
||
def build_copyright(text, url) | ||
link_to(text, url, class: %w(govuk-footer__link govuk-footer__copyright-logo)) | ||
end | ||
|
||
def default_copright_text | ||
raw(%(© Crown copyright)) | ||
end | ||
|
||
def default_copyright_url | ||
"https://www.nationalarchives.gov.uk/information-management/re-using-public-sector-information/uk-government-licensing-framework/crown-copyright/" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe(GovukComponent::Footer, type: :component) do | ||
subject do | ||
Capybara::Node::Simple.new(render_inline(component).to_html) | ||
end | ||
|
||
context 'when no arguments are supplied' do | ||
let(:component) { GovukComponent::Footer.new } | ||
|
||
specify 'the default licence info is included' do | ||
expect(subject).to have_css('footer.govuk-footer .govuk-footer__meta') do | ||
expect(page).to have_css('.govuk-footer__licence-description') do | ||
expect(page).to have_content(/All content is available under/) | ||
expect(page).to have_link("Open Government Licence v3.0", href: "https://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/") | ||
end | ||
end | ||
end | ||
|
||
specify 'the default copyright information is included' do | ||
expect(subject).to have_css('footer.govuk-footer .govuk-footer__meta') do | ||
expect(page).to have_css('.govuk-footer__meta-item', text: %r{\© Crown copyright}) | ||
end | ||
end | ||
|
||
specify 'the crown symbol is included' do | ||
expect(subject).to have_css('footer.govuk-footer .govuk-footer__meta') do | ||
expect(page).to have_css('svg', class: 'govuk-footer__licence-logo') | ||
end | ||
end | ||
end | ||
|
||
context 'when custom licence and copyright info are supplied' do | ||
let(:custom_copyright) { "All rights reserved" } | ||
let(:custom_copyright_url) { "https://en.wikipedia.org/wiki/All_rights_reserved" } | ||
let(:custom_licence_url) { "https://mit-license.org/" } | ||
let(:custom_licence) do | ||
%(Licenced under the <a href="#{custom_licence_url}">MIT Licence</a>.) | ||
end | ||
|
||
let(:component) { GovukComponent::Footer.new(licence: custom_licence, copyright_text: custom_copyright, copyright_url: custom_copyright_url) } | ||
|
||
specify 'the custom licence should have replaced the default' do | ||
expect(subject).to have_css('footer.govuk-footer .govuk-footer__meta') do | ||
within('.govuk-footer__licence-description') do | ||
expect(page).to have_content(custom_licence) | ||
expect(page).to have_link("MIT Licence", href: custom_licence_url) | ||
|
||
expect(page).not_to content(/All content is available under/) | ||
end | ||
end | ||
end | ||
|
||
specify 'the custom copyright should have replaced the default' do | ||
expect(subject).to have_css('footer.govuk-footer .govuk-footer__meta') do | ||
expect(page).to have_css('.govuk-footer__meta-item') do | ||
expect(page).to have_link(custom_copyright, href: custom_copyright_url) | ||
end | ||
end | ||
end | ||
end | ||
|
||
xcontext 'when custom content is passed in' do | ||
let(:content) do | ||
capture do | ||
content_tag('nav') do | ||
concat(tag.h3('Navigation')) | ||
end | ||
end | ||
end | ||
let(:component) { GovukComponent::Footer.new { content } } | ||
|
||
specify 'the content should be rendered' do | ||
expect(subject).to have_css('footer.govuk-footer .govuk-footer__meta') do | ||
expect(page).to have_css('nav', text: 'Navigation') | ||
end | ||
end | ||
end | ||
|
||
describe 'meta links' do | ||
let(:component) { GovukComponent::Footer.new(meta_links: links, meta_heading: heading) } | ||
|
||
context 'when meta links are supplied' do | ||
let(:heading) { 'Related info' } | ||
|
||
let(:links) do | ||
{ one: '/one', two: '/two', three: '/three' } | ||
end | ||
|
||
it { is_expected.to have_css('ul.govuk-footer__inline-list') } | ||
it { is_expected.to have_css('h2', class: 'govuk-visually-hidden', text: heading) } | ||
|
||
specify 'the meta links should be rendered' do | ||
expect(subject).to have_css('footer.govuk-footer .govuk-footer__meta') do | ||
expect(page).to have_css('li', class: 'govuk-footer__inline-list-item', count: links.size) | ||
|
||
links.each do |text, href| | ||
expect(page).to have_link(text, href: href) | ||
end | ||
end | ||
end | ||
end | ||
|
||
context 'when no meta links are supplied' do | ||
let(:links) { {} } | ||
let(:heading) { 'This should be absent' } | ||
|
||
it { is_expected.not_to have_css('ul.govuk-footer__inline-list') } | ||
it { is_expected.not_to have_css('h2', class: 'govuk-visually-hidden', text: heading) } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.