govuk_publishing_components 28.6.0 → 28.7.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -45,7 +45,7 @@ module GovukPublishingComponents
45
45
  end
46
46
 
47
47
  def parse_documentation(file)
48
- { id: File.basename(file, ".yml") }.merge(YAML.load_file(file)).with_indifferent_access
48
+ { id: File.basename(file, ".yml") }.merge(YAML.unsafe_load_file(file)).with_indifferent_access
49
49
  end
50
50
 
51
51
  def app_documentation_directory
@@ -21,11 +21,11 @@
21
21
  %>
22
22
 
23
23
  <% if button.link? %>
24
- <%= link_to button_text, button.href, button.html_options %>
24
+ <%= link_to button_text, button.href, **button.html_options %>
25
25
  <% else %>
26
- <%= content_tag :button, button_text, button.html_options %>
26
+ <%= content_tag :button, button_text, **button.html_options %>
27
27
  <% end %>
28
28
 
29
29
  <% if button.info_text %>
30
- <%= tag.span button.info_text, button.info_text_options %>
30
+ <%= tag.span button.info_text, **button.info_text_options %>
31
31
  <% end %>
@@ -98,7 +98,7 @@
98
98
  } %>
99
99
  <% end %>
100
100
 
101
- <% input_tag = tag.input({
101
+ <% input_tag = tag.input(
102
102
  aria: {
103
103
  describedby: aria_described_by,
104
104
  controls: controls
@@ -116,8 +116,8 @@
116
116
  readonly: readonly,
117
117
  tabindex: tabindex,
118
118
  type: type,
119
- value: value,
120
- }) %>
119
+ value: value
120
+ ) %>
121
121
 
122
122
  <% if prefix && suffix %>
123
123
  <%= tag.div class: "govuk-input__wrapper" do %>
@@ -45,11 +45,11 @@
45
45
  section_options.merge!({ hidden: true }) if hide
46
46
  %>
47
47
  <% if suggestion_text || (suggestion_link_text && suggestion_link_url) %>
48
- <%= tag.section section_options do %>
48
+ <%= tag.section **section_options do %>
49
49
  <p class="govuk-body">
50
50
  <%= tag.span suggestion_text, class: "gem-c-intervention__textwrapper" if suggestion_text %>
51
51
  <% if suggestion_link_text && suggestion_link_url %>
52
- <%= tag.a suggestion_link_text, suggestion_tag_options %>
52
+ <%= tag.a suggestion_link_text, **suggestion_tag_options %>
53
53
  <% end %>
54
54
  </p>
55
55
 
@@ -39,7 +39,7 @@
39
39
  label_classes << "govuk-!-margin-bottom-#{label_margin_bottom}" if [*1..9].include?(label_margin_bottom) and local_assigns.include?(:inline_label)
40
40
 
41
41
  tag_label = capture do
42
- tag.label({ for: id, class: label_classes }) do
42
+ tag.label(for: id, class: label_classes) do
43
43
  label_text
44
44
  end
45
45
  end
@@ -47,9 +47,7 @@
47
47
 
48
48
  <div class="<%= classes.join(" ") %>" data-module="gem-toggle-input-class-on-focus">
49
49
  <% if wrap_label_in_a_heading %>
50
- <%= content_tag(shared_helper.get_heading_level, {
51
- class: "govuk-!-margin-0",
52
- }) do %>
50
+ <%= content_tag(shared_helper.get_heading_level, class: "govuk-!-margin-0") do %>
53
51
  <%= tag_label %>
54
52
  <% end %>
55
53
  <% else %>
@@ -1,67 +1,39 @@
1
1
  <%
2
- shared_helper = GovukPublishingComponents::Presenters::SharedHelper.new(local_assigns)
3
-
4
- options ||= []
2
+ # select_helper.css_classes generates "gem-c-select"
5
3
  id ||= false
6
4
  label ||= false
7
- full_width ||= false
8
5
  name ||= id
9
6
  is_page_heading ||= false
10
- heading_size = false unless shared_helper.valid_heading_size?(heading_size)
11
- error_message ||= nil
12
- error_id ||= nil
13
- hint ||= nil
14
- hint_id ||= nil
15
-
16
- describedby = %w[]
17
-
18
- if error_message || error_id
19
- error_id = "error-#{SecureRandom.hex(4)}" unless error_id
20
- describedby << error_id
21
- end
22
-
23
- if hint
24
- hint_id = "hint-#{SecureRandom.hex(4)}" unless hint_id
25
- describedby << hint_id
26
- end
27
7
 
28
- aria_describedby = { describedby: describedby } if describedby
29
-
30
- css_classes = %w(govuk-form-group gem-c-select)
31
- css_classes << "govuk-form-group--error" if error_message
32
-
33
- select_classes = %w(govuk-select)
34
- select_classes << "gem-c-select__select--full-width" if full_width
35
- select_classes << "govuk-select--error" if error_id
36
-
37
- label_classes = %w(govuk-label)
38
- label_classes << "govuk-label--#{heading_size}" if heading_size
8
+ shared_helper = GovukPublishingComponents::Presenters::SharedHelper.new(local_assigns)
9
+ heading_size = false unless shared_helper.valid_heading_size?(heading_size)
10
+ select_helper = GovukPublishingComponents::Presenters::SelectHelper.new(local_assigns)
39
11
 
40
- select_helper = GovukPublishingComponents::Presenters::SelectHelper.new(options)
12
+ aria_describedby = { describedby: select_helper.describedby }
41
13
  data_module = { module: "track-select-change" } unless select_helper.data_tracking?.eql?(false)
42
14
  %>
43
- <% if options.any? && id && label %>
44
- <%= content_tag :div, class: css_classes do %>
15
+ <% if select_helper.options.any? && id && label %>
16
+ <%= content_tag :div, class: select_helper.css_classes do %>
45
17
  <% if is_page_heading %>
46
- <%= tag.h1 label_tag(id, label, class: label_classes), class: "gem-c-title__text" %>
18
+ <%= tag.h1 label_tag(id, label, class: select_helper.label_classes), class: "gem-c-title__text" %>
47
19
  <% else %>
48
- <%= label_tag(id, label, class: label_classes) %>
20
+ <%= label_tag(id, label, class: select_helper.label_classes) %>
49
21
  <% end %>
50
22
 
51
- <% if hint %>
23
+ <% if select_helper.hint %>
52
24
  <%= render "govuk_publishing_components/components/hint", {
53
- id: hint_id,
25
+ id: select_helper.hint_id,
54
26
  text: hint
55
27
  } %>
56
28
  <% end %>
57
29
 
58
- <% if error_message %>
30
+ <% if select_helper.error_message %>
59
31
  <%= render "govuk_publishing_components/components/error_message", {
60
- id: error_id,
61
- text: error_message
32
+ id: select_helper.error_id,
33
+ text: select_helper.error_message
62
34
  } %>
63
35
  <% end %>
64
36
 
65
- <%= select_tag name, options_for_select(select_helper.option_markup, select_helper.selected_option), id: id, class: select_classes, data: data_module, aria: aria_describedby %>
37
+ <%= select_tag name, options_for_select(select_helper.option_markup, select_helper.selected_option), id: id, class: select_helper.select_classes, data: data_module, aria: aria_describedby %>
66
38
  <% end %>
67
39
  <% end %>
@@ -49,17 +49,16 @@
49
49
  <svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" class="gem-c-subscription-links__icon" focusable="false" fill="currentColor" aria-hidden="true"><path d="M1.996 11A2 2 0 0 0 0 12.993c0 1.101.895 1.99 1.996 1.99 1.106 0 2-.889 2-1.99a2 2 0 0 0-2-1.993zM.002 5.097V7.97c1.872 0 3.632.733 4.958 2.059A6.984 6.984 0 0 1 7.015 15h2.888c0-5.461-4.443-9.903-9.9-9.903zM.006 0v2.876c6.676 0 12.11 5.44 12.11 12.124H15C15 6.731 8.273 0 .006 0z"/>
50
50
  </svg><%= sl_helper.feed_link_text %>
51
51
  <% end %>
52
- <%= tag.button feed_link_text, {
52
+ <%= tag.button(feed_link_text,
53
53
  class: "govuk-link govuk-link--no-underline gem-c-subscription-links__item #{brand_helper.color_class} gem-c-subscription-links__item--button",
54
54
  data: sl_helper.feed_link_data_attributes,
55
55
  lang: feed_link_text_locale
56
- } if sl_helper.feed_link_box_value %>
57
- <%= link_to feed_link_text, sl_helper.feed_link,
58
- {
59
- class: "govuk-link govuk-link--no-underline gem-c-subscription-links__item #{brand_helper.color_class} gem-c-subscription-links__item--link",
60
- data: sl_helper.feed_link_data_attributes,
61
- lang: feed_link_text_locale
62
- } unless sl_helper.feed_link_box_value %>
56
+ ) if sl_helper.feed_link_box_value %>
57
+ <%= link_to(feed_link_text, sl_helper.feed_link,
58
+ class: "govuk-link govuk-link--no-underline gem-c-subscription-links__item #{brand_helper.color_class} gem-c-subscription-links__item--link",
59
+ data: sl_helper.feed_link_data_attributes,
60
+ lang: feed_link_text_locale
61
+ ) unless sl_helper.feed_link_box_value %>
63
62
  </li>
64
63
  <% end %>
65
64
  </ul>
@@ -47,7 +47,7 @@ examples:
47
47
  data:
48
48
  id: 'dropdown2-1'
49
49
  label: 'Choose your preferred thing'
50
- hint_text: 'You might need some more information here'
50
+ hint: 'You might need some more information here'
51
51
  hint_id: 'optional-hint-id'
52
52
  options:
53
53
  - text: 'Something'
@@ -10,6 +10,7 @@ Rails.application.config.assets.precompile += %w[
10
10
  govuk_publishing_components/vendor/lux/lux-reporter.js
11
11
  govuk_publishing_components/vendor/lux/lux-measurer.js
12
12
  govuk_publishing_components/all_components.js
13
+ govuk_publishing_components/dependencies.js
13
14
  govuk_publishing_components/ie.js
14
15
  govuk_publishing_components/modules.js
15
16
  govuk_publishing_components/vendor/modernizr.js
@@ -0,0 +1,85 @@
1
+ module GovukPublishingComponents
2
+ module Presenters
3
+ class SelectHelper
4
+ attr_reader :options, :option_markup, :selected_option, :error_message, :error_id, :hint, :hint_id, :describedby
5
+
6
+ def initialize(local_assigns)
7
+ @options = local_assigns[:options] || []
8
+ @error_message = local_assigns[:error_message]
9
+ @error_id = local_assigns[:error_id] || nil
10
+ @hint = local_assigns[:hint] || nil
11
+ @hint_id = local_assigns[:hint_id] || nil
12
+ @heading_size = local_assigns[:heading_size]
13
+ @full_width = local_assigns[:full_width] || false
14
+ @option_markup = get_options
15
+ @describedby = get_describedby
16
+ end
17
+
18
+ def data_tracking?
19
+ @options.any? { |item| item[:data_attributes] && item[:data_attributes][:track_category] && item[:data_attributes][:track_action] }
20
+ end
21
+
22
+ def css_classes
23
+ classes = %w[govuk-form-group gem-c-select]
24
+ classes << "govuk-form-group--error" if @error_message
25
+ classes
26
+ end
27
+
28
+ def select_classes
29
+ classes = %w[govuk-select]
30
+ classes << "gem-c-select__select--full-width" if @full_width
31
+ classes << "govuk-select--error" if @error_id
32
+ classes
33
+ end
34
+
35
+ def label_classes
36
+ classes = %w[govuk-label]
37
+ classes << "govuk-label--#{@heading_size}" if @heading_size
38
+ classes
39
+ end
40
+
41
+ private
42
+
43
+ def get_options
44
+ return if options.nil?
45
+
46
+ options.map do |option|
47
+ @selected_option = option[:value] if option[:selected]
48
+ [
49
+ option[:text],
50
+ option[:value],
51
+ options_data_attribute(option[:data_attributes]),
52
+ ]
53
+ end
54
+ end
55
+
56
+ def options_data_attribute(attributes)
57
+ return {} if attributes.nil?
58
+
59
+ attrs = {}
60
+ attributes.each do |key, value|
61
+ key_name = "data-#{key.to_s.split('_').join('-')}"
62
+ attrs[key_name] = value.is_a?(Hash) ? value.to_json : value
63
+ end
64
+
65
+ attrs
66
+ end
67
+
68
+ def get_describedby
69
+ describedby = %w[]
70
+
71
+ if @error_message || @error_id
72
+ @error_id ||= "error-#{SecureRandom.hex(4)}"
73
+ describedby << @error_id
74
+ end
75
+
76
+ if @hint
77
+ @hint_id ||= "hint-#{SecureRandom.hex(4)}"
78
+ describedby << @hint_id
79
+ end
80
+
81
+ describedby
82
+ end
83
+ end
84
+ end
85
+ end
@@ -1,3 +1,3 @@
1
1
  module GovukPublishingComponents
2
- VERSION = "28.6.0".freeze
2
+ VERSION = "28.7.1".freeze
3
3
  end
@@ -21,7 +21,7 @@ require "govuk_publishing_components/presenters/content_breadcrumbs_based_on_pri
21
21
  require "govuk_publishing_components/presenters/content_breadcrumbs_based_on_taxons"
22
22
  require "govuk_publishing_components/presenters/content_breadcrumbs_based_on_topic"
23
23
  require "govuk_publishing_components/presenters/checkboxes_helper"
24
- require "govuk_publishing_components/presenters/select"
24
+ require "govuk_publishing_components/presenters/select_helper"
25
25
  require "govuk_publishing_components/presenters/meta_tags"
26
26
  require "govuk_publishing_components/presenters/content_item"
27
27
  require "govuk_publishing_components/presenters/translation_nav_helper"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk_publishing_components
3
3
  version: !ruby/object:Gem::Version
4
- version: 28.6.0
4
+ version: 28.7.1
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: 2022-02-21 00:00:00.000000000 Z
11
+ date: 2022-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: govuk_app_config
@@ -66,18 +66,32 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: psych
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '4'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '4'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: rails
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
- - - "~>"
87
+ - - ">="
74
88
  - !ruby/object:Gem::Version
75
89
  version: '6'
76
90
  type: :runtime
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
- - - "~>"
94
+ - - ">="
81
95
  - !ruby/object:Gem::Version
82
96
  version: '6'
83
97
  - !ruby/object:Gem::Dependency
@@ -192,34 +206,6 @@ dependencies:
192
206
  - - ">="
193
207
  - !ruby/object:Gem::Version
194
208
  version: '0'
195
- - !ruby/object:Gem::Dependency
196
- name: jasmine
197
- requirement: !ruby/object:Gem::Requirement
198
- requirements:
199
- - - "~>"
200
- - !ruby/object:Gem::Version
201
- version: 3.10.0
202
- type: :development
203
- prerelease: false
204
- version_requirements: !ruby/object:Gem::Requirement
205
- requirements:
206
- - - "~>"
207
- - !ruby/object:Gem::Version
208
- version: 3.10.0
209
- - !ruby/object:Gem::Dependency
210
- name: jasmine_selenium_runner
211
- requirement: !ruby/object:Gem::Requirement
212
- requirements:
213
- - - "~>"
214
- - !ruby/object:Gem::Version
215
- version: 3.0.0
216
- type: :development
217
- prerelease: false
218
- version_requirements: !ruby/object:Gem::Requirement
219
- requirements:
220
- - - "~>"
221
- - !ruby/object:Gem::Version
222
- version: 3.0.0
223
209
  - !ruby/object:Gem::Dependency
224
210
  name: percy-capybara
225
211
  requirement: !ruby/object:Gem::Requirement
@@ -514,7 +500,6 @@ files:
514
500
  - app/assets/javascripts/govuk_publishing_components/lib/govspeak/barchart-enhancement.js
515
501
  - app/assets/javascripts/govuk_publishing_components/lib/govspeak/magna-charta.js
516
502
  - app/assets/javascripts/govuk_publishing_components/lib/govspeak/youtube-link-enhancement.js
517
- - app/assets/javascripts/govuk_publishing_components/lib/header-navigation.js
518
503
  - app/assets/javascripts/govuk_publishing_components/lib/initial-focus.js
519
504
  - app/assets/javascripts/govuk_publishing_components/lib/primary-links.js
520
505
  - app/assets/javascripts/govuk_publishing_components/lib/toggle-input-class-on-focus.js
@@ -962,14 +947,13 @@ files:
962
947
  - lib/govuk_publishing_components/presenters/public_layout_helper.rb
963
948
  - lib/govuk_publishing_components/presenters/related_navigation_helper.rb
964
949
  - lib/govuk_publishing_components/presenters/schema_org.rb
965
- - lib/govuk_publishing_components/presenters/select.rb
950
+ - lib/govuk_publishing_components/presenters/select_helper.rb
966
951
  - lib/govuk_publishing_components/presenters/shared_helper.rb
967
952
  - lib/govuk_publishing_components/presenters/single_page_notification_button_helper.rb
968
953
  - lib/govuk_publishing_components/presenters/step_by_step_nav_helper.rb
969
954
  - lib/govuk_publishing_components/presenters/subscription_links_helper.rb
970
955
  - lib/govuk_publishing_components/presenters/translation_nav_helper.rb
971
956
  - lib/govuk_publishing_components/version.rb
972
- - lib/tasks/govuk_publishing_components_tasks.rake
973
957
  - node_modules/axe-core/CHANGELOG.md
974
958
  - node_modules/axe-core/CONTRIBUTING.md
975
959
  - node_modules/axe-core/LICENSE
@@ -2017,14 +2001,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
2017
2001
  requirements:
2018
2002
  - - ">="
2019
2003
  - !ruby/object:Gem::Version
2020
- version: '2.6'
2004
+ version: '2.7'
2021
2005
  required_rubygems_version: !ruby/object:Gem::Requirement
2022
2006
  requirements:
2023
2007
  - - ">="
2024
2008
  - !ruby/object:Gem::Version
2025
2009
  version: '0'
2026
2010
  requirements: []
2027
- rubygems_version: 3.0.3.1
2011
+ rubygems_version: 3.3.8
2028
2012
  signing_key:
2029
2013
  specification_version: 4
2030
2014
  summary: A gem to document components in GOV.UK frontend applications
@@ -1,100 +0,0 @@
1
- /* eslint-disable no-var */
2
-
3
- // used by the header navigation from govuk_template
4
-
5
- (function () {
6
- 'use strict'
7
-
8
- if (document.querySelectorAll && document.addEventListener) {
9
- var els = document.querySelectorAll('.js-header-toggle')
10
- for (var i = 0; i < els.length; i++) {
11
- // Reassign current index to bypass rules in Chrome and Firefox around indexed property setting
12
- var thisEl = els[i]
13
-
14
- // If the element is an a tag, convert it to a button
15
- // This is to target instances where we want to change behaviour between a js and a no-js view eg: the search button on the mobile menu for some government pages. On no-js it's just a link to /search
16
- // This swaps a link for no-js to a button, making it interactable. Using a link for interactivity is poor accessibility as it's a misuse of the link tag and can be confusing to assistive tech users
17
-
18
- if (thisEl.tagName === 'A') {
19
- var attributes = thisEl.attributes
20
- var button = document.createElement('button')
21
-
22
- for (var k = 0; k < attributes.length; k++) {
23
- var thisAttr = attributes[k].name
24
-
25
- if (thisAttr === 'href') {
26
- if (button.getAttribute('data-search-toggle-for')) {
27
- continue
28
- } else {
29
- button.setAttribute('data-search-toggle-for', thisEl.getAttribute('href').substr(1))
30
- }
31
- } else if (thisAttr !== 'data-button-text') {
32
- button.setAttribute(thisAttr, thisEl.getAttribute(thisAttr))
33
- }
34
- }
35
-
36
- button.innerText = thisEl.getAttribute('data-button-text') || thisEl.innerText
37
-
38
- thisEl.parentNode.replaceChild(button, thisEl)
39
- thisEl = button
40
- }
41
-
42
- thisEl.addEventListener('click', function (e) {
43
- e.preventDefault()
44
- var target = document.getElementById(this.getAttribute('data-search-toggle-for'))
45
- var targetClass = target.getAttribute('class') || ''
46
- var sourceClass = this.getAttribute('class') || ''
47
- var isSearchToggle = sourceClass.match('search-toggle')
48
- var showText = this.getAttribute('data-show-text') || 'Show search'
49
- var hideText = this.getAttribute('data-hide-text') || 'Hide search'
50
- var buttonName = this.getAttribute('data-button-name') || 'menu'
51
-
52
- if (targetClass.indexOf('js-visible') !== -1) {
53
- target.setAttribute('class', targetClass.replace(/(^|\s)js-visible(\s|$)/, ''))
54
- if (window.GOVUK.analytics && window.GOVUK.analytics.trackEvent) {
55
- window.GOVUK.analytics.trackEvent('headerClicked', buttonName + 'Closed', { label: 'none' })
56
- }
57
- } else {
58
- target.setAttribute('class', targetClass + ' js-visible')
59
- if (window.GOVUK.analytics && window.GOVUK.analytics.trackEvent) {
60
- window.GOVUK.analytics.trackEvent('headerClicked', buttonName + 'Opened', { label: 'none' })
61
- }
62
- }
63
- if (sourceClass.indexOf('js-visible') !== -1) {
64
- this.setAttribute('class', sourceClass.replace(/(^|\s)js-visible(\s|$)/, ''))
65
- if (isSearchToggle) {
66
- this.innerText = showText
67
- }
68
- } else {
69
- this.setAttribute('class', sourceClass + ' js-visible')
70
- if (isSearchToggle) {
71
- this.innerText = hideText
72
- }
73
- }
74
- this.setAttribute('aria-expanded', this.getAttribute('aria-expanded') !== 'true')
75
- target.setAttribute('aria-hidden', target.getAttribute('aria-hidden') === 'false')
76
- })
77
- }
78
- }
79
- }).call(this)
80
-
81
- ;(function () {
82
- var $menuToggleButtons = document.querySelectorAll('.govuk-js-header-toggle')
83
-
84
- for (var j = 0; j < $menuToggleButtons.length; j++) {
85
- var element = $menuToggleButtons[j]
86
-
87
- element.addEventListener('click', function (event) {
88
- var buttonName = event.target.getAttribute('data-button-name') || 'menu'
89
- var expanded = event.target.getAttribute('aria-expanded')
90
-
91
- if (window.GOVUK.analytics && window.GOVUK.analytics.trackEvent) {
92
- if (expanded === 'true') {
93
- window.GOVUK.analytics.trackEvent('headerClicked', buttonName + 'Closed', { label: 'none' })
94
- } else {
95
- window.GOVUK.analytics.trackEvent('headerClicked', buttonName + 'Opened', { label: 'none' })
96
- }
97
- }
98
- })
99
- }
100
- })()
@@ -1,43 +0,0 @@
1
- module GovukPublishingComponents
2
- module Presenters
3
- class SelectHelper
4
- attr_reader :options, :option_markup, :selected_option
5
-
6
- def initialize(options)
7
- @options = options
8
- @option_markup = get_options
9
- end
10
-
11
- def data_tracking?
12
- @options.any? { |item| item[:data_attributes] && item[:data_attributes][:track_category] && item[:data_attributes][:track_action] }
13
- end
14
-
15
- private
16
-
17
- def get_options
18
- return if options.nil?
19
-
20
- options.map do |option|
21
- @selected_option = option[:value] if option[:selected]
22
- [
23
- option[:text],
24
- option[:value],
25
- options_data_attribute(option[:data_attributes]),
26
- ]
27
- end
28
- end
29
-
30
- def options_data_attribute(attributes)
31
- return {} if attributes.nil?
32
-
33
- attrs = {}
34
- attributes.each do |key, value|
35
- key_name = "data-#{key.to_s.split('_').join('-')}"
36
- attrs[key_name] = value.is_a?(Hash) ? value.to_json : value
37
- end
38
-
39
- attrs
40
- end
41
- end
42
- end
43
- end
@@ -1,49 +0,0 @@
1
- namespace :component do
2
- desc "warns if component view files exist without corresponding documentation"
3
- task :validate_documentation_exists do
4
- print "Validating that each component has documentation... "
5
- components_missing_docs = []
6
- component_views = Dir["app/views/#{GovukPublishingComponents::Config.component_directory_name}/**/*.html.erb"]
7
- component_views.each do |partial|
8
- expected_component_docs_file = partial.split("/")[-1].gsub("html.erb", "yml")
9
- expected_component_docs_file.sub!(/^_/, "")
10
-
11
- expected_component_docs_path = "app/views/#{GovukPublishingComponents::Config.component_directory_name}/docs/#{expected_component_docs_file}"
12
- components_missing_docs << partial unless File.exist?(expected_component_docs_path)
13
- end
14
-
15
- if components_missing_docs.any?
16
- error = "You have components which are missing documentation. These components will not be displayed in the component guide:\n"
17
- components_missing_docs.each { |component| error += "\t#{component}\n" }
18
- error += "\n"
19
- raise NotImplementedError, error
20
- end
21
- puts "✔︎"
22
- end
23
-
24
- desc "warns if component is missing accessibility criteria"
25
- task :validate_accessibility_criteria_exist do
26
- print "Validating that each component has accessibility criteria... "
27
- errors = []
28
-
29
- component_docs = Dir["app/views/#{GovukPublishingComponents::Config.component_directory_name}/**/*.yml"]
30
- component_docs.each do |doc_file|
31
- file = YAML.load_file(doc_file)
32
-
33
- if file["accessibility_criteria"].nil? && file["shared_accessibility_criteria"].nil?
34
- errors << file["name"]
35
- end
36
- end
37
- if errors.any?
38
- error = "The following components need accessibility criteria:\n#{errors.join("\n")}"
39
- raise NotImplementedError, error
40
- end
41
- puts "✔︎"
42
- end
43
-
44
- desc "warns if component view files exist without corresponding documentation or accessibility critera"
45
- task :validate_documentation do
46
- Rake::Task["component:validate_documentation_exists"].invoke
47
- Rake::Task["component:validate_accessibility_criteria_exist"].invoke
48
- end
49
- end