govuk_publishing_components 29.5.0 → 29.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/govuk_publishing_components/analytics/explicit-cross-domain-links.js +72 -73
  3. data/app/assets/javascripts/govuk_publishing_components/analytics/page-content.js +11 -0
  4. data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/gtm-click-tracking.js +49 -0
  5. data/app/assets/javascripts/govuk_publishing_components/analytics-ga4.js +1 -0
  6. data/app/assets/javascripts/govuk_publishing_components/components/accordion.js +0 -1
  7. data/app/assets/javascripts/govuk_publishing_components/lib/govspeak/magna-charta.js +20 -6
  8. data/app/assets/javascripts/govuk_publishing_components/modules.js +0 -1
  9. data/app/assets/javascripts/govuk_publishing_components/vendor/lux/lux-measurer.js +28 -0
  10. data/app/assets/stylesheets/govuk_publishing_components/components/_cards.scss +11 -4
  11. data/app/assets/stylesheets/govuk_publishing_components/components/_layout-super-navigation-header.scss +1 -1
  12. data/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_attachment.scss +1 -1
  13. data/app/controllers/govuk_publishing_components/audit_controller.rb +1 -4
  14. data/app/models/govuk_publishing_components/audit_components.rb +61 -24
  15. data/app/views/govuk_publishing_components/audit/_applications.html.erb +8 -3
  16. data/app/views/govuk_publishing_components/audit/_component_contents.html.erb +82 -0
  17. data/app/views/govuk_publishing_components/audit/_components.html.erb +2 -47
  18. data/app/views/govuk_publishing_components/component_guide/index.html.erb +2 -2
  19. data/app/views/govuk_publishing_components/component_guide/show.html.erb +1 -1
  20. data/app/views/govuk_publishing_components/components/_attachment.html.erb +1 -1
  21. data/app/views/govuk_publishing_components/components/_attachment_link.html.erb +1 -1
  22. data/app/views/govuk_publishing_components/components/_cards.html.erb +13 -11
  23. data/app/views/govuk_publishing_components/components/docs/contents_list.yml +1 -1
  24. data/app/views/govuk_publishing_components/components/docs/document_list.yml +4 -4
  25. data/app/views/govuk_publishing_components/components/docs/heading.yml +1 -1
  26. data/app/views/govuk_publishing_components/components/docs/image_card.yml +1 -1
  27. data/app/views/govuk_publishing_components/components/docs/meta_tags.yml +4 -4
  28. data/app/views/govuk_publishing_components/components/docs/metadata.yml +1 -1
  29. data/app/views/govuk_publishing_components/components/docs/share_links.yml +1 -1
  30. data/app/views/govuk_publishing_components/components/docs/subscription_links.yml +1 -1
  31. data/app/views/govuk_publishing_components/components/docs/translation_nav.yml +1 -2
  32. data/config/locales/ar.yml +1 -0
  33. data/config/locales/az.yml +1 -0
  34. data/config/locales/be.yml +1 -0
  35. data/config/locales/bg.yml +1 -0
  36. data/config/locales/bn.yml +1 -0
  37. data/config/locales/cs.yml +1 -0
  38. data/config/locales/cy.yml +1 -0
  39. data/config/locales/da.yml +1 -0
  40. data/config/locales/de.yml +1 -0
  41. data/config/locales/dr.yml +1 -0
  42. data/config/locales/el.yml +1 -0
  43. data/config/locales/en.yml +54 -3
  44. data/config/locales/es-419.yml +1 -0
  45. data/config/locales/es.yml +1 -0
  46. data/config/locales/et.yml +1 -0
  47. data/config/locales/fa.yml +1 -0
  48. data/config/locales/fi.yml +1 -0
  49. data/config/locales/fr.yml +1 -0
  50. data/config/locales/gd.yml +1 -0
  51. data/config/locales/gu.yml +1 -0
  52. data/config/locales/he.yml +1 -0
  53. data/config/locales/hi.yml +1 -0
  54. data/config/locales/hr.yml +1 -0
  55. data/config/locales/hu.yml +1 -0
  56. data/config/locales/hy.yml +1 -0
  57. data/config/locales/id.yml +1 -0
  58. data/config/locales/is.yml +1 -0
  59. data/config/locales/it.yml +1 -0
  60. data/config/locales/ja.yml +1 -0
  61. data/config/locales/ka.yml +1 -0
  62. data/config/locales/kk.yml +1 -0
  63. data/config/locales/ko.yml +1 -0
  64. data/config/locales/lt.yml +1 -0
  65. data/config/locales/lv.yml +1 -0
  66. data/config/locales/ms.yml +1 -0
  67. data/config/locales/mt.yml +1 -0
  68. data/config/locales/nl.yml +1 -0
  69. data/config/locales/no.yml +1 -0
  70. data/config/locales/pa-pk.yml +1 -0
  71. data/config/locales/pa.yml +1 -0
  72. data/config/locales/pl.yml +1 -0
  73. data/config/locales/ps.yml +1 -0
  74. data/config/locales/pt.yml +1 -0
  75. data/config/locales/ro.yml +1 -0
  76. data/config/locales/ru.yml +1 -0
  77. data/config/locales/si.yml +1 -0
  78. data/config/locales/sk.yml +1 -0
  79. data/config/locales/sl.yml +1 -0
  80. data/config/locales/so.yml +1 -0
  81. data/config/locales/sq.yml +1 -0
  82. data/config/locales/sr.yml +1 -0
  83. data/config/locales/sv.yml +1 -0
  84. data/config/locales/sw.yml +1 -0
  85. data/config/locales/ta.yml +1 -0
  86. data/config/locales/th.yml +1 -0
  87. data/config/locales/tk.yml +1 -0
  88. data/config/locales/tr.yml +1 -0
  89. data/config/locales/uk.yml +1 -0
  90. data/config/locales/ur.yml +1 -0
  91. data/config/locales/uz.yml +1 -0
  92. data/config/locales/vi.yml +1 -0
  93. data/config/locales/zh-hk.yml +1 -0
  94. data/config/locales/zh-tw.yml +1 -0
  95. data/config/locales/zh.yml +1 -0
  96. data/lib/generators/govuk_publishing_components/templates/_component.html.erb +1 -1
  97. data/lib/govuk_publishing_components/app_helpers/brand_helper.rb +1 -1
  98. data/lib/govuk_publishing_components/presenters/{attachment.rb → attachment_helper.rb} +1 -2
  99. data/lib/govuk_publishing_components/presenters/public_layout_helper.rb +18 -289
  100. data/lib/govuk_publishing_components/version.rb +1 -1
  101. data/lib/govuk_publishing_components.rb +1 -1
  102. metadata +7 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3aa5e0fc0a38b75525aa2915acb8986988d4311a46a84aa9baaa5e3ca546ea21
4
- data.tar.gz: 94a1d71770c10fc48dc306ebe1e9857680649bab32c5017ebf921a8b550617bd
3
+ metadata.gz: 4cef8771d15136a9e4ebbe4fc0cbedb616731c433ea12db09af6fa12c1613594
4
+ data.tar.gz: 721a1fb8532f1952e49aa9ff61a6aa075d3719f8a774c387319858da6c153edf
5
5
  SHA512:
6
- metadata.gz: 9ca1d951afe78053a1e8213c5a55cc90bf09c826a33d76703e5549bd9734a202c591d468b59b4205b3c3f7a128270c20db128bf6604f3ec91905b70f28ae9bcf
7
- data.tar.gz: f37fb440c117ff86a76376a4aa2733be0defbda0157b6c0e1b38078f2cc100f93eb33f880d29e69d98a637c2d98aef51dbd2f2a4bf3a07375ac25d4d38809c78
6
+ metadata.gz: f1544190ffc2c00a4f1576c84c74c89e1bc647d4916bccd72deb7f571a9b3f010ebba18abec66a1d67868b86de280dd83cbe4c5bc34677b5a1150bf1a54fdf16
7
+ data.tar.gz: 868c8e7d02ab075e08fa196c526c39f02e6583dada12cfbb70f0384326a22728471cffe310d16692712d985960c4f78ec1e0f3ad5e8daeae84a4596398cf21a9
@@ -1,89 +1,88 @@
1
- ;(function (global) {
2
- 'use strict'
3
-
4
- var GOVUK = global.GOVUK || {}
5
- GOVUK.Modules = GOVUK.Modules || {}
6
-
7
- GOVUK.Modules.ExplicitCrossDomainLinks = function () {
8
- this.start = function ($module) {
9
- this.element = $module[0]
10
- this.attribute = 'href'
11
- this.attributeValue = this.element.getAttribute(this.attribute)
12
- this.eventType = 'click'
13
- if (!this.attributeValue) {
14
- this.attribute = 'action'
15
- this.attributeValue = this.element.getAttribute(this.attribute)
16
- this.eventType = 'submit'
17
- }
18
-
19
- this.handleEvent = this.handleEvent.bind(this)
20
- this.handleCookiesAccepted = this.handleCookiesAccepted.bind(this)
21
- // Listens for the 'submit' event if the element is a form, and the 'click' event if it is a link
22
- this.element.addEventListener(this.eventType, this.handleEvent)
23
- }
1
+ window.GOVUK = window.GOVUK || {}
2
+ window.GOVUK.Modules = window.GOVUK.Modules || {};
3
+
4
+ (function (Modules) {
5
+ function ExplicitCrossDomainLinks ($module) {
6
+ this.$module = $module
7
+ }
24
8
 
25
- this.handleEvent = function (e) {
26
- // prevent default: we want the link href and/or form action to be decorated before we navigate away
27
- e.preventDefault()
28
- var cookieBannerEngaged = GOVUK.cookie('cookies_preferences_set')
29
- var cookieConsent = GOVUK.getConsentCookie()
30
-
31
- if (cookieBannerEngaged !== 'true') {
32
- // If not engaged, append only ?cookie_consent=not-engaged
33
- this.decorate(this.element, 'cookie_consent=not-engaged', this.attribute)
34
- } else if (cookieConsent && cookieConsent.usage === true) {
35
- this.handleCookiesAccepted()
36
- } else {
37
- this.decorate(this.element, 'cookie_consent=reject', this.attribute)
38
- }
39
-
40
- // remove the event listener to avoid an infinite loop
41
- this.element.removeEventListener(this.eventType, this.handleEvent)
42
-
43
- // if the element is a form, submit it. If it is a link, click it
44
- if (this.eventType === 'submit') {
45
- this.element.submit()
46
- } else {
47
- this.element.click()
48
- }
9
+ ExplicitCrossDomainLinks.prototype.init = function () {
10
+ this.attribute = 'href'
11
+ this.attributeValue = this.$module.getAttribute(this.attribute)
12
+ this.eventType = 'click'
13
+ if (!this.attributeValue) {
14
+ this.attribute = 'action'
15
+ this.attributeValue = this.$module.getAttribute(this.attribute)
16
+ this.eventType = 'submit'
49
17
  }
50
18
 
51
- this.handleCookiesAccepted = function () {
52
- // If the cookie banner was engaged and usage cookie accepted, append ?_ga=clientid if available and cookie_consent=accept
53
- var element = this.element
54
- var attribute = this.attribute
55
- this.decorate(element, 'cookie_consent=accept', attribute)
19
+ this.handleEvent = this.handleEvent.bind(this)
20
+ this.handleCookiesAccepted = this.handleCookiesAccepted.bind(this)
21
+ // Listens for the 'submit' event if the element is a form, and the 'click' event if it is a link
22
+ this.$module.addEventListener(this.eventType, this.handleEvent)
23
+ }
56
24
 
57
- if (!global.ga) {
58
- return
59
- }
25
+ ExplicitCrossDomainLinks.prototype.decorate = function (element, param, attribute) {
26
+ var attributeValue = element.getAttribute(attribute)
60
27
 
61
- global.ga(function () {
62
- var trackers = global.ga.getAll()
28
+ if (!attributeValue) { return }
63
29
 
64
- if (!trackers.length) { return }
30
+ if (attributeValue.indexOf('?') !== -1) {
31
+ attributeValue += '&' + param
32
+ } else {
33
+ attributeValue += '?' + param
34
+ }
65
35
 
66
- var linker = new global.gaplugins.Linker(trackers[0])
67
- var attrValue = element.getAttribute(attribute)
36
+ element.setAttribute(attribute, attributeValue)
37
+ }
68
38
 
69
- element.setAttribute(attribute, linker.decorate(attrValue))
70
- })
39
+ ExplicitCrossDomainLinks.prototype.handleEvent = function (e) {
40
+ // prevent default: we want the link href and/or form action to be decorated before we navigate away
41
+ e.preventDefault()
42
+ var cookieBannerEngaged = window.GOVUK.cookie('cookies_preferences_set')
43
+ var cookieConsent = window.GOVUK.getConsentCookie()
44
+
45
+ if (cookieBannerEngaged !== 'true') {
46
+ // If not engaged, append only ?cookie_consent=not-engaged
47
+ this.decorate(this.$module, 'cookie_consent=not-engaged', this.attribute)
48
+ } else if (cookieConsent && cookieConsent.usage === true) {
49
+ this.handleCookiesAccepted()
50
+ } else {
51
+ this.decorate(this.$module, 'cookie_consent=reject', this.attribute)
71
52
  }
72
53
 
73
- this.decorate = function (element, param, attribute) {
74
- var attributeValue = element.getAttribute(attribute)
54
+ // remove the event listener to avoid an infinite loop
55
+ this.$module.removeEventListener(this.eventType, this.handleEvent)
75
56
 
76
- if (!attributeValue) { return }
57
+ // if the element is a form, submit it. If it is a link, click it
58
+ if (this.eventType === 'submit') {
59
+ this.$module.submit()
60
+ } else {
61
+ this.$module.click()
62
+ }
63
+ }
77
64
 
78
- if (attributeValue.indexOf('?') !== -1) {
79
- attributeValue += '&' + param
80
- } else {
81
- attributeValue += '?' + param
82
- }
65
+ ExplicitCrossDomainLinks.prototype.handleCookiesAccepted = function () {
66
+ // If the cookie banner was engaged and usage cookie accepted, append ?_ga=clientid if available and cookie_consent=accept
67
+ var element = this.$module
68
+ var attribute = this.attribute
69
+ this.decorate(element, 'cookie_consent=accept', attribute)
83
70
 
84
- element.setAttribute(attribute, attributeValue)
71
+ if (!window.ga) {
72
+ return
85
73
  }
74
+
75
+ window.ga(function () {
76
+ var trackers = window.ga.getAll()
77
+
78
+ if (!trackers.length) { return }
79
+
80
+ var linker = new window.gaplugins.Linker(trackers[0])
81
+ var attrValue = element.getAttribute(attribute)
82
+
83
+ element.setAttribute(attribute, linker.decorate(attrValue))
84
+ })
86
85
  }
87
86
 
88
- global.GOVUK = GOVUK
89
- })(window)
87
+ Modules.ExplicitCrossDomainLinks = ExplicitCrossDomainLinks
88
+ })(window.GOVUK.Modules)
@@ -13,6 +13,10 @@
13
13
  return document.querySelectorAll('[data-track-count="accordionSection"]').length
14
14
  case isDocumentCollectionPage():
15
15
  return document.querySelectorAll('.document-collection .group-title').length
16
+ case isNewBrowsePageLevelTwo():
17
+ // if there are no accordion sections on the browse level 2 page
18
+ // then it is a default page with only one section
19
+ return document.querySelectorAll('[data-track-count="accordionSection"]').length || 1
16
20
  case isNewBrowsePage():
17
21
  return document.querySelectorAll('[data-track-count="cardList"]').length
18
22
  case isMainstreamBrowsePage():
@@ -46,6 +50,8 @@
46
50
  return document.querySelectorAll('a[data-track-category="navAccordionLinkClicked"]').length
47
51
  case isDocumentCollectionPage():
48
52
  return document.querySelectorAll('.document-collection .group-document-list li a').length
53
+ case isNewBrowsePageLevelTwo():
54
+ return document.querySelectorAll('[data-track-count="contentLink"]').length
49
55
  case isNewBrowsePage():
50
56
  return document.querySelectorAll('[data-track-count="cardLink"]').length
51
57
  case isMainstreamBrowsePage():
@@ -98,6 +104,11 @@
98
104
  getMetaAttribute(metaNavigationTypeSelector) === 'leaf'
99
105
  }
100
106
 
107
+ function isNewBrowsePageLevelTwo () {
108
+ return getMetaAttribute(metaApplicationSelector) === 'collections' &&
109
+ getMetaAttribute(metaNavigationTypeSelector) === 'browse level 2'
110
+ }
111
+
101
112
  function isNewBrowsePage () {
102
113
  return getMetaAttribute(metaApplicationSelector) === 'collections' &&
103
114
  getMetaAttribute(metaSectionSelector) === 'new_browse_page' &&
@@ -0,0 +1,49 @@
1
+ window.GOVUK = window.GOVUK || {}
2
+ window.GOVUK.Modules = window.GOVUK.Modules || {};
3
+
4
+ (function (Modules) {
5
+ 'use strict'
6
+
7
+ function GtmClickTracking (module) {
8
+ this.module = module
9
+ this.trackingTrigger = 'data-gtm-event-name' // elements with this attribute get tracked
10
+ }
11
+
12
+ GtmClickTracking.prototype.init = function () {
13
+ var trackClicksOn = [this.module]
14
+ if (!this.module.getAttribute(this.trackingTrigger)) {
15
+ trackClicksOn = this.module.querySelectorAll('[' + this.trackingTrigger + ']')
16
+ }
17
+
18
+ for (var i = 0; i < trackClicksOn.length; i++) {
19
+ trackClicksOn[i].addEventListener('click', this.trackClick.bind(this))
20
+ }
21
+ }
22
+
23
+ GtmClickTracking.prototype.trackClick = function (event) {
24
+ if (window.dataLayer) {
25
+ var target = event.currentTarget
26
+ var data = {
27
+ event: 'analytics',
28
+ event_name: target.getAttribute('data-gtm-event-name'),
29
+ // get entire URL apart from domain
30
+ link_url: window.location.href.substring(window.location.origin.length),
31
+ ui: JSON.parse(target.getAttribute('data-gtm-attributes'))
32
+ }
33
+ var ariaExpanded = this.checkExpandedState(target)
34
+ if (ariaExpanded) {
35
+ data.ui.state = ariaExpanded === 'false' ? 'opened' : 'closed'
36
+ }
37
+ window.dataLayer.push(data)
38
+ }
39
+ }
40
+
41
+ GtmClickTracking.prototype.checkExpandedState = function (clicked) {
42
+ var expanded = clicked.querySelector('[aria-expanded]')
43
+ if (expanded) {
44
+ return expanded.getAttribute('aria-expanded')
45
+ }
46
+ }
47
+
48
+ Modules.GtmClickTracking = GtmClickTracking
49
+ })(window.GOVUK.Modules)
@@ -0,0 +1 @@
1
+ //= require ./analytics-ga4/gtm-click-tracking
@@ -131,7 +131,6 @@ window.GOVUK.Modules.GovukAccordion = window.GOVUKFrontend.Accordion;
131
131
 
132
132
  if (window.GOVUK.analytics && window.GOVUK.analytics.trackEvent) {
133
133
  window.GOVUK.analytics.trackEvent('pageElementInteraction', action, options)
134
- console.log('pageElementInteraction', action, options)
135
134
  }
136
135
  }
137
136
 
@@ -51,6 +51,16 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
51
51
  // giving the table a class of mc-stacked
52
52
  this.options.stacked = this.$table.classList.contains('mc-stacked')
53
53
 
54
+ // stacked charts require tables to use the th element in the table header
55
+ // if the th element is not included, then the ENABLED flag is set to false
56
+ // this will stop the chart and toggleLink from being rendered
57
+ if (this.options.stacked) {
58
+ var allTheTHsInTableHead = this.$table.querySelectorAll('thead th')
59
+ if (allTheTHsInTableHead.length === 0) {
60
+ this.ENABLED = false
61
+ }
62
+ }
63
+
54
64
  // set the negative option based on
55
65
  // giving the table a class of mc-negative
56
66
  this.options.negative = this.$table.classList.contains('mc-negative')
@@ -106,12 +116,16 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
106
116
 
107
117
  MagnaCharta.prototype.apply = function () {
108
118
  if (this.ENABLED) {
109
- this.constructChart()
110
- this.addClassesToHeader()
111
- this.applyWidths()
112
- this.insert()
113
- this.$table.classList.add('mc-hidden')
114
- this.applyOutdent()
119
+ try {
120
+ this.constructChart()
121
+ this.addClassesToHeader()
122
+ this.applyWidths()
123
+ this.insert()
124
+ this.$table.classList.add('mc-hidden')
125
+ this.applyOutdent()
126
+ } catch (error) {
127
+ console.error('MagnaCharta error:', error)
128
+ }
115
129
  }
116
130
  }
117
131
 
@@ -35,7 +35,6 @@
35
35
  for (var j = 0, k = moduleNames.length; j < k; j++) {
36
36
  var moduleName = camelCaseAndCapitalise(moduleNames[j])
37
37
  var started = element.getAttribute('data-' + moduleNames[j] + '-module-started')
38
-
39
38
  if (typeof GOVUK.Modules[moduleName] === 'function' && !started) {
40
39
  // Vanilla JavaScript GOV.UK Modules and GOV.UK Frontend Modules
41
40
  if (GOVUK.Modules[moduleName].prototype.init) {
@@ -157,3 +157,31 @@ if (
157
157
  LongTaskObserver.observe({ type: ["longtask"] });
158
158
  } catch (e) {}
159
159
  }
160
+
161
+ // As per RFC 147[1], this adds in monitoring of the type of HTTP protocol that
162
+ // is used when a browser loads a page.
163
+ //
164
+ // The User Timing API (aka window.performance) is used to record the data - to
165
+ // avoid the use of this from breaking the JavaScript for the small number of
166
+ // browsers that don't support it, it's been wrapped in a try/catch block plus a
167
+ // couple of checks to prevent "is not defined" errors.
168
+ //
169
+ // Because the `nextHopProtocol` isn't immediately available - it seems to need
170
+ // a request to be made before it's populated - we need to wait for the
171
+ // `DOMContentReady` event before we can see what the HTTP version is.
172
+ //
173
+ // [1]: https://github.com/alphagov/govuk-rfcs/pull/148
174
+ try {
175
+ if (typeof performance !== 'undefined') {
176
+ document.addEventListener('DOMContentLoaded', function () {
177
+ var getEntriesByType = performance.getEntriesByType('navigation')
178
+
179
+ if (getEntriesByType.length > 0) {
180
+ var httpProtocol = performance.getEntriesByType('navigation')[0].nextHopProtocol
181
+ LUX.addData("http-protocol", httpProtocol)
182
+ }
183
+ })
184
+ }
185
+ } catch (e) {
186
+ console.error('Error in LUX reporting the HTTP protocol (' + window.location + '):', e)
187
+ }
@@ -50,12 +50,19 @@
50
50
  // We use grid to split the container into column widths, so manage the horizontal spacing with
51
51
  // internal margins.
52
52
  margin: 0 govuk-spacing(3);
53
- padding: govuk-spacing(3) 0 govuk-spacing(6) 0;
53
+ padding: govuk-spacing(1) 0 govuk-spacing(4) 0;
54
+ }
55
+
56
+ .gem-c-cards__list-item-wrapper {
57
+ // this wrapper ensures that the clickable area of the card only
58
+ // covers the area of the card containing text so in a grid of cards
59
+ // there is space above and below each link
60
+ padding: govuk-spacing(2) govuk-spacing(6) govuk-spacing(2) 0;
54
61
  position: relative;
55
62
  }
56
63
 
57
64
  .gem-c-cards__sub-heading {
58
- margin: 0 govuk-spacing(6) govuk-spacing(2) 0;
65
+ margin-bottom: govuk-spacing(2);
59
66
  }
60
67
 
61
68
  .gem-c-cards__link {
@@ -79,7 +86,7 @@
79
86
  height: $dimension;
80
87
  position: absolute;
81
88
  right: govuk-spacing(1);
82
- top: govuk-spacing(4);
89
+ top: govuk-spacing(3);
83
90
  @include prefixed-transform($rotate: 45deg);
84
91
  width: $dimension;
85
92
  }
@@ -98,5 +105,5 @@
98
105
  }
99
106
 
100
107
  .gem-c-cards__description {
101
- margin: 0;
108
+ margin: 0 govuk-spacing(-6) 0 0;
102
109
  }
@@ -816,7 +816,7 @@ $button-pipe-colour: darken(govuk-colour("mid-grey"), 20%);
816
816
 
817
817
  .gem-c-layout-super-navigation-header__navigation-second-items--topics {
818
818
  @include govuk-media-query($from: "desktop") {
819
- @include columns($items: 17, $columns: 2, $selector: "li", $flow: column);
819
+ @include columns($items: 16, $columns: 2, $selector: "li", $flow: column);
820
820
  }
821
821
  }
822
822
 
@@ -16,7 +16,7 @@
16
16
  // This block is duplicated from Whitehall as a transitional step, see the
17
17
  // commit message for 2d893c10ee3f2cab27162b9aba38b12379a71d07 before making
18
18
  // changes, original version:
19
- // https://github.com/alphagov/whitehall/blob/master/app/assets/stylesheets/frontend/helpers/_attachment.scss
19
+ // https://github.com/alphagov/whitehall/blob/main/app/assets/stylesheets/frontend/helpers/_attachment.scss
20
20
  $thumbnail-width: 99px;
21
21
 
22
22
  .attachment {
@@ -13,8 +13,6 @@ module GovukPublishingComponents
13
13
  frontend
14
14
  government-frontend
15
15
  govspeak-preview
16
- govuk-account-manager-prototype
17
- govuk-coronavirus-vulnerable-people-form
18
16
  info-frontend
19
17
  licence-finder
20
18
  manuals-frontend
@@ -32,10 +30,9 @@ module GovukPublishingComponents
32
30
  gem_path = Gem.loaded_specs["govuk_publishing_components"].full_gem_path
33
31
  gem_path = Dir.pwd if ENV["MAIN_COMPONENT_GUIDE"]
34
32
  host_dir = File.expand_path("..")
35
- path = File.expand_path("..", gem_path)
36
33
 
37
34
  @in_application = false
38
- @in_application = true unless path.to_s == host_dir.to_s
35
+ @in_application = true unless ENV["MAIN_COMPONENT_GUIDE"]
39
36
 
40
37
  components = AuditComponents.new(gem_path, false)
41
38
  applications = analyse_applications(host_dir, application_dirs)
@@ -12,29 +12,40 @@ module GovukPublishingComponents
12
12
  private
13
13
 
14
14
  def compile_data(path, simple)
15
+ # simple is used to reduce effort (and therefore page load time) required
16
+ # when loading auditing summary on the main component guide page
15
17
  @simple = simple
16
- templates_path = "app/views/govuk_publishing_components/components"
17
- stylesheets_path = "app/assets/stylesheets/govuk_publishing_components/components"
18
- print_stylesheets_path = "app/assets/stylesheets/govuk_publishing_components/components/print"
19
- javascripts_path = "app/assets/javascripts/govuk_publishing_components/components"
20
- tests_path = "spec/components"
21
- js_tests_path = "spec/javascripts/components"
22
-
23
- templates = Dir["#{path}/#{templates_path}/*.erb"]
24
- stylesheets = Dir["#{path}/#{stylesheets_path}/*.scss"]
25
- print_stylesheets = Dir["#{path}/#{print_stylesheets_path}/*.scss"]
26
- javascripts = Dir["#{path}/#{javascripts_path}/*.js"]
27
- tests = Dir["#{path}/#{tests_path}/*.rb"]
28
- js_tests = Dir["#{path}/#{js_tests_path}/*.js"]
29
-
30
- @templates_full_path = "#{path}/#{templates_path}/"
31
-
32
- @components = find_files(templates, [path, templates_path].join("/"))
33
- @component_stylesheets = find_files(stylesheets, [path, stylesheets_path].join("/"))
34
- @component_print_stylesheets = find_files(print_stylesheets, [path, print_stylesheets_path].join("/"))
35
- @component_javascripts = find_files(javascripts, [path, javascripts_path].join("/"))
36
- @component_tests = find_files(tests, [path, tests_path].join("/"))
37
- @component_js_tests = find_files(js_tests, [path, js_tests_path].join("/"))
18
+
19
+ # paths to key file locations
20
+ @templates_path = "app/views/govuk_publishing_components/components"
21
+ @stylesheets_path = "app/assets/stylesheets/govuk_publishing_components/components"
22
+ @print_stylesheets_path = "app/assets/stylesheets/govuk_publishing_components/components/print"
23
+ @javascripts_path = "app/assets/javascripts/govuk_publishing_components/components"
24
+ @tests_path = "spec/components"
25
+ @js_tests_path = "spec/javascripts/components"
26
+ @helpers_path = "lib/govuk_publishing_components/presenters"
27
+
28
+ # get all files in key file locations
29
+ templates = Dir["#{path}/#{@templates_path}/*.erb"]
30
+ stylesheets = Dir["#{path}/#{@stylesheets_path}/*.scss"]
31
+ print_stylesheets = Dir["#{path}/#{@print_stylesheets_path}/*.scss"]
32
+ javascripts = Dir["#{path}/#{@javascripts_path}/*.js"]
33
+ tests = Dir["#{path}/#{@tests_path}/*.rb"]
34
+ js_tests = Dir["#{path}/#{@js_tests_path}/*.js"]
35
+ helpers = Dir["#{path}/#{@helpers_path}/*_helper.rb"]
36
+
37
+ @templates_full_path = "#{path}/#{@templates_path}/"
38
+
39
+ # find the cleaned names of components in key file locations
40
+ # i.e. will show that 'component name' has a stylesheet
41
+ # standardised like this to be used later for easier comparison
42
+ @components = clean_files(templates, [path, @templates_path].join("/"))
43
+ @component_stylesheets = clean_files(stylesheets, [path, @stylesheets_path].join("/"))
44
+ @component_print_stylesheets = clean_files(print_stylesheets, [path, @print_stylesheets_path].join("/"))
45
+ @component_javascripts = clean_files(javascripts, [path, @javascripts_path].join("/"))
46
+ @component_tests = clean_files(tests, [path, @tests_path].join("/"))
47
+ @component_js_tests = clean_files(js_tests, [path, @js_tests_path].join("/"))
48
+ @component_helpers = clean_files(helpers, [path, @helpers_path].join("/"))
38
49
 
39
50
  {
40
51
  gem_found: true,
@@ -44,12 +55,13 @@ module GovukPublishingComponents
44
55
  component_javascripts: @component_javascripts,
45
56
  component_tests: @component_tests,
46
57
  component_js_tests: @component_js_tests,
58
+ component_helpers: @component_helpers,
47
59
  components_containing_components: find_all_partials_in(templates),
48
60
  component_listing: list_all_component_details,
49
61
  }
50
62
  end
51
63
 
52
- def find_files(files, replace)
64
+ def clean_files(files, replace)
53
65
  files.map { |file| clean_file_name(file.gsub(replace, "")) }.sort
54
66
  end
55
67
 
@@ -61,6 +73,7 @@ module GovukPublishingComponents
61
73
  .gsub(".js", "")
62
74
  .gsub("spec", "")
63
75
  .gsub(".rb", "")
76
+ .gsub("helper", "")
64
77
  .strip
65
78
  end
66
79
 
@@ -72,11 +85,14 @@ module GovukPublishingComponents
72
85
  .tr('\"\'', "")
73
86
  end
74
87
 
88
+ # create link to component guide page for a given component e.g. 'component name'
75
89
  def get_component_link(component)
76
90
  "/component-guide/#{component.gsub(' ', '_')}"
77
91
  end
78
92
 
79
93
  def find_all_partials_in(templates)
94
+ return [] if @simple
95
+
80
96
  components = []
81
97
 
82
98
  templates.each do |template|
@@ -142,6 +158,7 @@ module GovukPublishingComponents
142
158
  javascript: check_component_has("javascript", component),
143
159
  tests: check_component_has("test", component),
144
160
  js_tests: check_component_has("js_test", component),
161
+ helper: check_component_has("helper", component),
145
162
  }
146
163
  end
147
164
 
@@ -154,8 +171,28 @@ module GovukPublishingComponents
154
171
  look_in = @component_javascripts if a_thing == "javascript"
155
172
  look_in = @component_tests if a_thing == "test"
156
173
  look_in = @component_js_tests if a_thing == "js_test"
174
+ look_in = @component_helpers if a_thing == "helper"
175
+
176
+ if look_in.include?(component)
177
+ return get_asset_link(a_thing, component)
178
+ end
179
+
180
+ false
181
+ end
157
182
 
158
- true if look_in.include?(component)
183
+ def get_asset_link(a_thing, component)
184
+ url = "https://github.com/alphagov"
185
+ repo = "govuk_publishing_components"
186
+ blob = "blob/main"
187
+ link = nil
188
+ link = "#{url}/#{repo}/#{blob}/#{@stylesheets_path}/_#{component.gsub(' ', '-')}.scss" if a_thing == "stylesheet"
189
+ link = "#{url}/#{repo}/#{blob}/#{@print_stylesheets_path}/_#{component.gsub(' ', '-')}.scss" if a_thing == "print_stylesheet"
190
+ link = "#{url}/#{repo}/#{blob}/#{@javascripts_path}/#{component.gsub(' ', '-')}.js" if a_thing == "javascript"
191
+ link = "#{url}/#{repo}/#{blob}/#{@tests_path}/#{component.gsub(' ', '_')}_spec.rb" if a_thing == "test"
192
+ link = "#{url}/#{repo}/#{blob}/#{@js_tests_path}/#{component.gsub(' ', '-')}-spec.js" if a_thing == "js_test"
193
+ link = "#{url}/#{repo}/#{blob}/#{@helpers_path}/#{component.gsub(' ', '_')}_helper.rb" if a_thing == "helper"
194
+
195
+ link
159
196
  end
160
197
  end
161
198
  end
@@ -32,6 +32,7 @@
32
32
 
33
33
  <% accordion_content = capture do %>
34
34
  <% if application[:application_found] %>
35
+ <% github_link = 'https://github.com/alphagov/' + application[:name] + '/blob/main/' %>
35
36
  <% application[:warnings].each do |warning| %>
36
37
  <p class="govuk-body">
37
38
  <strong class="govuk-tag">Warn</strong>
@@ -74,7 +75,9 @@
74
75
  <p class="govuk-body">This shows instances of `gem-c-` classes found in the application. If a reference is found in a stylesheet or in code a warning is created, as this could be a style override or hard coded component markup.</p>
75
76
  <ul class="govuk-list govuk-list--bullet">
76
77
  <% application[:gem_style_references].each do |ref| %>
77
- <li><%= ref %></li>
78
+ <li>
79
+ <%= link_to ref, github_link + ref, class: 'govuk-link' %>
80
+ </li>
78
81
  <% end %>
79
82
  </ul>
80
83
  <% end %>
@@ -86,10 +89,12 @@
86
89
  margin_bottom: 4,
87
90
  heading_level: 3,
88
91
  } %>
89
- <p class="govuk-body">This shows JavaScript files that might contain jQuery, which we are trying to remove our dependency on.</p>
92
+ <p class="govuk-body">This shows JavaScript files that might contain jQuery, which we are trying to remove.</p>
90
93
  <ul class="govuk-list govuk-list--bullet">
91
94
  <% application[:jquery_references].each do |ref| %>
92
- <li><%= ref %></li>
95
+ <li>
96
+ <%= link_to ref, github_link + ref, class: 'govuk-link' %>
97
+ </li>
93
98
  <% end %>
94
99
  </ul>
95
100
  <% end %>