crown_marketplace_utils 0.1.0.beta.6 → 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 +1 -1
  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 +1 -1
@@ -2,121 +2,123 @@
2
2
 
3
3
  require 'action_view'
4
4
 
5
- module CrownMarketplaceUtils::Helpers
6
- module GovUkHelper
7
- # = GOV.UK Button
8
- #
9
- # This helper is used for generating the button component from the
10
- # {https://design-system.service.gov.uk/components/button GDS - Components - Button}
11
-
12
- module Button
13
- include ActionView::Context
14
- include ActionView::Helpers::TagHelper
15
- include ActionView::Helpers::TextHelper
16
- include ActionView::Helpers::UrlHelper
17
- include ActionView::Helpers::FormTagHelper
18
-
19
- # Generates the HTML for the GOV.UK button component
5
+ module CrownMarketplaceUtils
6
+ module Helpers
7
+ module GovUkHelper
8
+ # = GOV.UK Button
20
9
  #
21
- # @param text [String] the text that will be shown in the button
22
- # @param govuk_button_options [Hash] options that will be used in customising the HTML
23
- #
24
- # @option govuk_button_options [String] :classes additional CSS classes for the button HTML
25
- # @option govuk_button_options [Boolean] :is_start_button indicates if it is a start button
26
- # @option govuk_button_options [String] :href the URI that will be used in anchor tag
27
- # @option govuk_button_options [ActionView::Helpers::FormBuilder] :form the form builder used to create the submit button
28
- # @option govuk_button_options [Hash] :attributes ({ data: { module: 'govuk-button' } }) any additional attributes that will added as part of the HTML
29
- #
30
- # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Button
31
- # which can then be rendered on the page
32
-
33
- def govuk_button(text, **govuk_button_options)
34
- govuk_button_classes = ['govuk-button']
35
- govuk_button_classes << govuk_button_options[:classes]
36
- govuk_button_options[:attributes] ||= {}
37
- govuk_button_classes << 'govuk-button--disabled' if govuk_button_options[:attributes][:disabled]
38
- govuk_button_classes << 'govuk-button--start' if govuk_button_options[:is_start_button]
39
-
40
- (govuk_button_options[:attributes][:data] ||= {}).merge!({ module: 'govuk-button' })
41
-
42
- button_method = if govuk_button_options[:href]
43
- :govuk_button_link
44
- elsif govuk_button_options[:form]
45
- :govuk_button_submit
46
- else
47
- :govuk_button_button
48
- end
49
-
50
- send(button_method, text, govuk_button_classes, **govuk_button_options)
51
- end
52
-
53
- private
54
-
55
- # Generates the HTML for the GOV.UK button component as an anchor tag.
56
- # It is called by {#govuk_button} which will pass in the parameters, including any defaults.
57
- #
58
- # @param text [String] the text that will be shown in the button
59
- # @param classes [String] additional CSS classes for the button HTML
60
- # @param govuk_button_options [Hash] options that will be used in customising the HTML
61
- #
62
- # @option govuk_button_options [Boolean] :is_start_button indicates if it is a start button
63
- # @option govuk_button_options [String] :href the URI that will be used in anchor tag
64
- # @option govuk_button_options [Hash] :attributes any additional attributes that will added as part of the HTML
65
- #
66
- # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Button as an anchor element
67
- # which can then be rendered on the page
68
-
69
- def govuk_button_link(text, classes, **govuk_button_options)
70
- link_to(govuk_button_options[:href], class: classes, role: :button, draggable: false, **govuk_button_options[:attributes]) do
71
- concat(text)
72
- concat(govuk_start_button_icon) if govuk_button_options[:is_start_button]
10
+ # This helper is used for generating the button component from the
11
+ # {https://design-system.service.gov.uk/components/button GDS - Components - Button}
12
+
13
+ module Button
14
+ include ActionView::Context
15
+ include ActionView::Helpers::TagHelper
16
+ include ActionView::Helpers::TextHelper
17
+ include ActionView::Helpers::UrlHelper
18
+ include ActionView::Helpers::FormTagHelper
19
+
20
+ # Generates the HTML for the GOV.UK button component
21
+ #
22
+ # @param text [String] the text that will be shown in the button
23
+ # @param govuk_button_options [Hash] options that will be used in customising the HTML
24
+ #
25
+ # @option govuk_button_options [String] :classes additional CSS classes for the button HTML
26
+ # @option govuk_button_options [Boolean] :is_start_button indicates if it is a start button
27
+ # @option govuk_button_options [String] :href the URI that will be used in anchor tag
28
+ # @option govuk_button_options [ActionView::Helpers::FormBuilder] :form the form builder used to create the submit button
29
+ # @option govuk_button_options [Hash] :attributes ({ data: { module: 'govuk-button' } }) any additional attributes that will added as part of the HTML
30
+ #
31
+ # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Button
32
+ # which can then be rendered on the page
33
+
34
+ def govuk_button(text, **govuk_button_options)
35
+ govuk_button_classes = ['govuk-button']
36
+ govuk_button_classes << govuk_button_options[:classes]
37
+ govuk_button_options[:attributes] ||= {}
38
+ govuk_button_classes << 'govuk-button--disabled' if govuk_button_options[:attributes][:disabled]
39
+ govuk_button_classes << 'govuk-button--start' if govuk_button_options[:is_start_button]
40
+
41
+ (govuk_button_options[:attributes][:data] ||= {}).merge!({ module: 'govuk-button' })
42
+
43
+ button_method = if govuk_button_options[:href]
44
+ :govuk_button_link
45
+ elsif govuk_button_options[:form]
46
+ :govuk_button_submit
47
+ else
48
+ :govuk_button_button
49
+ end
50
+
51
+ send(button_method, text, govuk_button_classes, **govuk_button_options)
73
52
  end
74
- end
75
-
76
- # Generates the HTML for the GOV.UK button component as a button.
77
- # It is called by {#govuk_button} which will pass in the parameters, including any defaults.
78
- #
79
- # @param text [String] the text that will be shown in the button
80
- # @param classes [String] additional CSS classes for the button HTML
81
- # @param govuk_button_options [Hash] options that will be used in customising the HTML
82
- #
83
- # @option govuk_button_options [Boolean] :is_start_button indicates if it is a start button
84
- # @option govuk_button_options [Hash] :attributes any additional attributes that will added as part of the HTML
85
- #
86
- # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Button as a button element
87
- # which can then be rendered on the page
88
53
 
89
- def govuk_button_button(text, classes, **govuk_button_options)
90
- button_tag(class: classes, **govuk_button_options[:attributes]) do
91
- concat(text)
92
- concat(govuk_start_button_icon) if govuk_button_options[:is_start_button]
54
+ private
55
+
56
+ # Generates the HTML for the GOV.UK button component as an anchor tag.
57
+ # It is called by {#govuk_button} which will pass in the parameters, including any defaults.
58
+ #
59
+ # @param text [String] the text that will be shown in the button
60
+ # @param classes [String] additional CSS classes for the button HTML
61
+ # @param govuk_button_options [Hash] options that will be used in customising the HTML
62
+ #
63
+ # @option govuk_button_options [Boolean] :is_start_button indicates if it is a start button
64
+ # @option govuk_button_options [String] :href the URI that will be used in anchor tag
65
+ # @option govuk_button_options [Hash] :attributes any additional attributes that will added as part of the HTML
66
+ #
67
+ # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Button as an anchor element
68
+ # which can then be rendered on the page
69
+
70
+ def govuk_button_link(text, classes, **govuk_button_options)
71
+ link_to(govuk_button_options[:href], class: classes, role: :button, draggable: false, **govuk_button_options[:attributes]) do
72
+ concat(text)
73
+ concat(govuk_start_button_icon) if govuk_button_options[:is_start_button]
74
+ end
93
75
  end
94
- end
95
76
 
96
- # Generates the HTML for the GOV.UK button component as an input.
97
- # It is called by {#govuk_button} which will pass in the parameters, including any defaults.
98
- #
99
- # @param text [String] the text that will be shown in the input
100
- # @param classes [String] additional CSS classes for the button HTML
101
- # @param govuk_button_options [Hash] options that will be used in customising the HTML
102
- #
103
- # @option govuk_button_options [ActionView::Helpers::FormBuilder] :form the form builder used to create the submit button
104
- # @option govuk_button_options [Hash] :attributes any additional attributes that will added as part of the HTML
105
- #
106
- # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Button as an input element
107
- # which can then be rendered on the page
77
+ # Generates the HTML for the GOV.UK button component as a button.
78
+ # It is called by {#govuk_button} which will pass in the parameters, including any defaults.
79
+ #
80
+ # @param text [String] the text that will be shown in the button
81
+ # @param classes [String] additional CSS classes for the button HTML
82
+ # @param govuk_button_options [Hash] options that will be used in customising the HTML
83
+ #
84
+ # @option govuk_button_options [Boolean] :is_start_button indicates if it is a start button
85
+ # @option govuk_button_options [Hash] :attributes any additional attributes that will added as part of the HTML
86
+ #
87
+ # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Button as a button element
88
+ # which can then be rendered on the page
89
+
90
+ def govuk_button_button(text, classes, **govuk_button_options)
91
+ button_tag(class: classes, **govuk_button_options[:attributes]) do
92
+ concat(text)
93
+ concat(govuk_start_button_icon) if govuk_button_options[:is_start_button]
94
+ end
95
+ end
108
96
 
109
- def govuk_button_submit(text, classes, **govuk_button_options)
110
- govuk_button_options[:form].submit(text, class: classes, **govuk_button_options[:attributes])
111
- end
97
+ # Generates the HTML for the GOV.UK button component as an input.
98
+ # It is called by {#govuk_button} which will pass in the parameters, including any defaults.
99
+ #
100
+ # @param text [String] the text that will be shown in the input
101
+ # @param classes [String] additional CSS classes for the button HTML
102
+ # @param govuk_button_options [Hash] options that will be used in customising the HTML
103
+ #
104
+ # @option govuk_button_options [ActionView::Helpers::FormBuilder] :form the form builder used to create the submit button
105
+ # @option govuk_button_options [Hash] :attributes any additional attributes that will added as part of the HTML
106
+ #
107
+ # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Button as an input element
108
+ # which can then be rendered on the page
109
+
110
+ def govuk_button_submit(text, classes, **govuk_button_options)
111
+ govuk_button_options[:form].submit(text, class: classes, **govuk_button_options[:attributes])
112
+ end
112
113
 
113
- # Generates the arrow for the start button option as part of {#govuk_button}
114
- #
115
- # @return [ActiveSupport::SafeBuffer] the HTML for the arrow for the start button
114
+ # Generates the arrow for the start button option as part of {#govuk_button}
115
+ #
116
+ # @return [ActiveSupport::SafeBuffer] the HTML for the arrow for the start button
116
117
 
117
- def govuk_start_button_icon
118
- tag.svg(class: 'govuk-button__start-icon', xmlns: 'http://www.w3.org/2000/svg', width: 17.5, height: 19, viewBox: '0 0 33 40', aria: { hidden: true }, focusable: false) do
119
- tag.path(fill: 'currentColor', d: 'M0 0h13l20 20-20 20H0l20-20z')
118
+ def govuk_start_button_icon
119
+ tag.svg(class: 'govuk-button__start-icon', xmlns: 'http://www.w3.org/2000/svg', width: 17.5, height: 19, viewBox: '0 0 33 40', aria: { hidden: true }, focusable: false) do
120
+ tag.path(fill: 'currentColor', d: 'M0 0h13l20 20-20 20H0l20-20z')
121
+ end
120
122
  end
121
123
  end
122
124
  end
@@ -2,41 +2,43 @@
2
2
 
3
3
  require 'action_view'
4
4
 
5
- module CrownMarketplaceUtils::Helpers
6
- module GovUkHelper
7
- # = GOV.UK Details
8
- #
9
- # This helper is used for generating the details component from the
10
- # {https://design-system.service.gov.uk/components/details GDS - Components - Details}
5
+ module CrownMarketplaceUtils
6
+ module Helpers
7
+ module GovUkHelper
8
+ # = GOV.UK Details
9
+ #
10
+ # This helper is used for generating the details component from the
11
+ # {https://design-system.service.gov.uk/components/details GDS - Components - Details}
11
12
 
12
- module Details
13
- include ActionView::Context
14
- include ActionView::Helpers::TagHelper
15
- include ActionView::Helpers::TextHelper
13
+ module Details
14
+ include ActionView::Context
15
+ include ActionView::Helpers::TagHelper
16
+ include ActionView::Helpers::TextHelper
16
17
 
17
- # Generates the HTML for the GOV.UK Details component
18
- #
19
- # @param summary_text [String] the summary text for the details element
20
- # @param govuk_details_options [Hash] options that will be used in customising the HTML
21
- #
22
- # @option govuk_details_options [String] :classes additional CSS classes for the details HTML
23
- # @option govuk_details_options [Hash] :attributes ({ data: { module: 'govuk-details' } }) any additional attributes that will added as part of the HTML
24
- #
25
- # @yield HTML that will be contained within the 'govuk-details__text' div
26
- #
27
- # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Details
28
- # which can then be rendered on the page
18
+ # Generates the HTML for the GOV.UK Details component
19
+ #
20
+ # @param summary_text [String] the summary text for the details element
21
+ # @param govuk_details_options [Hash] options that will be used in customising the HTML
22
+ #
23
+ # @option govuk_details_options [String] :classes additional CSS classes for the details HTML
24
+ # @option govuk_details_options [Hash] :attributes ({ data: { module: 'govuk-details' } }) any additional attributes that will added as part of the HTML
25
+ #
26
+ # @yield HTML that will be contained within the 'govuk-details__text' div
27
+ #
28
+ # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Details
29
+ # which can then be rendered on the page
29
30
 
30
- def govuk_details(summary_text, **govuk_details_options, &block)
31
- govuk_details_classes = ['govuk-details']
32
- govuk_details_classes << govuk_details_options[:classes]
33
- govuk_details_options[:attributes] ||= {}
34
- (govuk_details_options[:attributes][:data] ||= {}).merge!({ module: 'govuk-details' })
31
+ def govuk_details(summary_text, **govuk_details_options, &block)
32
+ govuk_details_classes = ['govuk-details']
33
+ govuk_details_classes << govuk_details_options[:classes]
34
+ govuk_details_options[:attributes] ||= {}
35
+ (govuk_details_options[:attributes][:data] ||= {}).merge!({ module: 'govuk-details' })
35
36
 
36
- tag.details(class: govuk_details_classes, **govuk_details_options[:attributes]) do
37
- capture do
38
- concat(tag.summary(tag.span(summary_text, class: 'govuk-details__summary-text'), class: 'govuk-details__summary'))
39
- concat(tag.div(class: 'govuk-details__text', &block))
37
+ tag.details(class: govuk_details_classes, **govuk_details_options[:attributes]) do
38
+ capture do
39
+ concat(tag.summary(tag.span(summary_text, class: 'govuk-details__summary-text'), class: 'govuk-details__summary'))
40
+ concat(tag.div(class: 'govuk-details__text', &block))
41
+ end
40
42
  end
41
43
  end
42
44
  end
@@ -2,57 +2,59 @@
2
2
 
3
3
  require 'action_view'
4
4
 
5
- module CrownMarketplaceUtils::Helpers
6
- module GovUkHelper
7
- # = GOV.UK Error Message
8
- #
9
- # This helper is used for generating the error message component from the
10
- # {https://design-system.service.gov.uk/components/error-message GDS - Components - Error message}
11
-
12
- module ErrorMessage
13
- include ActionView::Context
14
- include ActionView::Helpers::TagHelper
15
- include ActionView::Helpers::TextHelper
16
-
17
- # Generates the HTML for the GOV.UK Error message component
5
+ module CrownMarketplaceUtils
6
+ module Helpers
7
+ module GovUkHelper
8
+ # = GOV.UK Error Message
18
9
  #
19
- # @param message [String] the message to be displayed
20
- # @param attribute [String, Symbol] the attribute that has an error
21
- # @param govuk_error_message_options [Hash] options that will be used in customising the HTML
22
- #
23
- # @option govuk_error_message_options [String] :classes additional CSS classes for the error message HTML
24
- # @option govuk_error_message_options [String] :visually_hidden_text ('Error') visualy hidden text before the error message
25
- # @option govuk_error_message_options [Hash] :attributes ({}) any additional attributes that will be added as part of the HTML
26
- #
27
- # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Error message
28
- # which can then be rendered on the page
29
-
30
- def govuk_error_message(message, attribute, **govuk_error_message_options)
31
- class_list = ['govuk-error-message']
32
- class_list << govuk_error_message_options[:classes]
33
- visually_hidden_text = govuk_error_message_options[:visually_hidden_text] || 'Error'
34
- govuk_error_message_options[:attributes] ||= {}
35
-
36
- tag.p(id: "#{attribute}-error", class: class_list, **govuk_error_message_options[:attributes]) do
37
- capture do
38
- concat(tag.span("#{visually_hidden_text}: ", class: 'govuk-visually-hidden')) if visually_hidden_text.present?
39
- concat(message)
10
+ # This helper is used for generating the error message component from the
11
+ # {https://design-system.service.gov.uk/components/error-message GDS - Components - Error message}
12
+
13
+ module ErrorMessage
14
+ include ActionView::Context
15
+ include ActionView::Helpers::TagHelper
16
+ include ActionView::Helpers::TextHelper
17
+
18
+ # Generates the HTML for the GOV.UK Error message component
19
+ #
20
+ # @param message [String] the message to be displayed
21
+ # @param attribute [String, Symbol] the attribute that has an error
22
+ # @param govuk_error_message_options [Hash] options that will be used in customising the HTML
23
+ #
24
+ # @option govuk_error_message_options [String] :classes additional CSS classes for the error message HTML
25
+ # @option govuk_error_message_options [String] :visually_hidden_text ('Error') visualy hidden text before the error message
26
+ # @option govuk_error_message_options [Hash] :attributes ({}) any additional attributes that will be added as part of the HTML
27
+ #
28
+ # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Error message
29
+ # which can then be rendered on the page
30
+
31
+ def govuk_error_message(message, attribute, **govuk_error_message_options)
32
+ class_list = ['govuk-error-message']
33
+ class_list << govuk_error_message_options[:classes]
34
+ visually_hidden_text = govuk_error_message_options[:visually_hidden_text] || 'Error'
35
+ govuk_error_message_options[:attributes] ||= {}
36
+
37
+ tag.p(id: "#{attribute}-error", class: class_list, **govuk_error_message_options[:attributes]) do
38
+ capture do
39
+ concat(tag.span("#{visually_hidden_text}: ", class: 'govuk-visually-hidden')) if visually_hidden_text.present?
40
+ concat(message)
41
+ end
40
42
  end
41
43
  end
42
- end
43
-
44
- # Generates the HTML for the GOV.UK Error message component using the error messages in an ActiveModel
45
- #
46
- # @param model [ActiveModel] model that will be used to find the error message
47
- # @param attribute [String, Symbol] the attribute that has an error
48
- # @param govuk_error_message_options [Hash] options that will be used in customising the HTML
49
- #
50
- # @option (see #govuk_error_message)
51
- #
52
- # @return (see #govuk_error_message)
53
44
 
54
- def govuk_error_message_with_model(model, attribute, **govuk_error_message_options)
55
- govuk_error_message(model.errors[attribute].first, attribute, **govuk_error_message_options)
45
+ # Generates the HTML for the GOV.UK Error message component using the error messages in an ActiveModel
46
+ #
47
+ # @param model [ActiveModel] model that will be used to find the error message
48
+ # @param attribute [String, Symbol] the attribute that has an error
49
+ # @param govuk_error_message_options [Hash] options that will be used in customising the HTML
50
+ #
51
+ # @option (see #govuk_error_message)
52
+ #
53
+ # @return (see #govuk_error_message)
54
+
55
+ def govuk_error_message_with_model(model, attribute, **govuk_error_message_options)
56
+ govuk_error_message(model.errors[attribute].first, attribute, **govuk_error_message_options)
57
+ end
56
58
  end
57
59
  end
58
60
  end