govuk_publishing_components 12.5.0 → 12.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/views/govuk_publishing_components/components/_breadcrumbs.html.erb +11 -22
- data/app/views/govuk_publishing_components/components/docs/breadcrumbs.yml +1 -0
- data/lib/govuk_publishing_components/app_helpers/taxon_breadcrumbs.rb +1 -1
- data/lib/govuk_publishing_components/presenters/breadcrumbs.rb +58 -5
- data/lib/govuk_publishing_components/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24ceb44b4f462698eac37aae0a7b7f3f97eb581a8a079ab8cc95fdb2fffdc545
|
4
|
+
data.tar.gz: 5e89d14681030ec55c196e689222439a792412d449df0c49a5a34ba07611a452
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cbac9fc0b488a44d378b1324b5dcb6441db28b257d4fbc6e80065c2c56bf372d878f9b9320fdda0f0b2fef461efc87ac34cc02e4d1f171529073f293a798e2ea
|
7
|
+
data.tar.gz: 95ed81d296db98e98ac644d6c5f22eada8f756b93917219f14957eac96f42b982dd5cf6462abcb035dfead053faa5643a98d5b71e050c68d70eff0766e793fb0
|
@@ -4,44 +4,33 @@
|
|
4
4
|
inverse ||= false
|
5
5
|
collapse_class = collapse_on_mobile && breadcrumbs.any? { |crumb| crumb[:is_page_parent] } ? "gem-c-breadcrumbs--collapse-on-mobile" : ""
|
6
6
|
invert_class = inverse ? "gem-c-breadcrumbs--inverse" : ""
|
7
|
-
|
7
|
+
breadcrumb_presenter = GovukPublishingComponents::Presenters::Breadcrumbs.new(breadcrumbs, request.path)
|
8
8
|
%>
|
9
9
|
|
10
10
|
<script type="application/ld+json">
|
11
|
-
<%= raw structured_data.to_json %>
|
11
|
+
<%= raw breadcrumb_presenter.structured_data.to_json %>
|
12
12
|
</script>
|
13
13
|
|
14
14
|
<div class="gem-c-breadcrumbs govuk-breadcrumbs <%= invert_class %>" data-module="track-click">
|
15
15
|
<ol class="govuk-breadcrumbs__list">
|
16
16
|
<% breadcrumbs.each_with_index do |crumb, index| %>
|
17
|
-
<%
|
18
|
-
|
19
|
-
|
20
|
-
aria_current = crumb[:is_current_page] ? 'page' : 'false'
|
21
|
-
%>
|
22
|
-
<li class="govuk-breadcrumbs__list-item" aria-current="<%= aria_current %>">
|
23
|
-
<% if is_link %>
|
17
|
+
<% breadcrumb = GovukPublishingComponents::Presenters::Breadcrumb.new(crumb, index) %>
|
18
|
+
<li class="govuk-breadcrumbs__list-item" aria-current="<%= breadcrumb.aria_current %>">
|
19
|
+
<% if breadcrumb.is_link? %>
|
24
20
|
<%= link_to(
|
25
|
-
|
26
|
-
path,
|
27
|
-
data:
|
28
|
-
track_category: 'breadcrumbClicked',
|
29
|
-
track_action: index + 1,
|
30
|
-
track_label: path,
|
31
|
-
track_options: {
|
32
|
-
dimension28: breadcrumbs.length.to_s,
|
33
|
-
dimension29: crumb[:title]
|
34
|
-
}
|
35
|
-
},
|
21
|
+
breadcrumb[:title],
|
22
|
+
breadcrumb.path,
|
23
|
+
data: breadcrumb.tracking_data(breadcrumbs.length),
|
36
24
|
class: "govuk-breadcrumbs__link",
|
37
25
|
aria: {
|
38
|
-
current: aria_current,
|
26
|
+
current: breadcrumb.aria_current,
|
39
27
|
}
|
40
28
|
) %>
|
41
29
|
<% else %>
|
42
|
-
<%=
|
30
|
+
<%= breadcrumb[:title] %>
|
43
31
|
<% end %>
|
44
32
|
</li>
|
45
33
|
<% end %>
|
46
34
|
</ol>
|
47
35
|
</div>
|
36
|
+
|
@@ -2,6 +2,7 @@ name: "Breadcrumbs"
|
|
2
2
|
description: "Navigational breadcrumbs, showing page hierarchy"
|
3
3
|
body: |
|
4
4
|
Accepts an array of breadcrumb objects. Each crumb must have a title and a URL.
|
5
|
+
Links have tracking data but links to the homepage (any link with a url of "/") will be tracked separately as `homeLinkClicked`
|
5
6
|
shared_accessibility_criteria:
|
6
7
|
- link
|
7
8
|
accessibility_criteria:
|
@@ -20,15 +20,68 @@ module GovukPublishingComponents
|
|
20
20
|
|
21
21
|
def item_list_element
|
22
22
|
breadcrumbs.each_with_index.map do |crumb, index|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
23
|
+
Breadcrumb.new(crumb, index).item_list_element(@request_path)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class Breadcrumb
|
29
|
+
extend Forwardable
|
30
|
+
def_delegators :@crumb, :[]
|
31
|
+
|
32
|
+
def initialize(crumb, index)
|
33
|
+
@crumb = crumb
|
34
|
+
@index = index + 1
|
35
|
+
end
|
36
|
+
|
37
|
+
def item_list_element(request_path)
|
38
|
+
{
|
39
|
+
"@type" => "ListItem",
|
40
|
+
"position" => index,
|
41
|
+
"item" => list_item_item(request_path)
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
def is_link?
|
46
|
+
crumb[:url].present? || crumb[:is_current_page]
|
47
|
+
end
|
48
|
+
|
49
|
+
def path
|
50
|
+
crumb[:is_current_page] ? '#content' : crumb[:url]
|
51
|
+
end
|
52
|
+
|
53
|
+
def aria_current
|
54
|
+
crumb[:is_current_page] ? 'page' : 'false'
|
55
|
+
end
|
56
|
+
|
57
|
+
def tracking_data(breadcrumbs_length)
|
58
|
+
data = {
|
59
|
+
track_category: 'breadcrumbClicked',
|
60
|
+
track_action: index,
|
61
|
+
track_label: path,
|
62
|
+
track_options: {
|
63
|
+
dimension28: breadcrumbs_length.to_s,
|
64
|
+
dimension29: crumb[:title]
|
27
65
|
}
|
66
|
+
}
|
67
|
+
|
68
|
+
is_homepage = crumb[:url] == "/"
|
69
|
+
|
70
|
+
if is_homepage
|
71
|
+
data[:track_category] = 'homeLinkClicked'
|
72
|
+
data[:track_action] = 'homeBreadcrumb'
|
73
|
+
data[:track_label] = ''
|
74
|
+
data[:track_options] = '{}'
|
28
75
|
end
|
76
|
+
|
77
|
+
data
|
29
78
|
end
|
30
79
|
|
31
|
-
|
80
|
+
private
|
81
|
+
|
82
|
+
attr_reader :crumb, :index
|
83
|
+
|
84
|
+
def list_item_item(request_path)
|
32
85
|
path = crumb[:is_current_page] ? request_path : crumb[:url]
|
33
86
|
item = { "name" => crumb[:title] }
|
34
87
|
item["@id"] = Plek.new.website_root + path if path
|