crown_marketplace_utils 0.1.0.beta.5 → 0.1.0.beta.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (30) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +10 -10
  3. data/lib/crown_marketplace_utils/helpers/gov_uk_helper/accordion.rb +91 -89
  4. data/lib/crown_marketplace_utils/helpers/gov_uk_helper/back_link.rb +24 -22
  5. data/lib/crown_marketplace_utils/helpers/gov_uk_helper/breadcrumbs.rb +56 -54
  6. data/lib/crown_marketplace_utils/helpers/gov_uk_helper/button.rb +109 -107
  7. data/lib/crown_marketplace_utils/helpers/gov_uk_helper/details.rb +33 -31
  8. data/lib/crown_marketplace_utils/helpers/gov_uk_helper/error_message.rb +49 -47
  9. data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/character_count.rb +144 -142
  10. data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/checkboxes.rb +176 -174
  11. data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/date_input.rb +126 -124
  12. data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/file_upload.rb +75 -73
  13. data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/input.rb +137 -135
  14. data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/radios.rb +176 -174
  15. data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/select.rb +111 -109
  16. data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/textarea.rb +86 -84
  17. data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field.rb +181 -179
  18. data/lib/crown_marketplace_utils/helpers/gov_uk_helper/fieldset.rb +56 -54
  19. data/lib/crown_marketplace_utils/helpers/gov_uk_helper/form_group.rb +37 -35
  20. data/lib/crown_marketplace_utils/helpers/gov_uk_helper/header.rb +142 -140
  21. data/lib/crown_marketplace_utils/helpers/gov_uk_helper/hint.rb +25 -23
  22. data/lib/crown_marketplace_utils/helpers/gov_uk_helper/label.rb +69 -67
  23. data/lib/crown_marketplace_utils/helpers/gov_uk_helper/notification_banner.rb +121 -119
  24. data/lib/crown_marketplace_utils/helpers/gov_uk_helper/pagination.rb +290 -288
  25. data/lib/crown_marketplace_utils/helpers/gov_uk_helper/step_by_step_navigation.rb +187 -185
  26. data/lib/crown_marketplace_utils/helpers/gov_uk_helper/tag.rb +29 -27
  27. data/lib/crown_marketplace_utils/helpers/gov_uk_helper/warning_text.rb +39 -37
  28. data/lib/crown_marketplace_utils/helpers/gov_uk_helper.rb +31 -29
  29. data/lib/crown_marketplace_utils/version.rb +1 -1
  30. metadata +2 -2
@@ -2,85 +2,87 @@
2
2
 
3
3
  require 'action_view'
4
4
 
5
- module CrownMarketplaceUtils::Helpers
6
- module GovUkHelper
7
- # = GOV.UK label
8
- #
9
- # This helper is used for generating the label component from the Government Design Systems
5
+ module CrownMarketplaceUtils
6
+ module Helpers
7
+ module GovUkHelper
8
+ # = GOV.UK label
9
+ #
10
+ # This helper is used for generating the label component from the Government Design Systems
10
11
 
11
- module Label
12
- include ActionView::Context
13
- include ActionView::Helpers::TagHelper
14
- include ActionView::Helpers::TextHelper
15
- include ActionView::Helpers::FormTagHelper
12
+ module Label
13
+ include ActionView::Context
14
+ include ActionView::Helpers::TagHelper
15
+ include ActionView::Helpers::TextHelper
16
+ include ActionView::Helpers::FormTagHelper
16
17
 
17
- # Generates the HTML for the GOV.UK label component
18
- #
19
- # @param attribute [String, Symbol] the attribute of the input that requires a label
20
- # @param label_text [String] the label text, it is ignored if a block is given
21
- # @param govuk_label_options [Hash] options that will be used in customising the HTML
22
- #
23
- # @option govuk_label_options [String] :classes additional CSS classes for the label HTML
24
- # @option govuk_label_options [Boolean] :is_page_heading (false) if the legend is also the heading it will rendered in a h1
25
- # @option govuk_label_options [ActionView::Helpers::FormBuilder] :form (nil) optional form builder used to create the label
26
- # @option govuk_label_options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
27
- #
28
- # @yield HTML that will be contained within the 'govuk-label' label. Ignored if label text is given
29
- #
30
- # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Label
31
- # which can then be rendered on the page
18
+ # Generates the HTML for the GOV.UK label component
19
+ #
20
+ # @param attribute [String, Symbol] the attribute of the input that requires a label
21
+ # @param label_text [String] the label text, it is ignored if a block is given
22
+ # @param govuk_label_options [Hash] options that will be used in customising the HTML
23
+ #
24
+ # @option govuk_label_options [String] :classes additional CSS classes for the label HTML
25
+ # @option govuk_label_options [Boolean] :is_page_heading (false) if the legend is also the heading it will rendered in a h1
26
+ # @option govuk_label_options [ActionView::Helpers::FormBuilder] :form (nil) optional form builder used to create the label
27
+ # @option govuk_label_options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
28
+ #
29
+ # @yield HTML that will be contained within the 'govuk-label' label. Ignored if label text is given
30
+ #
31
+ # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Label
32
+ # which can then be rendered on the page
32
33
 
33
- def govuk_label(attribute, label_text = nil, **govuk_label_options, &block)
34
- govuk_label_options[:attributes] ||= {}
35
- govuk_label_options[:attributes][:class] = "govuk-label #{govuk_label_options[:classes]}".rstrip
34
+ def govuk_label(attribute, label_text = nil, **govuk_label_options, &block)
35
+ govuk_label_options[:attributes] ||= {}
36
+ govuk_label_options[:attributes][:class] = "govuk-label #{govuk_label_options[:classes]}".rstrip
36
37
 
37
- label_html = if govuk_label_options[:form]
38
- govuk_label_form(attribute, label_text, **govuk_label_options, &block)
39
- else
40
- govuk_label_tag(attribute, label_text, **govuk_label_options, &block)
41
- end
38
+ label_html = if govuk_label_options[:form]
39
+ govuk_label_form(attribute, label_text, **govuk_label_options, &block)
40
+ else
41
+ govuk_label_tag(attribute, label_text, **govuk_label_options, &block)
42
+ end
42
43
 
43
- if govuk_label_options[:is_page_heading]
44
- tag.h1(label_html, class: 'govuk-label-wrapper')
45
- else
46
- label_html
44
+ if govuk_label_options[:is_page_heading]
45
+ tag.h1(label_html, class: 'govuk-label-wrapper')
46
+ else
47
+ label_html
48
+ end
47
49
  end
48
- end
49
50
 
50
- private
51
+ private
51
52
 
52
- # Generates the HTML for the GOV.UK label component
53
- # using the inbuilt rails method +label+
54
- #
55
- # @param (see govuk_label)
56
- #
57
- # @option (see govuk_label)
58
- #
59
- # @yield (see govuk_label)
60
- #
61
- # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Label
62
- # which can then be rendered on the page
53
+ # Generates the HTML for the GOV.UK label component
54
+ # using the inbuilt rails method +label+
55
+ #
56
+ # @param (see govuk_label)
57
+ #
58
+ # @option (see govuk_label)
59
+ #
60
+ # @yield (see govuk_label)
61
+ #
62
+ # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Label
63
+ # which can then be rendered on the page
63
64
 
64
- def govuk_label_tag(attribute, label_text, **govuk_label_options)
65
- label_tag(attribute, **govuk_label_options[:attributes]) do
66
- label_text || yield
65
+ def govuk_label_tag(attribute, label_text, **govuk_label_options)
66
+ label_tag(attribute, **govuk_label_options[:attributes]) do
67
+ label_text || yield
68
+ end
67
69
  end
68
- end
69
70
 
70
- # Generates the HTML for the GOV.UK label component
71
- # using the inbuilt rails ActionView::Helpers::FormBuilder
72
- #
73
- # @param (see govuk_label)
74
- #
75
- # @option (see govuk_label)
76
- #
77
- # @yield (see govuk_label)
78
- #
79
- # @return (see govuk_label_tag)
71
+ # Generates the HTML for the GOV.UK label component
72
+ # using the inbuilt rails ActionView::Helpers::FormBuilder
73
+ #
74
+ # @param (see govuk_label)
75
+ #
76
+ # @option (see govuk_label)
77
+ #
78
+ # @yield (see govuk_label)
79
+ #
80
+ # @return (see govuk_label_tag)
80
81
 
81
- def govuk_label_form(attribute, label_text, **govuk_label_options)
82
- govuk_label_options[:form].label(attribute, **govuk_label_options[:attributes]) do
83
- label_text || yield
82
+ def govuk_label_form(attribute, label_text, **govuk_label_options)
83
+ govuk_label_options[:form].label(attribute, **govuk_label_options[:attributes]) do
84
+ label_text || yield
85
+ end
84
86
  end
85
87
  end
86
88
  end
@@ -2,138 +2,140 @@
2
2
 
3
3
  require 'action_view'
4
4
 
5
- module CrownMarketplaceUtils::Helpers
6
- module GovUkHelper
7
- # = GOV.UK Notification Banner
8
- #
9
- # This helper is used for generating the notification banner component from the
10
- # {https://design-system.service.gov.uk/components/notification-banner GDS - Components - Notification banner}
11
-
12
- module NotificationBanner
13
- include ActionView::Context
14
- include ActionView::Helpers::TagHelper
15
- include ActionView::Helpers::TextHelper
16
-
17
- # Generates the HTML for the GOV.UK Notification banner component
5
+ module CrownMarketplaceUtils
6
+ module Helpers
7
+ module GovUkHelper
8
+ # = GOV.UK Notification Banner
18
9
  #
19
- # @param text [String] the text that will be used for the heading in the content section of the banner.
20
- # It is ignored if a block is given
21
- # @param success_banner [Boolean] will use the success banner options if this is set to true
22
- # @param govuk_notification_banner_options [Hash] options that will be used in customising the HTML
23
- #
24
- # @option govuk_notification_banner_options [String] :classes additional CSS classes for the notification banner HTML
25
- # @option govuk_notification_banner_options [String] :title_text ('Important') the title text shown at the top of the banner
26
- # @option govuk_notification_banner_options [String] :title_id ('govuk-notification-banner-title') the ID for the title text
27
- # @option govuk_notification_banner_options [String] :role ('region') the role for the banner
28
- # @option govuk_notification_banner_options [String] :heading_level (2) the heading level for the title text
29
- # @option govuk_notification_banner_options [Hash] :attributes ({data: { module: 'govuk-notification-banner' }, aria: { labelledby: 'govuk-notification-banner-title' }})
30
- # any additional attributes that will added as part of the HTML
31
- #
32
- # @yield HTML that will be contained within the 'govuk-notification-banner__content' div
33
- #
34
- # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Notification banner
35
- # which can then be rendered on the page
36
-
37
- def govuk_notification_banner(text = nil, success_banner = false, **govuk_notification_banner_options)
38
- banner_options = fetch_banner_options(success_banner, govuk_notification_banner_options)
39
- govuk_notification_banner_classes = fetch_banner_classes(banner_options, govuk_notification_banner_options)
40
- govuk_notification_banner_attributes = fetch_banner_attributes(banner_options, govuk_notification_banner_options)
41
-
42
- tag.div(class: govuk_notification_banner_classes, role: banner_options[:role], **govuk_notification_banner_attributes) do
43
- capture do
44
- concat(tag.div(class: 'govuk-notification-banner__header') do
45
- tag.send(:"h#{govuk_notification_banner_options[:heading_level] || 2}", banner_options[:title_text], class: 'govuk-notification-banner__title', id: banner_options[:title_id])
46
- end)
47
- concat(tag.div(class: 'govuk-notification-banner__content') do
48
- if block_given?
49
- yield
50
- else
51
- tag.p(text, class: 'govuk-notification-banner__heading')
52
- end
53
- end)
10
+ # This helper is used for generating the notification banner component from the
11
+ # {https://design-system.service.gov.uk/components/notification-banner GDS - Components - Notification banner}
12
+
13
+ module NotificationBanner
14
+ include ActionView::Context
15
+ include ActionView::Helpers::TagHelper
16
+ include ActionView::Helpers::TextHelper
17
+
18
+ # Generates the HTML for the GOV.UK Notification banner component
19
+ #
20
+ # @param text [String] the text that will be used for the heading in the content section of the banner.
21
+ # It is ignored if a block is given
22
+ # @param success_banner [Boolean] will use the success banner options if this is set to true
23
+ # @param govuk_notification_banner_options [Hash] options that will be used in customising the HTML
24
+ #
25
+ # @option govuk_notification_banner_options [String] :classes additional CSS classes for the notification banner HTML
26
+ # @option govuk_notification_banner_options [String] :title_text ('Important') the title text shown at the top of the banner
27
+ # @option govuk_notification_banner_options [String] :title_id ('govuk-notification-banner-title') the ID for the title text
28
+ # @option govuk_notification_banner_options [String] :role ('region') the role for the banner
29
+ # @option govuk_notification_banner_options [String] :heading_level (2) the heading level for the title text
30
+ # @option govuk_notification_banner_options [Hash] :attributes ({data: { module: 'govuk-notification-banner' }, aria: { labelledby: 'govuk-notification-banner-title' }})
31
+ # any additional attributes that will added as part of the HTML
32
+ #
33
+ # @yield HTML that will be contained within the 'govuk-notification-banner__content' div
34
+ #
35
+ # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Notification banner
36
+ # which can then be rendered on the page
37
+
38
+ def govuk_notification_banner(text = nil, success_banner = false, **govuk_notification_banner_options)
39
+ banner_options = fetch_banner_options(success_banner, govuk_notification_banner_options)
40
+ govuk_notification_banner_classes = fetch_banner_classes(banner_options, govuk_notification_banner_options)
41
+ govuk_notification_banner_attributes = fetch_banner_attributes(banner_options, govuk_notification_banner_options)
42
+
43
+ tag.div(class: govuk_notification_banner_classes, role: banner_options[:role], **govuk_notification_banner_attributes) do
44
+ capture do
45
+ concat(tag.div(class: 'govuk-notification-banner__header') do
46
+ tag.send(:"h#{govuk_notification_banner_options[:heading_level] || 2}", banner_options[:title_text], class: 'govuk-notification-banner__title', id: banner_options[:title_id])
47
+ end)
48
+ concat(tag.div(class: 'govuk-notification-banner__content') do
49
+ if block_given?
50
+ yield
51
+ else
52
+ tag.p(text, class: 'govuk-notification-banner__heading')
53
+ end
54
+ end)
55
+ end
54
56
  end
55
57
  end
56
- end
57
58
 
58
- private
59
-
60
- # Determines the banner options to be used for {#govuk_notification_banner}
61
- #
62
- # @param success_banner [Boolean] will use the success banner options if this is set to true
63
- # @param govuk_notification_banner_options [Hash] options that will be used in customising the HTML
64
- #
65
- # @option govuk_notification_banner_options [String] :title_text ('Important') the title text shown at the top of the banner
66
- # @option govuk_notification_banner_options [String] :title_id ('govuk-notification-banner-title') the ID for the title text
67
- # @option govuk_notification_banner_options [String] :role ('region') the role for the banner
68
- #
69
- # @return [Hash] contains the following options used in {#govuk_notification_banner}:
70
- # - +classes+
71
- # - +title_text+
72
- # - +title_id+
73
- # - +role+
74
-
75
- def fetch_banner_options(success_banner, govuk_notification_banner_options)
76
- banner_options = DEFAULT_OPTIONS.dup
77
-
78
- banner_options.merge!(SUCCESS_BANNER_OPTIONS) if success_banner
59
+ private
60
+
61
+ # Determines the banner options to be used for {#govuk_notification_banner}
62
+ #
63
+ # @param success_banner [Boolean] will use the success banner options if this is set to true
64
+ # @param govuk_notification_banner_options [Hash] options that will be used in customising the HTML
65
+ #
66
+ # @option govuk_notification_banner_options [String] :title_text ('Important') the title text shown at the top of the banner
67
+ # @option govuk_notification_banner_options [String] :title_id ('govuk-notification-banner-title') the ID for the title text
68
+ # @option govuk_notification_banner_options [String] :role ('region') the role for the banner
69
+ #
70
+ # @return [Hash] contains the following options used in {#govuk_notification_banner}:
71
+ # - +classes+
72
+ # - +title_text+
73
+ # - +title_id+
74
+ # - +role+
75
+
76
+ def fetch_banner_options(success_banner, govuk_notification_banner_options)
77
+ banner_options = DEFAULT_OPTIONS.dup
78
+
79
+ banner_options.merge!(SUCCESS_BANNER_OPTIONS) if success_banner
80
+
81
+ govuk_notification_banner_options.each do |key, value|
82
+ banner_options[key] = value if banner_options.key?(key)
83
+ end
79
84
 
80
- govuk_notification_banner_options.each do |key, value|
81
- banner_options[key] = value if banner_options.key?(key)
85
+ banner_options
82
86
  end
83
87
 
84
- banner_options
85
- end
86
-
87
- # Determines the banner classes to be used for {#govuk_notification_banner}
88
- #
89
- # @param banner_options [Hash] this is the return value from {#fetch_banner_options}
90
- # @param govuk_notification_banner_options [Hash] options that will be used in customising the HTML
91
- #
92
- # @option govuk_notification_banner_options [String] :classes additional CSS classes for the notification banner HTML
93
- #
94
- # @return [Array<String>] an array of classes to be used in {#govuk_notification_banner}
88
+ # Determines the banner classes to be used for {#govuk_notification_banner}
89
+ #
90
+ # @param banner_options [Hash] this is the return value from {#fetch_banner_options}
91
+ # @param govuk_notification_banner_options [Hash] options that will be used in customising the HTML
92
+ #
93
+ # @option govuk_notification_banner_options [String] :classes additional CSS classes for the notification banner HTML
94
+ #
95
+ # @return [Array<String>] an array of classes to be used in {#govuk_notification_banner}
96
+
97
+ def fetch_banner_classes(banner_options, govuk_notification_banner_options)
98
+ govuk_notification_banner_classes = ['govuk-notification-banner']
99
+ govuk_notification_banner_classes << govuk_notification_banner_options[:classes]
100
+ govuk_notification_banner_classes << banner_options[:classes]
101
+
102
+ govuk_notification_banner_classes
103
+ end
95
104
 
96
- def fetch_banner_classes(banner_options, govuk_notification_banner_options)
97
- govuk_notification_banner_classes = ['govuk-notification-banner']
98
- govuk_notification_banner_classes << govuk_notification_banner_options[:classes]
99
- govuk_notification_banner_classes << banner_options[:classes]
105
+ # Default HTML attributes for {#govuk_notification_banner}
106
+ #
107
+ # @param banner_options [Hash] this is the return value from {#fetch_banner_options}
108
+ # @param govuk_notification_banner_options [Hash] options that will be used in customising the HTML
109
+ #
110
+ # @option govuk_notification_banner_options [Hash] :attributes ({data: { module: 'govuk-notification-banner' }, aria: { labelledby: 'govuk-notification-banner-title' }})
111
+ # any additional attributes that will added as part of the HTML
112
+ #
113
+ # @return [Hash] contains the default attributes for {#govuk_notification_banner} and any additional attributes that were passed
114
+
115
+ def fetch_banner_attributes(banner_options, govuk_notification_banner_options)
116
+ govuk_notification_banner_attributes = govuk_notification_banner_options[:attributes] || {}
117
+ (govuk_notification_banner_attributes[:data] ||= {}).merge!({ module: 'govuk-notification-banner' })
118
+ (govuk_notification_banner_attributes[:aria] ||= {}).merge!({ labelledby: banner_options[:title_id] })
119
+
120
+ govuk_notification_banner_attributes
121
+ end
100
122
 
101
- govuk_notification_banner_classes
102
- end
123
+ # Default options used in normal versions of {#govuk_notification_banner}
103
124
 
104
- # Default HTML attributes for {#govuk_notification_banner}
105
- #
106
- # @param banner_options [Hash] this is the return value from {#fetch_banner_options}
107
- # @param govuk_notification_banner_options [Hash] options that will be used in customising the HTML
108
- #
109
- # @option govuk_notification_banner_options [Hash] :attributes ({data: { module: 'govuk-notification-banner' }, aria: { labelledby: 'govuk-notification-banner-title' }})
110
- # any additional attributes that will added as part of the HTML
111
- #
112
- # @return [Hash] contains the default attributes for {#govuk_notification_banner} and any additional attributes that were passed
125
+ DEFAULT_OPTIONS = {
126
+ title_text: 'Important',
127
+ title_id: 'govuk-notification-banner-title',
128
+ role: 'region'
129
+ }.freeze
113
130
 
114
- def fetch_banner_attributes(banner_options, govuk_notification_banner_options)
115
- govuk_notification_banner_attributes = govuk_notification_banner_options[:attributes] || {}
116
- (govuk_notification_banner_attributes[:data] ||= {}).merge!({ module: 'govuk-notification-banner' })
117
- (govuk_notification_banner_attributes[:aria] ||= {}).merge!({ labelledby: banner_options[:title_id] })
131
+ # Options specific for the success version of {#govuk_notification_banner}
118
132
 
119
- govuk_notification_banner_attributes
133
+ SUCCESS_BANNER_OPTIONS = {
134
+ classes: 'govuk-notification-banner--success',
135
+ title_text: 'Success',
136
+ role: 'alert'
137
+ }.freeze
120
138
  end
121
-
122
- # Default options used in normal versions of {#govuk_notification_banner}
123
-
124
- DEFAULT_OPTIONS = {
125
- title_text: 'Important',
126
- title_id: 'govuk-notification-banner-title',
127
- role: 'region'
128
- }.freeze
129
-
130
- # Options specific for the success version of {#govuk_notification_banner}
131
-
132
- SUCCESS_BANNER_OPTIONS = {
133
- classes: 'govuk-notification-banner--success',
134
- title_text: 'Success',
135
- role: 'alert'
136
- }.freeze
137
139
  end
138
140
  end
139
141
  end