Skip to content

Commit

Permalink
Merge pull request #539 from alphagov/national-applicability-no-nav
Browse files Browse the repository at this point in the history
Add national applicability to universal navigation variant
  • Loading branch information
maxgds authored Nov 16, 2017
2 parents 0a65ef2 + 8dfbd93 commit 739a988
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 51 deletions.
9 changes: 7 additions & 2 deletions app/assets/stylesheets/components/_content-metadata.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@
border-bottom: 1px solid $border-colour;
}

.app-c-content-metadata__from {
.app-c-content-metadata__other {
margin-top: $gutter-half;

// Don't include a margin if there’s no published dates above
&:first-child {
margin-top: 0;
}
}

.app-c-content-metadata__from a {
.app-c-content-metadata__other a {
font-weight: bold;
}
12 changes: 6 additions & 6 deletions app/presenters/content_item/linkable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@ def part_of
})
end

def organisations_ordered_by_importance
organisations_with_emphasised_first.map do |link|
link_to(link["title"], link["base_path"])
end
end

private

def links(type)
Expand All @@ -41,6 +35,12 @@ def links_group(types)
types.flat_map { |type| links(type) }.uniq
end

def organisations_ordered_by_importance
organisations_with_emphasised_first.map do |link|
link_to(link["title"], link["base_path"])
end
end

def organisations_with_emphasised_first
expanded_links_from_content_item("organisations").sort_by do |organisation|
is_emphasised = organisation["content_id"].in?(emphasised_organisations)
Expand Down
11 changes: 11 additions & 0 deletions app/presenters/content_item/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ def metadata
}
end

def content_metadata
{
published: published,
last_updated: updated,
link_to_history: !!updated,
other: {
'From': organisations_ordered_by_importance
}
}
end

def document_footer
{
from: from,
Expand Down
6 changes: 6 additions & 0 deletions app/presenters/content_item/national_applicability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ def metadata
end
end

def content_metadata
super.tap do |m|
m[:other] = { 'Applies to': applies_to }.merge(m[:other])
end
end

private

def translated_schema_name(count)
Expand Down
23 changes: 16 additions & 7 deletions app/views/components/_content-metadata.html.erb
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
<%
published ||= false
last_updated ||= false
from ||= false
link_to_history ||= false
metadata = [published, last_updated, from]
other ||= {}
other_has_values = other.values.compact.reject(&:blank?).any?
metadata = [published, last_updated]
%>
<% if metadata.any? %>
<% if metadata.any? || other_has_values %>
<div class="app-c-content-metadata">
<div class="grid-row">
<div class="column-two-thirds">
<%= render 'components/published-dates', published: published, last_updated: last_updated, link_to_history: link_to_history %>
<% if from %>
<div class="app-c-content-metadata__from">
<%= t("govuk_component.content-metadata.from", default: "From") %>: <%= from.to_sentence.html_safe %>
<% if other_has_values %>
<div class="app-c-content-metadata__other">
<% other.each do |title, values| %>
<%
values ||= []
values = Array(values)
%>
<% if values.any? %>
<p><%= title %>: <%= values.to_sentence.html_safe %></p>
<% end %>
<% end %>
</div>
<% end %>
</div>
</div>
</div>
<% end %>
<% end %>
39 changes: 28 additions & 11 deletions app/views/components/docs/content-metadata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,19 @@ shared_accessibility_criteria:
examples:
default:
data:
from:
- <a href='/government/organisations/ministry-of-defence'>Ministry of Defence</a>
published: 31 July 2017
last_updated: 20 September 2017
other:
From:
- <a href='/government/organisations/ministry-of-defence'>Ministry of Defence</a>
with_history_link:
data:
from:
- <a href='/government/organisations/ministry-of-defence'>Ministry of Defence</a>
published: 31 July 2017
last_updated: 20 September 2017
link_to_history: true
other:
From:
- <a href='/government/organisations/ministry-of-defence'>Ministry of Defence</a>
no_last_updated:
data:
published: 31 July 2017
Expand All @@ -31,16 +33,31 @@ examples:
link_to_history: true
two_publishers:
data:
from:
- <a href='/government/organisations/department-for-education'>Department for Education</a>
- <a href='/government/organisations/education-funding-agency'>Education Funding Agency</a>
published: 31 July 2017
last_updated: 20 September 2017
other:
From:
- <a href='/government/organisations/department-for-education'>Department for Education</a>
- <a href='/government/organisations/education-funding-agency'>Education Funding Agency</a>
multiple_publishers_and_no_link_to_history:
data:
from:
- <a href='/government/organisations/department-for-education'>Department for Education</a>
- <a href='/government/organisations/education-funding-agency'>Education Funding Agency</a>
- <a href='/government/organisations/department-for-work-pensions'>Department for Work and Pensions</a>
published: 31 July 2017
last_updated: 20 September 2017
other:
From:
- <a href='/government/organisations/department-for-education'>Department for Education</a>
- <a href='/government/organisations/education-funding-agency'>Education Funding Agency</a>
- <a href='/government/organisations/department-for-work-pensions'>Department for Work and Pensions</a>
nothing:
description: |
If an `other` object is provided with keys that have no values the component does not render.
data:
other:
From:
Another: []
"Empty thing": false
"Also empty": {}
national_applicability:
data:
other:
Applies to: "England, Scotland, and Wales (see detailed guidance for <a href=\"http://www.dardni.gov.uk/news-dard-pa022-a-13-new-procedure-for\" rel=\"external\">Northern Ireland</a>)"
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,7 @@
</div>
</div>

<%= render 'components/content-metadata', {
published: @content_item.published,
last_updated: @content_item.updated,
link_to_history: !!@content_item.updated,
from: @content_item.organisations_ordered_by_importance
} %>

<%= render 'components/content-metadata', @content_item.content_metadata %>
<%= render 'components/notice', @content_item.withdrawal_notice_component %>
<%= render 'shared/history_notice', content_item: @content_item %>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,7 @@
</div>
</div>

<%= render 'components/content-metadata', {
published: @content_item.published,
last_updated: @content_item.updated,
link_to_history: !!@content_item.updated,
from: @content_item.organisations_ordered_by_importance
} %>

<%= render 'components/content-metadata', @content_item.content_metadata %>
<%= render 'components/notice', @content_item.withdrawal_notice_component %>
<%= render 'shared/history_notice', content_item: @content_item %>

Expand Down
27 changes: 16 additions & 11 deletions test/components/content_metadata_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,27 @@ def component_name
assert_empty render_component({})
end

test "does not render when an 'other' object is provided without any values" do
assert_empty render_component(other: { From: [] })
assert_empty render_component(other: { a: false, b: "", c: [], d: {}, e: nil })
end

test "renders a from link when from data is given" do
render_component(from: ["<a href='/government/organisations/ministry-of-defence'>Ministry of Defence</a>"])
assert_select ".app-c-content-metadata__from a[href='/government/organisations/ministry-of-defence']", text: 'Ministry of Defence'
assert_select ".app-c-content-metadata__from", text: 'From: Ministry of Defence'
render_component(other: { From: ["<a href='/government/organisations/ministry-of-defence'>Ministry of Defence</a>"] })
assert_select ".app-c-content-metadata__other a[href='/government/organisations/ministry-of-defence']", text: 'Ministry of Defence'
assert_select ".app-c-content-metadata__other", text: 'From: Ministry of Defence'
end


test "renders two from links when two publishers are given" do
render_component(from: ["<a href='/government/organisations/ministry-of-defence'>Ministry of Defence</a>", "<a href='/government/organisations/education-funding-agency'>Education Funding Agency</a>"])
assert_select ".app-c-content-metadata__from a[href='/government/organisations/ministry-of-defence']", text: 'Ministry of Defence'
assert_select ".app-c-content-metadata__from a[href='/government/organisations/education-funding-agency']", text: 'Education Funding Agency'
render_component(other: { From: ["<a href='/government/organisations/ministry-of-defence'>Ministry of Defence</a>", "<a href='/government/organisations/education-funding-agency'>Education Funding Agency</a>"] })
assert_select ".app-c-content-metadata__other a[href='/government/organisations/ministry-of-defence']", text: 'Ministry of Defence'
assert_select ".app-c-content-metadata__other a[href='/government/organisations/education-funding-agency']", text: 'Education Funding Agency'
end

test "renders a sentence when multiple publishers are given" do
render_component(from: ["<a href='/government/organisations/department-for-education'>Department for Education</a>", "<a href='/government/organisations/education-funding-agency'>Education Funding Agency</a>"])
assert_select ".app-c-content-metadata__from", text: 'From: Department for Education and Education Funding Agency'
render_component(other: { From: ["<a href='/government/organisations/department-for-education'>Department for Education</a>", "<a href='/government/organisations/education-funding-agency'>Education Funding Agency</a>"] })
assert_select ".app-c-content-metadata__other", text: 'From: Department for Education and Education Funding Agency'
end

test "renders published dates component when only published date is given" do
Expand All @@ -38,9 +43,9 @@ def component_name
end

test "renders full metadata component when all parameters are given" do
render_component(from: ["<a href='/government/organisations/ministry-of-defence'>Ministry of Defence</a>"], published: "31 July 2017", last_updated: "20 September 2017", link_to_history: true)
render_component(other: { From: ["<a href='/government/organisations/ministry-of-defence'>Ministry of Defence</a>"] }, published: "31 July 2017", last_updated: "20 September 2017", link_to_history: true)
assert_select ".app-c-published-dates"
assert_select ".app-c-content-metadata__from a[href='/government/organisations/ministry-of-defence']", text: 'Ministry of Defence'
assert_select ".app-c-content-metadata__from", text: 'From: Ministry of Defence'
assert_select ".app-c-content-metadata__other a[href='/government/organisations/ministry-of-defence']", text: 'Ministry of Defence'
assert_select ".app-c-content-metadata__other", text: 'From: Ministry of Defence'
end
end

0 comments on commit 739a988

Please sign in to comment.