govuk_navigation_helpers 1.0.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +6 -2
- data/govuk_navigation_helpers.gemspec +1 -1
- data/lib/govuk_navigation_helpers/breadcrumbs.rb +3 -1
- data/lib/govuk_navigation_helpers/content_item.rb +47 -0
- data/lib/govuk_navigation_helpers/grouped_related_links.rb +47 -0
- data/lib/govuk_navigation_helpers/related_items.rb +92 -0
- data/lib/govuk_navigation_helpers/version.rb +1 -1
- data/lib/govuk_navigation_helpers.rb +11 -1
- data/spec/breadcrumbs_spec.rb +5 -11
- data/spec/related_items_spec.rb +267 -0
- data/spec/spec_helper.rb +3 -0
- metadata +9 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae03499e445926565f940d61ac2ca8a9e6566f40
|
4
|
+
data.tar.gz: e4b3be57785db7c30e2846cb9b2d410d1b3f4309
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 08da4b0086ef29b400da2c05c5b87bbc5219656cefa84fbdf139beefc73e8e150a95ac81c7d4ee08aa412ead50289bff2df652149aa3d8cacb1091d61ce0d5a3
|
7
|
+
data.tar.gz: 3dd946e21c66b799ad1119e2a97a8db3d1cefb3d022e7fc04e6b9542d7d05a409f44d2d429815eaeaab70775738ea8e322fa09a713cda3c927aed34be8916a85
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -36,7 +36,11 @@ end
|
|
36
36
|
Render the component:
|
37
37
|
|
38
38
|
```ruby
|
39
|
-
<%= render partial: 'govuk_component/breadcrumbs', locals:
|
39
|
+
<%= render partial: 'govuk_component/breadcrumbs', locals: @navigation.breadcrumbs %>
|
40
|
+
```
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
<%= render partial: 'govuk_component/related_items', locals: @navigation.related_items %>
|
40
44
|
```
|
41
45
|
|
42
46
|
### Running the test suite
|
@@ -53,4 +57,4 @@ To run a Yard server locally to preview documentation, run:
|
|
53
57
|
|
54
58
|
## Licence
|
55
59
|
|
56
|
-
|
60
|
+
[MIT License](LICENCE.txt)
|
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.add_development_dependency "govuk-lint", "~> 1.2.1"
|
26
26
|
spec.add_development_dependency "pry-byebug", "~> 3.4"
|
27
27
|
spec.add_development_dependency "yard", "~> 0.8"
|
28
|
-
spec.add_development_dependency "govuk_schemas", "~> 0
|
28
|
+
spec.add_development_dependency "govuk_schemas", "~> 1.0"
|
29
29
|
|
30
30
|
spec.required_ruby_version = ">= 2.3.1"
|
31
31
|
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module GovukNavigationHelpers
|
2
|
+
# Simple wrapper around a content store representation of a content item. Works
|
3
|
+
# for both the main content item and the expanded links in the links hash.
|
4
|
+
#
|
5
|
+
# @private
|
6
|
+
class ContentItem
|
7
|
+
attr_reader :content_store_response
|
8
|
+
|
9
|
+
def initialize(content_store_response)
|
10
|
+
@content_store_response = content_store_response
|
11
|
+
end
|
12
|
+
|
13
|
+
def parent
|
14
|
+
parent_item = content_store_response.dig("links", "parent", 0)
|
15
|
+
return unless parent_item
|
16
|
+
ContentItem.new(parent_item)
|
17
|
+
end
|
18
|
+
|
19
|
+
def mainstream_browse_pages
|
20
|
+
content_store_response.dig("links", "mainstream_browse_pages").to_a.map do |link|
|
21
|
+
ContentItem.new(link)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def title
|
26
|
+
content_store_response.fetch("title")
|
27
|
+
end
|
28
|
+
|
29
|
+
def base_path
|
30
|
+
content_store_response.fetch("base_path")
|
31
|
+
end
|
32
|
+
|
33
|
+
def content_id
|
34
|
+
content_store_response.fetch("content_id")
|
35
|
+
end
|
36
|
+
|
37
|
+
def related_links
|
38
|
+
content_store_response.dig("links", "ordered_related_items").to_a.map do |link|
|
39
|
+
ContentItem.new(link)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def external_links
|
44
|
+
content_store_response.dig("details", "external_related_links").to_a
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module GovukNavigationHelpers
|
2
|
+
# Take a content item and group the related links according to an algorithm
|
3
|
+
# that is intended to display the related links into three groups, depending
|
4
|
+
# on how much they have in common with the main content item.
|
5
|
+
#
|
6
|
+
# @private
|
7
|
+
class GroupedRelatedLinks
|
8
|
+
attr_reader :content_item
|
9
|
+
|
10
|
+
def initialize(content_item)
|
11
|
+
@content_item = content_item
|
12
|
+
end
|
13
|
+
|
14
|
+
# This will return related items that are tagged to the same mainstream
|
15
|
+
# browse page as the main content item.
|
16
|
+
def tagged_to_same_mainstream_browse_page
|
17
|
+
return [] unless content_item.parent
|
18
|
+
|
19
|
+
@tagged_to_same_mainstream_browse_page ||= content_item.related_links.select do |related_item|
|
20
|
+
related_item.mainstream_browse_pages.map(&:content_id).include?(content_item.parent.content_id)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# This will return related items whose parents are tagged to the same mainstream
|
25
|
+
# browse page as the main content item's parent.
|
26
|
+
def parents_tagged_to_same_mainstream_browse_page
|
27
|
+
return [] unless content_item.parent && content_item.parent.parent
|
28
|
+
|
29
|
+
common_parent_content_ids = tagged_to_same_mainstream_browse_page.map(&:content_id)
|
30
|
+
|
31
|
+
@parents_tagged_to_same_mainstream_browse_page ||= content_item.related_links.select do |related_item|
|
32
|
+
next if common_parent_content_ids.include?(related_item.content_id)
|
33
|
+
related_item.mainstream_browse_pages.map(&:parent).map(&:content_id).include?(content_item.parent.parent.content_id)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# This will return related links that are tagged to mainstream browse
|
38
|
+
# pages unrelated to the main content item.
|
39
|
+
def tagged_to_different_mainstream_browse_pages
|
40
|
+
all_content_ids = (tagged_to_same_mainstream_browse_page + parents_tagged_to_same_mainstream_browse_page).map(&:content_id)
|
41
|
+
|
42
|
+
@tagged_to_different_mainstream_browse_pages ||= content_item.related_links.reject do |related_item|
|
43
|
+
all_content_ids.include?(related_item.content_id)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'govuk_navigation_helpers/grouped_related_links'
|
2
|
+
require 'govuk_navigation_helpers/content_item'
|
3
|
+
|
4
|
+
module GovukNavigationHelpers
|
5
|
+
# Generate data for the "Related Items" component
|
6
|
+
#
|
7
|
+
# http://govuk-component-guide.herokuapp.com/components/related_items
|
8
|
+
#
|
9
|
+
# The procedure to group the links is quite complicated. In short, related links
|
10
|
+
# are grouped by how related they are to the current page.
|
11
|
+
#
|
12
|
+
# The wiki page on related items has more information:
|
13
|
+
#
|
14
|
+
# https://gov-uk.atlassian.net/wiki/pages/viewpage.action?pageId=99876878
|
15
|
+
class RelatedItems
|
16
|
+
def initialize(content_item)
|
17
|
+
@content_item = ContentItem.new(content_item)
|
18
|
+
end
|
19
|
+
|
20
|
+
def related_items
|
21
|
+
{
|
22
|
+
sections: [
|
23
|
+
tagged_to_same_mainstream_browse_page_section,
|
24
|
+
parents_tagged_to_same_mainstream_browse_page_section,
|
25
|
+
tagged_to_different_mainstream_browse_pages_section,
|
26
|
+
related_external_links_section,
|
27
|
+
].compact
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
attr_reader :content_item
|
34
|
+
|
35
|
+
def tagged_to_same_mainstream_browse_page_section
|
36
|
+
return unless grouped.tagged_to_same_mainstream_browse_page.any?
|
37
|
+
|
38
|
+
items = grouped.tagged_to_same_mainstream_browse_page.map do |related_item|
|
39
|
+
{
|
40
|
+
title: related_item.title,
|
41
|
+
url: related_item.base_path
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
{ title: content_item.parent.title, url: content_item.parent.base_path, items: items }
|
46
|
+
end
|
47
|
+
|
48
|
+
def parents_tagged_to_same_mainstream_browse_page_section
|
49
|
+
return unless grouped.parents_tagged_to_same_mainstream_browse_page.any?
|
50
|
+
|
51
|
+
items = grouped.parents_tagged_to_same_mainstream_browse_page.map do |related_item|
|
52
|
+
{
|
53
|
+
title: related_item.title,
|
54
|
+
url: related_item.base_path
|
55
|
+
}
|
56
|
+
end
|
57
|
+
|
58
|
+
{ title: content_item.parent.parent.title, url: content_item.parent.parent.base_path, items: items }
|
59
|
+
end
|
60
|
+
|
61
|
+
def tagged_to_different_mainstream_browse_pages_section
|
62
|
+
return unless grouped.tagged_to_different_mainstream_browse_pages.any?
|
63
|
+
|
64
|
+
items = grouped.tagged_to_different_mainstream_browse_pages.map do |related_item|
|
65
|
+
{
|
66
|
+
title: related_item.title,
|
67
|
+
url: related_item.base_path
|
68
|
+
}
|
69
|
+
end
|
70
|
+
|
71
|
+
{ title: "Elsewhere on GOV.UK", items: items }
|
72
|
+
end
|
73
|
+
|
74
|
+
def related_external_links_section
|
75
|
+
return unless content_item.external_links.any?
|
76
|
+
|
77
|
+
items = content_item.external_links.map do |h|
|
78
|
+
{
|
79
|
+
title: h.fetch("title"),
|
80
|
+
url: h.fetch("url"),
|
81
|
+
rel: "external"
|
82
|
+
}
|
83
|
+
end
|
84
|
+
|
85
|
+
{ title: "Elsewhere on the web", items: items }
|
86
|
+
end
|
87
|
+
|
88
|
+
def grouped
|
89
|
+
@grouped ||= GroupedRelatedLinks.new(content_item)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require "govuk_navigation_helpers/version"
|
2
2
|
require "govuk_navigation_helpers/breadcrumbs"
|
3
|
+
require "govuk_navigation_helpers/related_items"
|
3
4
|
|
4
5
|
module GovukNavigationHelpers
|
5
6
|
class NavigationHelper
|
@@ -9,11 +10,20 @@ module GovukNavigationHelpers
|
|
9
10
|
|
10
11
|
# Generate a breacrumb trail
|
11
12
|
#
|
12
|
-
# @return [
|
13
|
+
# @return [Hash] Payload for the GOV.UK breadcrumbs component
|
14
|
+
# @see http://govuk-component-guide.herokuapp.com/components/breadcrumbs
|
13
15
|
def breadcrumbs
|
14
16
|
Breadcrumbs.new(content_item).breadcrumbs
|
15
17
|
end
|
16
18
|
|
19
|
+
# Generate a related items payload
|
20
|
+
#
|
21
|
+
# @return [Hash] Payload for the GOV.UK Component
|
22
|
+
# @see http://govuk-component-guide.herokuapp.com/components/related_items
|
23
|
+
def related_items
|
24
|
+
RelatedItems.new(content_item).related_items
|
25
|
+
end
|
26
|
+
|
17
27
|
private
|
18
28
|
|
19
29
|
attr_reader :content_item
|
data/spec/breadcrumbs_spec.rb
CHANGED
@@ -1,17 +1,11 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'govuk_navigation_helpers'
|
3
|
-
require 'govuk_schemas'
|
4
2
|
|
5
3
|
RSpec.describe GovukNavigationHelpers::Breadcrumbs do
|
6
4
|
describe "#breadcrumbs" do
|
7
5
|
it "can handle any valid content item" do
|
8
6
|
generator = GovukSchemas::RandomExample.for_schema("placeholder", schema_type: "frontend")
|
9
7
|
|
10
|
-
|
11
|
-
expect {
|
12
|
-
described_class.new(generator.payload).breadcrumbs
|
13
|
-
}.to_not raise_error
|
14
|
-
end
|
8
|
+
expect { GovukNavigationHelpers::Breadcrumbs.new(generator.payload).breadcrumbs }.to_not raise_error
|
15
9
|
end
|
16
10
|
|
17
11
|
it "returns the root when parent is not specified" do
|
@@ -19,7 +13,7 @@ RSpec.describe GovukNavigationHelpers::Breadcrumbs do
|
|
19
13
|
breadcrumbs = breadcrumbs_for(content_item)
|
20
14
|
|
21
15
|
expect(breadcrumbs).to eq(
|
22
|
-
[
|
16
|
+
breadcrumbs: [
|
23
17
|
{ title: "Home", url: "/" },
|
24
18
|
]
|
25
19
|
)
|
@@ -30,7 +24,7 @@ RSpec.describe GovukNavigationHelpers::Breadcrumbs do
|
|
30
24
|
breadcrumbs = breadcrumbs_for(content_item)
|
31
25
|
|
32
26
|
expect(breadcrumbs).to eq(
|
33
|
-
[
|
27
|
+
breadcrumbs: [
|
34
28
|
{ title: "Home", url: "/" },
|
35
29
|
]
|
36
30
|
)
|
@@ -48,7 +42,7 @@ RSpec.describe GovukNavigationHelpers::Breadcrumbs do
|
|
48
42
|
breadcrumbs = breadcrumbs_for(content_item)
|
49
43
|
|
50
44
|
expect(breadcrumbs).to eq(
|
51
|
-
[
|
45
|
+
breadcrumbs: [
|
52
46
|
{ title: "Home", url: "/" },
|
53
47
|
{ title: "A-parent", url: "/a-parent" }
|
54
48
|
]
|
@@ -77,7 +71,7 @@ RSpec.describe GovukNavigationHelpers::Breadcrumbs do
|
|
77
71
|
breadcrumbs = breadcrumbs_for(content_item)
|
78
72
|
|
79
73
|
expect(breadcrumbs).to eq(
|
80
|
-
[
|
74
|
+
breadcrumbs: [
|
81
75
|
{ title: "Home", url: "/" },
|
82
76
|
{ title: "Another-parent", url: "/another-parent" },
|
83
77
|
{ title: "A-parent", url: "/a-parent" }
|
@@ -0,0 +1,267 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe GovukNavigationHelpers::RelatedItems do
|
4
|
+
def payload_for(content_item)
|
5
|
+
generator = GovukSchemas::RandomExample.for_schema("placeholder", schema_type: "frontend")
|
6
|
+
fully_valid_content_item = generator.merge_and_validate(content_item)
|
7
|
+
GovukNavigationHelpers::NavigationHelper.new(fully_valid_content_item).related_items
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "#related_items" do
|
11
|
+
it "can handle randomly generated content" do
|
12
|
+
generator = GovukSchemas::RandomExample.for_schema("placeholder", schema_type: "frontend")
|
13
|
+
|
14
|
+
expect { payload_for(generator.payload) }.to_not raise_error
|
15
|
+
end
|
16
|
+
|
17
|
+
it "returns nothing if there are no related links" do
|
18
|
+
nothing = payload_for(
|
19
|
+
"details" => {
|
20
|
+
"external_related_links" => []
|
21
|
+
},
|
22
|
+
"links" => {
|
23
|
+
}
|
24
|
+
)
|
25
|
+
|
26
|
+
expect(nothing).to eql(sections: [])
|
27
|
+
end
|
28
|
+
|
29
|
+
it "returns an elswhere on GOV.UK section for related items with no browse pages in common" do
|
30
|
+
payload = payload_for(
|
31
|
+
"details" => {
|
32
|
+
"external_related_links" => []
|
33
|
+
},
|
34
|
+
"links" => {
|
35
|
+
"ordered_related_items" => [
|
36
|
+
{
|
37
|
+
"title" => "Foo",
|
38
|
+
"content_id" => "fdbf634c-06f5-43ea-915a-53b34b660353",
|
39
|
+
"base_path" => "/foo",
|
40
|
+
"locale" => "en"
|
41
|
+
}
|
42
|
+
]
|
43
|
+
}
|
44
|
+
)
|
45
|
+
|
46
|
+
expect(payload).to eql(
|
47
|
+
sections: [
|
48
|
+
{
|
49
|
+
title: "Elsewhere on GOV.UK",
|
50
|
+
items: [
|
51
|
+
{ title: "Foo", url: "/foo" },
|
52
|
+
]
|
53
|
+
},
|
54
|
+
]
|
55
|
+
)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "returns the external related links" do
|
59
|
+
payload = payload_for(
|
60
|
+
"details" => {
|
61
|
+
"external_related_links" => [
|
62
|
+
{ "title" => "Foo", "url" => "https://example.org/foo" },
|
63
|
+
{ "title" => "Bar", "url" => "https://example.org/bar" }
|
64
|
+
]
|
65
|
+
},
|
66
|
+
"links" => {
|
67
|
+
}
|
68
|
+
)
|
69
|
+
|
70
|
+
expect(payload).to eql(
|
71
|
+
sections: [
|
72
|
+
{
|
73
|
+
title: "Elsewhere on the web",
|
74
|
+
items: [
|
75
|
+
{ title: "Foo", url: "https://example.org/foo", rel: "external" },
|
76
|
+
{ title: "Bar", url: "https://example.org/bar", rel: "external" },
|
77
|
+
]
|
78
|
+
},
|
79
|
+
]
|
80
|
+
)
|
81
|
+
end
|
82
|
+
|
83
|
+
it "returns a primary section for related items tagged to the same mainstream browse page as the item" do
|
84
|
+
payload = payload_for(
|
85
|
+
"details" => {
|
86
|
+
"external_related_links" => []
|
87
|
+
},
|
88
|
+
"links" => {
|
89
|
+
"parent" => [
|
90
|
+
{
|
91
|
+
"title" => "Foo's parent",
|
92
|
+
"content_id" => "a9c6f24a-92a1-4ead-a776-532d1d99123c",
|
93
|
+
"base_path" => "/foo-parent",
|
94
|
+
"locale" => "en"
|
95
|
+
}
|
96
|
+
],
|
97
|
+
"ordered_related_items" => [
|
98
|
+
{
|
99
|
+
"content_id" => "9effaabe-346d-4ad0-9c1b-baa49bc084d6",
|
100
|
+
"title" => "Foo",
|
101
|
+
"base_path" => "/bar",
|
102
|
+
"locale" => "en",
|
103
|
+
"links" => {
|
104
|
+
"mainstream_browse_pages" => [
|
105
|
+
{
|
106
|
+
"title" => "Foo's parent",
|
107
|
+
"content_id" => "a9c6f24a-92a1-4ead-a776-532d1d99123c",
|
108
|
+
"base_path" => "/foo-parent",
|
109
|
+
"locale" => "en"
|
110
|
+
}
|
111
|
+
]
|
112
|
+
}
|
113
|
+
}
|
114
|
+
]
|
115
|
+
}
|
116
|
+
)
|
117
|
+
|
118
|
+
expect(payload).to eql(
|
119
|
+
sections: [
|
120
|
+
{
|
121
|
+
title: "Foo's parent",
|
122
|
+
url: "/foo-parent",
|
123
|
+
items: [
|
124
|
+
{ title: "Foo", url: "/bar" },
|
125
|
+
]
|
126
|
+
},
|
127
|
+
]
|
128
|
+
)
|
129
|
+
end
|
130
|
+
|
131
|
+
it "returns a secondary section for related items tagged to the same mainstream browse page as the item's parent" do
|
132
|
+
payload = payload_for(
|
133
|
+
"details" => {
|
134
|
+
"external_related_links" => []
|
135
|
+
},
|
136
|
+
"links" => {
|
137
|
+
"parent" => [
|
138
|
+
{
|
139
|
+
"title" => "Foo's parent",
|
140
|
+
"content_id" => "67c28e19-9934-462c-b174-db5b8e566384",
|
141
|
+
"base_path" => "/foo-parent",
|
142
|
+
"locale" => "en",
|
143
|
+
"links" => {
|
144
|
+
"parent" => [
|
145
|
+
{
|
146
|
+
"title" => "Foo's grandparent",
|
147
|
+
"content_id" => "a9c6f24a-92a1-4ead-a776-532d1d99123c",
|
148
|
+
"base_path" => "/foo-grand-parent",
|
149
|
+
"locale" => "en",
|
150
|
+
}
|
151
|
+
]
|
152
|
+
}
|
153
|
+
}
|
154
|
+
],
|
155
|
+
"ordered_related_items" => [
|
156
|
+
{
|
157
|
+
"content_id" => "9effaabe-346d-4ad0-9c1b-baa49bc084d6",
|
158
|
+
"title" => "Foo",
|
159
|
+
"base_path" => "/bar",
|
160
|
+
"locale" => "en",
|
161
|
+
"links" => {
|
162
|
+
"mainstream_browse_pages" => [
|
163
|
+
{
|
164
|
+
"title" => "Some sibling of foo-parent",
|
165
|
+
"content_id" => "c34672dc-2ff3-4d28-92fd-bcba382e8a0b",
|
166
|
+
"base_path" => "/foo-sibling",
|
167
|
+
"locale" => "en",
|
168
|
+
"links" => {
|
169
|
+
"parent" => [
|
170
|
+
{
|
171
|
+
"title" => "Foo's grandparent",
|
172
|
+
"content_id" => "a9c6f24a-92a1-4ead-a776-532d1d99123c",
|
173
|
+
"base_path" => "/foo-grand-parent",
|
174
|
+
"locale" => "en",
|
175
|
+
}
|
176
|
+
]
|
177
|
+
}
|
178
|
+
}
|
179
|
+
]
|
180
|
+
}
|
181
|
+
}
|
182
|
+
]
|
183
|
+
}
|
184
|
+
)
|
185
|
+
|
186
|
+
expect(payload).to eql(
|
187
|
+
sections: [
|
188
|
+
{
|
189
|
+
title: "Foo's grandparent",
|
190
|
+
url: "/foo-grand-parent",
|
191
|
+
items: [
|
192
|
+
{ title: "Foo", url: "/bar" },
|
193
|
+
]
|
194
|
+
},
|
195
|
+
]
|
196
|
+
)
|
197
|
+
end
|
198
|
+
|
199
|
+
it "returns only related items in the primary section where they are tagged to the same mainstream browse pages as both the item and the item's parent" do
|
200
|
+
payload = payload_for(
|
201
|
+
"details" => {
|
202
|
+
"external_related_links" => []
|
203
|
+
},
|
204
|
+
"links" => {
|
205
|
+
"parent" => [
|
206
|
+
{
|
207
|
+
"title" => "Foo's parent",
|
208
|
+
"content_id" => "67c28e19-9934-462c-b174-db5b8e566384",
|
209
|
+
"base_path" => "/foo-parent",
|
210
|
+
"locale" => "en",
|
211
|
+
"links" => {
|
212
|
+
"parent" => [
|
213
|
+
{
|
214
|
+
"title" => "Foo's grandparent",
|
215
|
+
"content_id" => "a9c6f24a-92a1-4ead-a776-532d1d99123c",
|
216
|
+
"base_path" => "/foo-grand-parent",
|
217
|
+
"locale" => "en",
|
218
|
+
}
|
219
|
+
]
|
220
|
+
}
|
221
|
+
}
|
222
|
+
],
|
223
|
+
"ordered_related_items" => [
|
224
|
+
{
|
225
|
+
"content_id" => "9effaabe-346d-4ad0-9c1b-baa49bc084d6",
|
226
|
+
"title" => "Foo",
|
227
|
+
"base_path" => "/bar",
|
228
|
+
"locale" => "en",
|
229
|
+
"links" => {
|
230
|
+
"mainstream_browse_pages" => [
|
231
|
+
{
|
232
|
+
"title" => "Foo's parent",
|
233
|
+
"content_id" => "67c28e19-9934-462c-b174-db5b8e566384",
|
234
|
+
"base_path" => "/foo-parent",
|
235
|
+
"locale" => "en",
|
236
|
+
"links" => {
|
237
|
+
"parent" => [
|
238
|
+
{
|
239
|
+
"title" => "Foo's grandparent",
|
240
|
+
"content_id" => "a9c6f24a-92a1-4ead-a776-532d1d99123c",
|
241
|
+
"base_path" => "/foo-grand-parent",
|
242
|
+
"locale" => "en",
|
243
|
+
}
|
244
|
+
]
|
245
|
+
}
|
246
|
+
}
|
247
|
+
]
|
248
|
+
}
|
249
|
+
}
|
250
|
+
]
|
251
|
+
}
|
252
|
+
)
|
253
|
+
|
254
|
+
expect(payload).to eql(
|
255
|
+
sections: [
|
256
|
+
{
|
257
|
+
title: "Foo's parent",
|
258
|
+
url: "/foo-parent",
|
259
|
+
items: [
|
260
|
+
{ title: "Foo", url: "/bar" },
|
261
|
+
]
|
262
|
+
},
|
263
|
+
]
|
264
|
+
)
|
265
|
+
end
|
266
|
+
end
|
267
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
require 'govuk_navigation_helpers'
|
2
|
+
require 'govuk_schemas'
|
3
|
+
|
1
4
|
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
5
|
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
6
|
# The generated `.rspec` file contains `--require spec_helper` which will cause
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: govuk_navigation_helpers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GOV.UK Dev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-10-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -114,14 +114,14 @@ dependencies:
|
|
114
114
|
requirements:
|
115
115
|
- - "~>"
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: '0
|
117
|
+
version: '1.0'
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: '0
|
124
|
+
version: '1.0'
|
125
125
|
description: Gem to transform items from the content-store into payloads for GOV.UK
|
126
126
|
components
|
127
127
|
email:
|
@@ -142,8 +142,12 @@ files:
|
|
142
142
|
- jenkins.sh
|
143
143
|
- lib/govuk_navigation_helpers.rb
|
144
144
|
- lib/govuk_navigation_helpers/breadcrumbs.rb
|
145
|
+
- lib/govuk_navigation_helpers/content_item.rb
|
146
|
+
- lib/govuk_navigation_helpers/grouped_related_links.rb
|
147
|
+
- lib/govuk_navigation_helpers/related_items.rb
|
145
148
|
- lib/govuk_navigation_helpers/version.rb
|
146
149
|
- spec/breadcrumbs_spec.rb
|
150
|
+
- spec/related_items_spec.rb
|
147
151
|
- spec/spec_helper.rb
|
148
152
|
homepage: https://github.com/alphagov/govuk_navigation_helpers
|
149
153
|
licenses:
|
@@ -171,4 +175,5 @@ specification_version: 4
|
|
171
175
|
summary: Gem to transform items from the content-store into payloads for GOV.UK components
|
172
176
|
test_files:
|
173
177
|
- spec/breadcrumbs_spec.rb
|
178
|
+
- spec/related_items_spec.rb
|
174
179
|
- spec/spec_helper.rb
|