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.
- checksums.yaml +4 -4
- data/Gemfile.lock +10 -10
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/accordion.rb +91 -89
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/back_link.rb +24 -22
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/breadcrumbs.rb +56 -54
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/button.rb +109 -107
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/details.rb +33 -31
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/error_message.rb +49 -47
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/character_count.rb +144 -142
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/checkboxes.rb +176 -174
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/date_input.rb +126 -124
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/file_upload.rb +75 -73
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/input.rb +137 -135
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/radios.rb +176 -174
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/select.rb +111 -109
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/textarea.rb +86 -84
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field.rb +181 -179
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/fieldset.rb +56 -54
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/form_group.rb +37 -35
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/header.rb +142 -140
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/hint.rb +25 -23
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/label.rb +69 -67
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/notification_banner.rb +121 -119
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/pagination.rb +290 -288
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/step_by_step_navigation.rb +187 -185
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/tag.rb +29 -27
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/warning_text.rb +39 -37
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper.rb +31 -29
- data/lib/crown_marketplace_utils/version.rb +1 -1
- metadata +2 -2
@@ -3,149 +3,151 @@
|
|
3
3
|
require_relative '../field'
|
4
4
|
require_relative 'input'
|
5
5
|
|
6
|
-
module CrownMarketplaceUtils
|
7
|
-
module
|
8
|
-
module
|
9
|
-
|
10
|
-
|
11
|
-
# This helper is used for generating the date input component from the
|
12
|
-
# {https://design-system.service.gov.uk/components/date-input GDS - Components - Date Input}
|
13
|
-
#
|
14
|
-
# This is considered a Field module and so makes use of the methods in {CrownMarketplaceUtils::GovUkHelper::Field}
|
15
|
-
|
16
|
-
module DateInput
|
17
|
-
include Field
|
18
|
-
include Input
|
19
|
-
|
20
|
-
# Generates the HTML for the GOV.UK date input component
|
6
|
+
module CrownMarketplaceUtils
|
7
|
+
module Helpers
|
8
|
+
module GovUkHelper
|
9
|
+
module Field
|
10
|
+
# = GOV.UK Date Input
|
21
11
|
#
|
22
|
-
#
|
23
|
-
#
|
12
|
+
# This helper is used for generating the date input component from the
|
13
|
+
# {https://design-system.service.gov.uk/components/date-input GDS - Components - Date Input}
|
24
14
|
#
|
25
|
-
#
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
15
|
+
# This is considered a Field module and so makes use of the methods in {CrownMarketplaceUtils::GovUkHelper::Field}
|
16
|
+
|
17
|
+
module DateInput
|
18
|
+
include Field
|
19
|
+
include Input
|
20
|
+
|
21
|
+
# Generates the HTML for the GOV.UK date input component
|
22
|
+
#
|
23
|
+
# @param attribute [String, Symbol] the attribute of the date input
|
24
|
+
# @param govuk_date_input_options [Hash] options that will be used for the parts of the fieldset, form group, hint and date input
|
25
|
+
#
|
26
|
+
# @option govuk_date_input_options [String] :error_message (nil) the error message to be displayed
|
27
|
+
# @option govuk_date_input_options [ActiveModel] :model (nil) optional model that can be used to find an error message
|
28
|
+
# @option govuk_date_input_options [ActionView::Helpers::FormBuilder] :form (nil) optional form builder used to create
|
29
|
+
# the date tag and find the error message
|
30
|
+
# @option govuk_date_input_options [Hash] :form_group see {govuk_fields}
|
31
|
+
# @option govuk_date_input_options [Hash] :fieldset see {govuk_fields}
|
32
|
+
# @option govuk_date_input_options [Hash] :hint see {govuk_field}
|
33
|
+
# @option govuk_date_input_options [Hash] :date_input_options ({}) the options that will be used when rendering the date input.
|
34
|
+
# See {_govuk_date_input_fields} for more details.
|
35
|
+
#
|
36
|
+
# @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Date Input
|
37
|
+
# which can then be rendered on the page
|
38
|
+
|
39
|
+
def govuk_date_input(attribute, **govuk_date_input_options)
|
40
|
+
set_govuk_date_input_fieldset_options(**govuk_date_input_options)
|
41
|
+
|
42
|
+
govuk_fields(:date_input, attribute, **govuk_date_input_options) do |govuk_field_options, error_message|
|
43
|
+
concat(_govuk_date_input_fields(attribute, error_message, **govuk_field_options) do |date_item_attribute, date_item_input_options|
|
44
|
+
govuk_input(
|
45
|
+
date_item_attribute,
|
46
|
+
model: govuk_date_input_options[:model],
|
47
|
+
form: govuk_date_input_options[:form],
|
48
|
+
**date_item_input_options
|
49
|
+
)
|
50
|
+
end)
|
51
|
+
end
|
50
52
|
end
|
51
|
-
end
|
52
53
|
|
53
|
-
|
54
|
+
private
|
54
55
|
|
55
|
-
|
56
|
-
|
57
|
-
|
56
|
+
# Sets the role for the fieldset to group
|
57
|
+
#
|
58
|
+
# @param govuk_date_input_options [Hash] options that will be used for the parts of the fieldset, form group, hint and date input
|
58
59
|
|
59
|
-
|
60
|
-
|
61
|
-
|
60
|
+
def set_govuk_date_input_fieldset_options(**govuk_date_input_options)
|
61
|
+
(govuk_date_input_options[:fieldset][:attributes] ||= {})[:role] = 'group'
|
62
|
+
end
|
62
63
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
64
|
+
# Wrapper method used by {govuk_date_input} to generate the date inputs HTML
|
65
|
+
#
|
66
|
+
# @param attribute [String, Symbol] the attribute of the date input
|
67
|
+
# @param any_errors [Boolean] flag to indicate if the inputs need the error class
|
68
|
+
# @param govuk_date_input_options [Hash] options that will be used in customising the HTML
|
69
|
+
#
|
70
|
+
# @option govuk_date_input_options [String] :classes additional CSS classes for the date inputs HTML
|
71
|
+
# @option govuk_date_input_options[Array] :date_items an array of the date items that will be rendered.
|
72
|
+
# Each date item hash must contain the +:name+ to add as suffix to attribute.
|
73
|
+
# Anything else in the hash will be used as options in a {govuk_input}.
|
74
|
+
# @option govuk_date_input_options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
|
75
|
+
#
|
76
|
+
# @yield the date input item HTML generated by the parent method
|
77
|
+
#
|
78
|
+
# @yieldparam date_item_attribute [String] the attribute for individual date input
|
79
|
+
# @yieldparam date_item_input_options [Hash] the HTML options used for the date input item
|
80
|
+
#
|
81
|
+
# @return [ActiveSupport::SafeBuffer] the HTML for the date inputs which is used in {govuk_date_input}
|
82
|
+
|
83
|
+
def _govuk_date_input_fields(attribute, any_errors, **govuk_date_input_options)
|
84
|
+
govuk_date_input_options[:attributes] ||= {}
|
85
|
+
govuk_date_input_options[:attributes][:class] = "govuk-date-input #{govuk_date_input_options[:classes]}".rstrip
|
86
|
+
date_items = govuk_date_input_options[:date_items] || govuk_default_date_items
|
87
|
+
|
88
|
+
tag.div(**govuk_date_input_options[:attributes]) do
|
89
|
+
capture do
|
90
|
+
enumerate_and_set_date_input_options(date_items, any_errors) do |date_item_input_options|
|
91
|
+
concat(tag.div(class: 'govuk-date-input__item') do
|
92
|
+
concat(yield("#{attribute}_#{date_item_input_options[:name]}", date_item_input_options))
|
93
|
+
end)
|
94
|
+
end
|
93
95
|
end
|
94
96
|
end
|
95
97
|
end
|
96
|
-
end
|
97
98
|
|
98
|
-
|
99
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
99
100
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
101
|
+
# Enumerates and inititalises the attributes of each date input item and is used by {_govuk_date_input_fields}
|
102
|
+
#
|
103
|
+
# @param date_items [Array] an array of the date item hashes that will be inititalised
|
104
|
+
# @param any_errors [Boolean] flag to indicate if the inputs need the error class
|
105
|
+
#
|
106
|
+
# @yield the date input item HTML generated by teach date input item
|
107
|
+
#
|
108
|
+
# @yieldparam date_item_input_options [Hash] the HTML options used for the date input item
|
108
109
|
|
109
|
-
|
110
|
-
|
111
|
-
|
110
|
+
def enumerate_and_set_date_input_options(date_items, any_errors)
|
111
|
+
date_items.each do |date_item_input_options|
|
112
|
+
(date_item_input_options[:input] ||= {})[:attributes] ||= {}
|
112
113
|
|
113
|
-
|
114
|
+
date_item_input_options[:input][:classes] = "govuk-date-input__input #{date_item_input_options[:input][:classes]} #{'govuk-input--error' if any_errors}".rstrip
|
114
115
|
|
115
|
-
|
116
|
+
date_item_input_options[:input][:attributes][:inputmode] ||= 'numeric'
|
116
117
|
|
117
|
-
|
118
|
-
|
119
|
-
|
118
|
+
date_item_input_options[:label] ||= {}
|
119
|
+
date_item_input_options[:label][:text] ||= date_item_input_options[:name].capitalize
|
120
|
+
date_item_input_options[:label][:classes] = 'govuk-date-input__label'
|
120
121
|
|
121
|
-
|
122
|
+
yield(date_item_input_options)
|
123
|
+
end
|
122
124
|
end
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
}
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
125
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
126
|
+
|
127
|
+
# The default date items used in {_govuk_date_input_fields} if no date items are provided
|
128
|
+
|
129
|
+
def govuk_default_date_items
|
130
|
+
[
|
131
|
+
{
|
132
|
+
name: 'day',
|
133
|
+
input: {
|
134
|
+
classes: 'govuk-input--width-2'
|
135
|
+
}
|
136
|
+
},
|
137
|
+
{
|
138
|
+
name: 'month',
|
139
|
+
input: {
|
140
|
+
classes: 'govuk-input--width-2'
|
141
|
+
}
|
142
|
+
},
|
143
|
+
{
|
144
|
+
name: 'year',
|
145
|
+
input: {
|
146
|
+
classes: 'govuk-input--width-4'
|
147
|
+
}
|
140
148
|
}
|
141
|
-
|
142
|
-
|
143
|
-
name: 'year',
|
144
|
-
input: {
|
145
|
-
classes: 'govuk-input--width-4'
|
146
|
-
}
|
147
|
-
}
|
148
|
-
]
|
149
|
+
]
|
150
|
+
end
|
149
151
|
end
|
150
152
|
end
|
151
153
|
end
|
@@ -2,91 +2,93 @@
|
|
2
2
|
|
3
3
|
require_relative '../field'
|
4
4
|
|
5
|
-
module CrownMarketplaceUtils
|
6
|
-
module
|
7
|
-
module
|
8
|
-
|
9
|
-
|
10
|
-
# This helper is used for generating the file upload component from the
|
11
|
-
# {https://design-system.service.gov.uk/components/file-upload GDS - Components - File Upload}
|
12
|
-
#
|
13
|
-
# This is considered a Field module and so makes use of the methods in {CrownMarketplaceUtils::GovUkHelper::Field}
|
14
|
-
|
15
|
-
module FileUpload
|
16
|
-
include Field
|
17
|
-
|
18
|
-
# Generates the HTML for the GOV.UK file upload component
|
19
|
-
#
|
20
|
-
# @param attribute [String, Symbol] the attribute of the file upload
|
21
|
-
# @param govuk_file_upload_options [Hash] options that will be used for the parts of the form group, label, hint and file upload
|
5
|
+
module CrownMarketplaceUtils
|
6
|
+
module Helpers
|
7
|
+
module GovUkHelper
|
8
|
+
module Field
|
9
|
+
# = GOV.UK File Upload
|
22
10
|
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
# @option govuk_file_upload_options [ActionView::Helpers::FormBuilder] :form (nil) optional form builder used to create
|
26
|
-
# the file upload input and find the error message
|
27
|
-
# @option govuk_file_upload_options [Hash] :form_group see {govuk_field}
|
28
|
-
# @option govuk_file_upload_options [Hash] :label see {govuk_field}
|
29
|
-
# @option govuk_file_upload_options [Hash] :hint see {govuk_field}
|
30
|
-
# @option govuk_file_upload_options [Hash] :file_upload ({}) the options that will be used when rendering the file upload.
|
31
|
-
# See {set_file_upload_options} for more details.
|
11
|
+
# This helper is used for generating the file upload component from the
|
12
|
+
# {https://design-system.service.gov.uk/components/file-upload GDS - Components - File Upload}
|
32
13
|
#
|
33
|
-
#
|
34
|
-
|
14
|
+
# This is considered a Field module and so makes use of the methods in {CrownMarketplaceUtils::GovUkHelper::Field}
|
15
|
+
|
16
|
+
module FileUpload
|
17
|
+
include Field
|
18
|
+
|
19
|
+
# Generates the HTML for the GOV.UK file upload component
|
20
|
+
#
|
21
|
+
# @param attribute [String, Symbol] the attribute of the file upload
|
22
|
+
# @param govuk_file_upload_options [Hash] options that will be used for the parts of the form group, label, hint and file upload
|
23
|
+
#
|
24
|
+
# @option govuk_file_upload_options [String] :error_message (nil) the error message to be displayed
|
25
|
+
# @option govuk_file_upload_options [ActiveModel] :model (nil) optional model that can be used to find an error message
|
26
|
+
# @option govuk_file_upload_options [ActionView::Helpers::FormBuilder] :form (nil) optional form builder used to create
|
27
|
+
# the file upload input and find the error message
|
28
|
+
# @option govuk_file_upload_options [Hash] :form_group see {govuk_field}
|
29
|
+
# @option govuk_file_upload_options [Hash] :label see {govuk_field}
|
30
|
+
# @option govuk_file_upload_options [Hash] :hint see {govuk_field}
|
31
|
+
# @option govuk_file_upload_options [Hash] :file_upload ({}) the options that will be used when rendering the file upload.
|
32
|
+
# See {set_file_upload_options} for more details.
|
33
|
+
#
|
34
|
+
# @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK File Upload
|
35
|
+
# which can then be rendered on the page
|
35
36
|
|
36
|
-
|
37
|
-
|
38
|
-
|
37
|
+
def govuk_file_upload(attribute, **govuk_file_upload_options)
|
38
|
+
govuk_field(:file_upload, attribute, **govuk_file_upload_options) do |govuk_field_options, error_message|
|
39
|
+
set_file_upload_options(error_message, govuk_field_options)
|
39
40
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
41
|
+
concat(
|
42
|
+
if govuk_file_upload_options[:form]
|
43
|
+
govuk_file_upload_form(govuk_file_upload_options[:form], attribute, **govuk_field_options)
|
44
|
+
else
|
45
|
+
govuk_file_upload_tag(attribute, **govuk_field_options)
|
46
|
+
end
|
47
|
+
)
|
48
|
+
end
|
47
49
|
end
|
48
|
-
end
|
49
50
|
|
50
|
-
|
51
|
+
private
|
51
52
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
53
|
+
# Generates the file upload HTML for {govuk_file_upload}
|
54
|
+
#
|
55
|
+
# @param attribute [String, Symbol] the attribute of the file upload
|
56
|
+
# @param govuk_file_upload_options [Hash] options that will be used in customising the HTML
|
57
|
+
#
|
58
|
+
# @option (see set_file_upload_options)
|
59
|
+
#
|
60
|
+
# @return [ActiveSupport::SafeBuffer] the HTML for the file upload field which is used in {govuk_file_upload}
|
60
61
|
|
61
|
-
|
62
|
-
|
63
|
-
|
62
|
+
def govuk_file_upload_tag(attribute, **govuk_file_upload_options)
|
63
|
+
file_field_tag(attribute, **govuk_file_upload_options[:attributes])
|
64
|
+
end
|
64
65
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
66
|
+
# Generates the file upload HTML for {govuk_file_upload} when there is a ActionView::Helpers::FormBuilder
|
67
|
+
#
|
68
|
+
# @param form [ActionView::Helpers::FormBuilder] the form builder used to create the file upload input
|
69
|
+
# @param (see govuk_file_upload_tag)
|
70
|
+
#
|
71
|
+
# @option (see set_file_upload_options)
|
72
|
+
#
|
73
|
+
# @return (see govuk_file_upload_tag)
|
73
74
|
|
74
|
-
|
75
|
-
|
76
|
-
|
75
|
+
def govuk_file_upload_form(form, attribute, **govuk_file_upload_options)
|
76
|
+
form.file_field(attribute, **govuk_file_upload_options[:attributes])
|
77
|
+
end
|
77
78
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
79
|
+
# Initialises the attributes for the file upload input
|
80
|
+
#
|
81
|
+
# @param error_message [String] used to indicate if there is an error which will add extra classes
|
82
|
+
# @param govuk_file_upload_options [Hash] options that will be used in customising the HTML
|
83
|
+
#
|
84
|
+
# @option govuk_file_upload_options [String] :classes additional CSS classes for the file iupload HTML
|
85
|
+
# @option govuk_file_upload_options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
|
85
86
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
87
|
+
def set_file_upload_options(error_message, govuk_file_upload_options)
|
88
|
+
govuk_file_upload_options[:attributes] ||= {}
|
89
|
+
govuk_file_upload_options[:attributes][:class] = "govuk-file-upload #{govuk_file_upload_options[:classes]}".rstrip
|
90
|
+
govuk_file_upload_options[:attributes][:class] << ' govuk-file-upload--error' if error_message
|
91
|
+
end
|
90
92
|
end
|
91
93
|
end
|
92
94
|
end
|