govuk_publishing_components 12.5.0 → 12.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 493818b77e57bcb81f779a3bc4c08b0adea4d72fc74ad9db73383b2e229b8789
4
- data.tar.gz: 2a09a48ba19c95071ecebab651bcd5bf1f6eb0ae9a8d8fbda521702be5f24c07
3
+ metadata.gz: 24ceb44b4f462698eac37aae0a7b7f3f97eb581a8a079ab8cc95fdb2fffdc545
4
+ data.tar.gz: 5e89d14681030ec55c196e689222439a792412d449df0c49a5a34ba07611a452
5
5
  SHA512:
6
- metadata.gz: bf9fbdf048910fa2a60e66d64817f7cbfa447d570dd5bbab0af75589730cf3136b4e81f934cb2e8fbda927b227b064c03eea963c0714061abb4a2aca6579f71f
7
- data.tar.gz: 92ee9ccbadfc705288d501d13efa46925f8050abdb9443fedc5d10d5ac0f9285f1a181a41280cd7ae6541c5ccaa26a252cefa02e31d6c0dff1a8973453201b0b
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
- structured_data = GovukPublishingComponents::Presenters::Breadcrumbs.new(breadcrumbs, request.path).structured_data
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
- is_link = crumb[:url].present? || crumb[:is_current_page]
19
- path = crumb[:is_current_page] ? '#content' : crumb[:url]
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
- crumb[:title],
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
- <%= crumb[:title] %>
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:
@@ -15,7 +15,7 @@ module GovukPublishingComponents
15
15
  {
16
16
  title: parent.title,
17
17
  url: parent.base_path,
18
- is_page_parent: index.zero?
18
+ is_page_parent: index.zero?,
19
19
  }
20
20
  end
21
21
 
@@ -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
- "@type" => "ListItem",
25
- "position" => index + 1,
26
- "item" => list_item_item(crumb)
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
- def list_item_item(crumb)
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
@@ -1,3 +1,3 @@
1
1
  module GovukPublishingComponents
2
- VERSION = '12.5.0'.freeze
2
+ VERSION = '12.6.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk_publishing_components
3
3
  version: !ruby/object:Gem::Version
4
- version: 12.5.0
4
+ version: 12.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GOV.UK Dev