crown_marketplace_utils 0.1.0.beta.1 → 0.1.0.beta.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 06b0933612954153f5c6a0a37d666db46ad61709d6ce33705790b3f2906101ec
4
- data.tar.gz: d8622845984e64cabf38557e3c0045cadf2265975c8a38a5bac6ab25ffd93119
3
+ metadata.gz: b6c289917a94a2f6ee322e356590757f9963509f1a6fa7951783a780e84d5fcf
4
+ data.tar.gz: 63639f4f2cf082ed69432dccdd0e41ced94dc909ec397d81550169229cf6ae06
5
5
  SHA512:
6
- metadata.gz: 34d668ad1d821617e5cd81d9d040e32d5d9e503eb0e68c55757ecf945a1b38e25a59c3c08fadb4d15dd3158b7a238b1e933066748f3b7f3e5801574bea4474de
7
- data.tar.gz: a5c067665e8af0370c960d7868af516aeb3b8d86453aa94c732841a6824d3cb32ed3d400be26e81608b643eff119f44b30b7a0fdb8d13c6715c59bcf00daa18f
6
+ metadata.gz: d5505418729cabf9849322dbbc8255c274063dca392c1cc5e3e9125db366811236efd120821b701f691fe32f28a94b19520f7a0425afb7d0bf6bc2c190025fe7
7
+ data.tar.gz: e243d5969928fbf7924d4b81206e77a5cfc6ce5e066aac4f7022f7495c8acc255ca0178ac43485ca4b2d7af285018b91925367f4655ab66069e49418c09a0d0f
data/.rspec CHANGED
@@ -1,3 +1,2 @@
1
- --format documentation
2
1
  --color
3
2
  --require spec_helper
data/.rubocop.yml CHANGED
@@ -108,3 +108,10 @@ Style/OptionalBooleanParameter:
108
108
 
109
109
  RSpec/VerifiedDoubleReference:
110
110
  Enabled: false
111
+
112
+ RSpec/NestedGroups:
113
+ Max: 5
114
+
115
+ RSpec/ExampleLength:
116
+ Exclude:
117
+ - 'spec/crown_marketplace_utils/gov_uk_helper/**/*'
data/Gemfile.lock CHANGED
@@ -1,7 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- crown_marketplace_utils (0.1.0.beta.1)
4
+ crown_marketplace_utils (0.1.0.beta.2)
5
+ actionview (>= 6.0)
5
6
 
6
7
  GEM
7
8
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -33,6 +33,26 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
33
33
 
34
34
  At the moment this Gem only contains view helpers. It would be good in the future to add other kinds of modules to this gem so that they can be shared and managed in one place.
35
35
 
36
+ ### Helpers to create
37
+ - Accordion
38
+ - ~~Breadcrumbs~~
39
+ - ~~Button~~
40
+ - Checkboxes
41
+ - CharacterCount
42
+ - DateInput
43
+ - ~~Details~~
44
+ - ~~ErrorMessage~~
45
+ - Fieldset
46
+ - ~~FormGroup~~
47
+ - Header
48
+ - ~~Hint~~
49
+ - NotificationBanner
50
+ - Pagination
51
+ - Radios
52
+ - Select
53
+ - StepByStepNavigation
54
+ - TextInput
55
+
36
56
  ## Contributing
37
57
 
38
58
  Bug reports and pull requests are welcome on GitHub at https://github.com/tim-s-ccs/crown_marketplace_utils.
@@ -33,6 +33,8 @@ Gem::Specification.new do |spec|
33
33
 
34
34
  # Uncomment to register a new dependency of your gem
35
35
  # spec.add_dependency "example-gem", "~> 1.0"
36
+ spec.add_dependency 'actionview', '>= 6.0'
37
+
36
38
  spec.add_development_dependency 'bundler'
37
39
  spec.add_development_dependency 'rails'
38
40
  spec.add_development_dependency 'rspec', '~> 3.2'
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'action_view'
4
+
5
+ module CrownMarketplaceUtils
6
+ module GovUkHelper
7
+ # = GOV.UK Breadcrumbs
8
+ #
9
+ # This helper is used for generating the breadcrumbs component from the
10
+ # {https://design-system.service.gov.uk/components/breadcrumbs GDS - Components - Breadcrumbs}
11
+
12
+ module Breadcrumbs
13
+ include ActionView::Context
14
+ include ActionView::Helpers::TagHelper
15
+ include ActionView::Helpers::TextHelper
16
+ include ActionView::Helpers::UrlHelper
17
+
18
+ # Generates the HTML for the GOV.UK breadcrumbs component
19
+ #
20
+ # @param govuk_breadcrumb_items [Array<Hash>] An array of links for the breadcrumbs list. See {#govuk_breadcrumb_link} for details of the items in the array.
21
+ # @param govuk_breadcrumbs_options [Hash] options that will be used in customising the HTML
22
+ #
23
+ # @option govuk_breadcrumbs_options [String] :classes additional CSS classes for the breadcrums HTML
24
+ # @option govuk_breadcrumbs_options [Boolean] :collapse_on_mobile indicates if it is to colapse breadcrumbs on mobile
25
+ # @option govuk_breadcrumbs_options [Hash] :attributes any additional attributes that will added as part of the HTML
26
+ #
27
+ # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Breadcrumbs
28
+ # which can then be rendered on the page
29
+
30
+ def govuk_breadcrumbs(govuk_breadcrumb_items, **govuk_breadcrumbs_options)
31
+ govuk_breadcrumbs_classes = ['govuk-breadcrumbs']
32
+ govuk_breadcrumbs_classes << govuk_breadcrumbs_options[:classes]
33
+ govuk_breadcrumbs_classes << 'govuk-breadcrumbs--collapse-on-mobile' if govuk_breadcrumbs_options[:collapse_on_mobile]
34
+ govuk_breadcrumbs_options[:attributes] ||= {}
35
+
36
+ tag.div(class: govuk_breadcrumbs_classes, **govuk_breadcrumbs_options[:attributes]) do
37
+ tag.ol(class: 'govuk-breadcrumbs__list') do
38
+ capture do
39
+ govuk_breadcrumb_items.each { |govuk_breadcrumb_item| concat(govuk_breadcrumb_link(govuk_breadcrumb_item)) }
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ private
46
+
47
+ # Generates the HTML for each link in the breadcrumbs.
48
+ # It is called by {#govuk_breadcrumbs} which will pass in the breadcrum item.
49
+ #
50
+ # @param govuk_breadcrumb_item [Hash] a hash containg options for the breadcrumb item
51
+ #
52
+ # @option govuk_breadcrumb_item [String] :text the text for the link
53
+ # @option govuk_breadcrumb_item [String] :link the URI for the link. If blank it is assumed that this item relates to current page
54
+ # @option govuk_breadcrumb_item [Hash] :attributes any additional attributes that will added as part of the HTML.
55
+ # If the link is blank then it defaults to +{ aria: { current: 'page' } }+
56
+ #
57
+ # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Breadcrumb list item
58
+
59
+ def govuk_breadcrumb_link(govuk_breadcrumb_item)
60
+ govuk_breadcrumb_item[:attributes] ||= {}
61
+
62
+ if govuk_breadcrumb_item[:link].present?
63
+ tag.li(class: 'govuk-breadcrumbs__list-item', **govuk_breadcrumb_item[:attributes]) do
64
+ link_to govuk_breadcrumb_item[:text], govuk_breadcrumb_item[:link], class: 'govuk-breadcrumbs__link'
65
+ end
66
+ else
67
+ (govuk_breadcrumb_item[:attributes][:aria] ||= {}).merge!({ current: 'page' })
68
+
69
+ tag.li(class: 'govuk-breadcrumbs__list-item', **govuk_breadcrumb_item[:attributes]) do
70
+ govuk_breadcrumb_item[:text]
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,130 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'action_view'
4
+
5
+ module CrownMarketplaceUtils
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
20
+ #
21
+ # @param text [String] the text that will be shown in the button
22
+ # @param type [Symbol] the type of button that will be created.
23
+ # - :a will create a anchor tag
24
+ # - :submit will create a input with type submit
25
+ # - all other values will create a button with the type specified
26
+ # @param govuk_button_options [Hash] options that will be used in customising the HTML
27
+ #
28
+ # @option govuk_button_options [String] :classes additional CSS classes for the button HTML
29
+ # @option govuk_button_options [Boolean] :is_start_button indicates if it is a start button
30
+ # @option govuk_button_options [String] :href the URI that will be used in anchor tag (only used if type is +:a+)
31
+ # @option govuk_button_options [ActionView::Helpers::FormBuilder] :form the form builder used to create the submit button (only used if type is +:submit+)
32
+ # @option govuk_button_options [Hash] :attributes ({ data: { module: 'govuk-button' } }) any additional attributes that will added as part of the HTML
33
+ #
34
+ # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Button
35
+ # which can then be rendered on the page
36
+
37
+ def govuk_button(text, type = :a, **govuk_button_options)
38
+ govuk_button_classes = ['govuk-button']
39
+ govuk_button_classes << govuk_button_options[:classes]
40
+ govuk_button_options[:attributes] ||= {}
41
+ govuk_button_classes << 'govuk-button--disabled' if govuk_button_options[:attributes][:disabled]
42
+ (govuk_button_options[:attributes][:data] ||= {}).merge!({ module: 'govuk-button' })
43
+
44
+ button_method = case type
45
+ when :a
46
+ :govuk_button_link
47
+ when :submit
48
+ :govuk_button_submit
49
+ else
50
+ :govuk_button_button
51
+ end
52
+
53
+ send(button_method, text, type, govuk_button_classes, **govuk_button_options)
54
+ end
55
+
56
+ private
57
+
58
+ # Generates the HTML for the GOV.UK button component as an anchor tag.
59
+ # It is called by {#govuk_button} which will pass in the parameters, including any defaults.
60
+ #
61
+ # @param text [String] the text that will be shown in the button
62
+ # @param _type [Symbol] unused as type has already been determined
63
+ # @param classes [String] additional CSS classes for the button HTML
64
+ # @param govuk_button_options [Hash] options that will be used in customising the HTML
65
+ #
66
+ # @option govuk_button_options [Boolean] :is_start_button indicates if it is a start button
67
+ # @option govuk_button_options [String] :href the URI that will be used in anchor tag
68
+ # @option govuk_button_options [Hash] :attributes any additional attributes that will added as part of the HTML
69
+ #
70
+ # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Button as an anchor element
71
+ # which can then be rendered on the page
72
+
73
+ def govuk_button_link(text, _type, classes, **govuk_button_options)
74
+ link_to(govuk_button_options[:href], class: classes, role: :button, draggable: false, **govuk_button_options[:attributes]) do
75
+ concat(text)
76
+ concat(govuk_start_button_icon) if govuk_button_options[:is_start_button]
77
+ end
78
+ end
79
+
80
+ # Generates the HTML for the GOV.UK button component as a button.
81
+ # It is called by {#govuk_button} which will pass in the parameters, including any defaults.
82
+ #
83
+ # @param text [String] the text that will be shown in the button
84
+ # @param type [Symbol] the type of attribute of the button
85
+ # @param classes [String] additional CSS classes for the button HTML
86
+ # @param govuk_button_options [Hash] options that will be used in customising the HTML
87
+ #
88
+ # @option govuk_button_options [Boolean] :is_start_button indicates if it is a start button
89
+ # @option govuk_button_options [Hash] :attributes any additional attributes that will added as part of the HTML
90
+ #
91
+ # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Button as a button element
92
+ # which can then be rendered on the page
93
+
94
+ def govuk_button_button(text, type, classes, **govuk_button_options)
95
+ button_tag(class: classes, type: type, **govuk_button_options[:attributes]) do
96
+ concat(text)
97
+ concat(govuk_start_button_icon) if govuk_button_options[:is_start_button]
98
+ end
99
+ end
100
+
101
+ # Generates the HTML for the GOV.UK button component as an input.
102
+ # It is called by {#govuk_button} which will pass in the parameters, including any defaults.
103
+ #
104
+ # @param text [String] the text that will be shown in the input
105
+ # @param _type [Symbol] unused as type has already been determined
106
+ # @param classes [String] additional CSS classes for the button HTML
107
+ # @param govuk_button_options [Hash] options that will be used in customising the HTML
108
+ #
109
+ # @option govuk_button_options [ActionView::Helpers::FormBuilder] :form the form builder used to create the submit button
110
+ # @option govuk_button_options [Hash] :attributes any additional attributes that will added as part of the HTML
111
+ #
112
+ # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Button as an input element
113
+ # which can then be rendered on the page
114
+
115
+ def govuk_button_submit(text, _type, classes, **govuk_button_options)
116
+ govuk_button_options[:form].submit(text, class: classes, **govuk_button_options[:attributes])
117
+ end
118
+
119
+ # Generates the arrow for the start button option as part of {#govuk_button}
120
+ #
121
+ # @return [ActiveSupport::SafeBuffer] the HTML for the arrow for the start button
122
+
123
+ def govuk_start_button_icon
124
+ 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
125
+ tag.path(fill: 'currentColor', d: 'M0 0h13l20 20-20 20H0l20-20z')
126
+ end
127
+ end
128
+ end
129
+ end
130
+ end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'action_view'
4
+
3
5
  module CrownMarketplaceUtils
4
6
  module GovUkHelper
5
7
  # = GOV.UK Details
@@ -8,26 +10,30 @@ module CrownMarketplaceUtils
8
10
  # {https://design-system.service.gov.uk/components/details GDS - Components - Details}
9
11
 
10
12
  module Details
13
+ include ActionView::Context
14
+ include ActionView::Helpers::TagHelper
15
+ include ActionView::Helpers::TextHelper
16
+
11
17
  # Generates the HTML for the GOV.UK Details component
12
18
  #
13
19
  # @param summary_text [String] the summary text for the details element
14
- # @param details_options [Hash] options that will be used in customising the HTML
20
+ # @param govuk_details_options [Hash] options that will be used in customising the HTML
15
21
  #
16
- # @option details_options [String] :classes additional CSS classes for the error message HTML
17
- # @option details_options [Hash] :attributes ({ data: { module: 'govuk-details' } }) any additional attributes that will added as part of the HTML
22
+ # @option govuk_details_options [String] :classes additional CSS classes for the error message HTML
23
+ # @option govuk_details_options [Hash] :attributes ({ data: { module: 'govuk-details' } }) any additional attributes that will added as part of the HTML
18
24
  #
19
25
  # @yield HTML that will be contained within the 'govuk-details__text' div
20
26
  #
21
27
  # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Details
22
28
  # which can then be rendered on the page
23
29
 
24
- def govuk_details(summary_text, **details_options, &block)
30
+ def govuk_details(summary_text, **govuk_details_options, &block)
25
31
  govuk_details_classes = ['govuk-details']
26
- govuk_details_classes << details_options[:classes]
27
- details_options[:attributes] ||= {}
28
- (details_options[:attributes][:data] ||= {}).merge!({ module: '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' })
29
35
 
30
- tag.details(class: govuk_details_classes, **details_options[:attributes]) do
36
+ tag.details(class: govuk_details_classes, **govuk_details_options[:attributes]) do
31
37
  capture do
32
38
  concat(tag.summary(tag.span(summary_text, class: 'govuk-details__summary-text'), class: 'govuk-details__summary'))
33
39
  concat(tag.div(class: 'govuk-details__text', &block))
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'action_view'
4
+
3
5
  module CrownMarketplaceUtils
4
6
  module GovUkHelper
5
7
  # = GOV.UK Error Message
@@ -8,25 +10,30 @@ module CrownMarketplaceUtils
8
10
  # {https://design-system.service.gov.uk/components/error-message GDS - Components - Error message}
9
11
 
10
12
  module ErrorMessage
13
+ include ActionView::Context
14
+ include ActionView::Helpers::TagHelper
15
+ include ActionView::Helpers::TextHelper
16
+
11
17
  # Generates the HTML for the GOV.UK Error message component
12
18
  #
13
19
  # @param message [String] the message to be displayed
14
20
  # @param attribute [String, Symbol] the attribute that has an error
15
- # @param error_message_options [Hash] options that will be used in customising the HTML
21
+ # @param govuk_error_message_options [Hash] options that will be used in customising the HTML
16
22
  #
17
- # @option error_message_options [String] :classes additional CSS classes for the error message HTML
18
- # @option error_message_options [String] :visually_hidden_text ('Error') visualy hidden text before the error message
19
- # @option error_message_options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
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 added as part of the HTML
20
26
  #
21
27
  # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Error message
22
28
  # which can then be rendered on the page
23
29
 
24
- def govuk_error_message(message, attribute, **error_message_options)
30
+ def govuk_error_message(message, attribute, **govuk_error_message_options)
25
31
  class_list = ['govuk-error-message']
26
- class_list << error_message_options[:classes]
27
- visually_hidden_text = error_message_options[:visually_hidden_text] || 'Error'
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] ||= {}
28
35
 
29
- tag.p(id: "#{attribute}-error", class: class_list, **(error_message_options[:attributes] || {})) do
36
+ tag.p(id: "#{attribute}-error", class: class_list, **govuk_error_message_options[:attributes]) do
30
37
  capture do
31
38
  concat(tag.span("#{visually_hidden_text}: ", class: 'govuk-visually-hidden')) if visually_hidden_text.present?
32
39
  concat(message)
@@ -38,14 +45,14 @@ module CrownMarketplaceUtils
38
45
  #
39
46
  # @param model [ActiveModel] model that will be used to find the error message
40
47
  # @param attribute [String, Symbol] the attribute that has an error
41
- # @param error_message_options [Hash] options that will be used in customising the HTML
48
+ # @param govuk_error_message_options [Hash] options that will be used in customising the HTML
42
49
  #
43
50
  # @option (see #govuk_error_message)
44
51
  #
45
52
  # @return (see #govuk_error_message)
46
53
 
47
- def govuk_error_message_with_model(model, attribute, **error_message_options)
48
- govuk_error_message(model.errors[attribute].first, attribute, **error_message_options)
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)
49
56
  end
50
57
  end
51
58
  end
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'action_view'
4
+ require_relative 'error_message'
5
+
6
+ module CrownMarketplaceUtils
7
+ module GovUkHelper
8
+ # = GOV.UK FormGroup
9
+ #
10
+ # This helper is used for generating the form group component from the Government Design Systems
11
+
12
+ module FormGroup
13
+ include ActionView::Context
14
+ include ActionView::Helpers::TagHelper
15
+ include ErrorMessage
16
+
17
+ # Generates the HTML for the GOV.UK Form Group component
18
+ #
19
+ # @param attribute [String, Symbol] the attribute that the form group is for
20
+ # @param error_message [String] the error message to be displayed
21
+ # @param govuk_form_group_options [Hash] options that will be used in customising the HTML
22
+ #
23
+ # @option govuk_form_group_options [String] :classes additional CSS classes for the form group HTML
24
+ # @option govuk_form_group_options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
25
+ #
26
+ # @yield HTML that will be contained within the 'govuk-form-group' div
27
+ #
28
+ # @yieldparam displayed_error_message [ActiveSupport::SafeBuffer] the HTML for the error message (if there is one)
29
+ #
30
+ # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Form Group
31
+ # which can then be rendered on the page
32
+
33
+ def govuk_form_group(attribute, error_message = nil, **govuk_form_group_options)
34
+ govuk_form_group_classes = ['govuk-form-group']
35
+ govuk_form_group_classes += ['govuk-form-group--error'] if error_message
36
+ govuk_form_group_classes << govuk_form_group_options[:classes]
37
+ govuk_form_group_options[:attributes] ||= {}
38
+
39
+ tag.div(class: govuk_form_group_classes, id: "#{attribute}-form-group", **govuk_form_group_options[:attributes]) do
40
+ yield((govuk_error_message(error_message, attribute) if error_message))
41
+ end
42
+ end
43
+
44
+ # Generates the HTML for the GOV.UK Form Group component using an ActiveModel
45
+ #
46
+ # @param model [ActiveModel] model that will be used to find an error message
47
+ # @param attribute [String, Symbol] the attribute that the form group is for
48
+ # @param govuk_form_group_options [Hash] options that will be used in customising the HTML
49
+ #
50
+ # @option (see #govuk_form_group)
51
+ #
52
+ # @yield (see #govuk_form_group)
53
+ #
54
+ # @yieldparam (see #govuk_form_group)
55
+ #
56
+ # @return (see #govuk_form_group)
57
+
58
+ def govuk_form_group_with_model(model, attribute, **govuk_form_group_options, &block)
59
+ govuk_form_group(attribute, model.errors[attribute].first, **govuk_form_group_options, &block)
60
+ end
61
+ end
62
+ end
63
+ end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'action_view'
4
+
3
5
  module CrownMarketplaceUtils
4
6
  module GovUkHelper
5
7
  # = GOV.UK Hint
@@ -7,22 +9,26 @@ module CrownMarketplaceUtils
7
9
  # This helper is used for generating the hint text component from the Government Design Systems
8
10
 
9
11
  module Hint
12
+ include ActionView::Context
13
+ include ActionView::Helpers::TagHelper
14
+
10
15
  # Generates the HTML for the GOV.UK Hint component
11
16
  #
12
17
  # @param hint_text [String] the hint text
13
- # @param hint_options [Hash] options that will be used in customising the HTML
18
+ # @param govuk_hint_options [Hash] options that will be used in customising the HTML
14
19
  #
15
- # @option hint_options [String] :classes additional CSS classes for the hint HTML
16
- # @option hint_options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
20
+ # @option govuk_hint_options [String] :classes additional CSS classes for the hint HTML
21
+ # @option govuk_hint_options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
17
22
  #
18
23
  # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Hint
19
24
  # which can then be rendered on the page
20
25
 
21
- def govuk_hint(hint_text, **hint_options)
26
+ def govuk_hint(hint_text, **govuk_hint_options)
22
27
  govuk_hint_classes = ['govuk-hint']
23
- govuk_hint_classes << hint_options[:classes]
28
+ govuk_hint_classes << govuk_hint_options[:classes]
29
+ govuk_hint_options[:attributes] ||= {}
24
30
 
25
- tag.div(hint_text, class: govuk_hint_classes, **(hint_options[:attributes] || {}))
31
+ tag.div(hint_text, class: govuk_hint_classes, **govuk_hint_options[:attributes])
26
32
  end
27
33
  end
28
34
  end
@@ -1,15 +1,22 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'gov_uk_helper/error_message'
3
+ require_relative 'gov_uk_helper/breadcrumbs'
4
+ require_relative 'gov_uk_helper/button'
4
5
  require_relative 'gov_uk_helper/details'
6
+ require_relative 'gov_uk_helper/error_message'
7
+ require_relative 'gov_uk_helper/form_group'
5
8
  require_relative 'gov_uk_helper/hint'
6
9
 
7
10
  module CrownMarketplaceUtils
8
- # This module loads in all the GOV.UK Helper methods
11
+ # This module loads in all the GOV.UK Helper methods.
12
+ # These are a collection of view helpers to help render GOV.UK components
9
13
 
10
14
  module GovUkHelper
15
+ include Breadcrumbs
16
+ include Button
11
17
  include Details
12
18
  include ErrorMessage
19
+ include FormGroup
13
20
  include Hint
14
21
  end
15
22
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CrownMarketplaceUtils
4
- VERSION = '0.1.0.beta.1'
4
+ VERSION = '0.1.0.beta.2'
5
5
  end
@@ -1,9 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'crown_marketplace_utils/gov_uk_helper'
4
- require 'crown_marketplace_utils/engine'
5
4
 
6
5
  require_relative 'crown_marketplace_utils/version'
7
6
 
7
+ # = Crown Marketplace Utilities
8
+ #
9
+ # The Crown Marketplace Utilities module contains code that is used in both Crown Marketplace projects.
10
+ # This includes:
11
+ # - view helpers to render GOV.UK components
12
+
8
13
  module CrownMarketplaceUtils
9
14
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crown_marketplace_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.beta.1
4
+ version: 0.1.0.beta.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - tim-s-ccs
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-10-19 00:00:00.000000000 Z
11
+ date: 2022-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: actionview
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '6.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '6.0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -140,10 +154,12 @@ files:
140
154
  - Rakefile
141
155
  - crown_marketplace_utils.gemspec
142
156
  - lib/crown_marketplace_utils.rb
143
- - lib/crown_marketplace_utils/engine.rb
144
157
  - lib/crown_marketplace_utils/gov_uk_helper.rb
158
+ - lib/crown_marketplace_utils/gov_uk_helper/breadcrumbs.rb
159
+ - lib/crown_marketplace_utils/gov_uk_helper/button.rb
145
160
  - lib/crown_marketplace_utils/gov_uk_helper/details.rb
146
161
  - lib/crown_marketplace_utils/gov_uk_helper/error_message.rb
162
+ - lib/crown_marketplace_utils/gov_uk_helper/form_group.rb
147
163
  - lib/crown_marketplace_utils/gov_uk_helper/hint.rb
148
164
  - lib/crown_marketplace_utils/version.rb
149
165
  - sig/crown_marketplace_utils.rbs
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rails/engine'
4
-
5
- module CrownMarketplaceUtils
6
- class Engine < ::Rails::Engine
7
- initializer 'crown_marketplace_utils.engine' do |_app|
8
- ActiveSupport.on_load(:action_view) { include CrownMarketplaceUtils::GovUkHelper }
9
- end
10
- end
11
- end