crown_marketplace_utils 0.1.0.beta.1 → 0.1.0.beta.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +0 -1
- data/.rubocop.yml +14 -0
- data/Gemfile +0 -4
- data/Gemfile.lock +45 -29
- data/README.md +44 -1
- data/crown_marketplace_utils.gemspec +11 -8
- data/lib/crown_marketplace_utils/gov_uk_helper/breadcrumbs.rb +76 -0
- data/lib/crown_marketplace_utils/gov_uk_helper/button.rb +130 -0
- data/lib/crown_marketplace_utils/gov_uk_helper/details.rb +14 -8
- data/lib/crown_marketplace_utils/gov_uk_helper/error_message.rb +18 -11
- data/lib/crown_marketplace_utils/gov_uk_helper/field/character_count.rb +193 -0
- data/lib/crown_marketplace_utils/gov_uk_helper/field/checkboxes.rb +209 -0
- data/lib/crown_marketplace_utils/gov_uk_helper/field/input.rb +160 -0
- data/lib/crown_marketplace_utils/gov_uk_helper/field/radios.rb +205 -0
- data/lib/crown_marketplace_utils/gov_uk_helper/field/select.rb +166 -0
- data/lib/crown_marketplace_utils/gov_uk_helper/field/textarea.rb +127 -0
- data/lib/crown_marketplace_utils/gov_uk_helper/field.rb +263 -0
- data/lib/crown_marketplace_utils/gov_uk_helper/fieldset.rb +75 -0
- data/lib/crown_marketplace_utils/gov_uk_helper/form_group.rb +60 -0
- data/lib/crown_marketplace_utils/gov_uk_helper/header.rb +172 -0
- data/lib/crown_marketplace_utils/gov_uk_helper/hint.rb +12 -6
- data/lib/crown_marketplace_utils/gov_uk_helper/label.rb +97 -0
- data/lib/crown_marketplace_utils/gov_uk_helper/notification_banner.rb +139 -0
- data/lib/crown_marketplace_utils/gov_uk_helper/pagination.rb +214 -0
- data/lib/crown_marketplace_utils/gov_uk_helper/step_by_step_navigation.rb +225 -0
- data/lib/crown_marketplace_utils/gov_uk_helper/tag.rb +39 -0
- data/lib/crown_marketplace_utils/gov_uk_helper.rb +37 -2
- data/lib/crown_marketplace_utils/version.rb +1 -1
- data/lib/crown_marketplace_utils.rb +6 -1
- metadata +75 -31
- data/lib/crown_marketplace_utils/engine.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9bded690841ee7e1cbd50580542cbebe6ec6f1522dfa1ee4ef3da56028ada558
|
4
|
+
data.tar.gz: 6cddd1647d22f33db11fc6120bd2f789b908d686b0c16e5d344a7ccbf188b3c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 051dee5a663d6355aba6d171307b7ea9965413e15c7926efa164c4ff651b9f25fa8946c66cbaa2f0be4491facfbb8dbbf366363d33d348deb8eaa5ae431aa8db
|
7
|
+
data.tar.gz: 7d201bfd9d0a383bf3e5bf71402f428f6eda75bd88d17c669a1f1d0649ad5029d2400ed5626b26b9bf3ffffdadbf3ddeba9b6a65fdb8c09edc26cc0683952b5e
|
data/.rspec
CHANGED
data/.rubocop.yml
CHANGED
@@ -108,3 +108,17 @@ 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/**/*'
|
118
|
+
|
119
|
+
Rails/DynamicFindBy:
|
120
|
+
Whitelist:
|
121
|
+
- find_by_id
|
122
|
+
|
123
|
+
RSpec/MultipleExpectations:
|
124
|
+
Max: 3
|
data/Gemfile
CHANGED
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.
|
4
|
+
crown_marketplace_utils (0.1.0.beta.3)
|
5
|
+
actionview (>= 6.0)
|
5
6
|
|
6
7
|
GEM
|
7
8
|
remote: https://rubygems.org/
|
@@ -71,8 +72,19 @@ GEM
|
|
71
72
|
i18n (>= 1.6, < 2)
|
72
73
|
minitest (>= 5.1)
|
73
74
|
tzinfo (~> 2.0)
|
75
|
+
addressable (2.8.1)
|
76
|
+
public_suffix (>= 2.0.2, < 6.0)
|
74
77
|
ast (2.4.2)
|
75
78
|
builder (3.2.4)
|
79
|
+
capybara (3.38.0)
|
80
|
+
addressable
|
81
|
+
matrix
|
82
|
+
mini_mime (>= 0.1.3)
|
83
|
+
nokogiri (~> 1.8)
|
84
|
+
rack (>= 1.6.0)
|
85
|
+
rack-test (>= 0.6.3)
|
86
|
+
regexp_parser (>= 1.5, < 3.0)
|
87
|
+
xpath (~> 3.2)
|
76
88
|
concurrent-ruby (1.1.10)
|
77
89
|
crass (1.0.6)
|
78
90
|
diff-lcs (1.5.0)
|
@@ -88,6 +100,7 @@ GEM
|
|
88
100
|
mail (2.7.1)
|
89
101
|
mini_mime (>= 0.1.1)
|
90
102
|
marcel (1.0.2)
|
103
|
+
matrix (0.4.2)
|
91
104
|
method_source (1.0.0)
|
92
105
|
mini_mime (1.1.2)
|
93
106
|
minitest (5.16.3)
|
@@ -100,13 +113,14 @@ GEM
|
|
100
113
|
net-smtp (0.3.2)
|
101
114
|
net-protocol
|
102
115
|
nio4r (2.5.8)
|
103
|
-
nokogiri (1.13.
|
116
|
+
nokogiri (1.13.9-x86_64-darwin)
|
104
117
|
racc (~> 1.4)
|
105
|
-
nokogiri (1.13.
|
118
|
+
nokogiri (1.13.9-x86_64-linux)
|
106
119
|
racc (~> 1.4)
|
107
120
|
parallel (1.22.1)
|
108
121
|
parser (3.1.2.1)
|
109
122
|
ast (~> 2.4.1)
|
123
|
+
public_suffix (5.0.0)
|
110
124
|
racc (1.6.0)
|
111
125
|
rack (2.2.4)
|
112
126
|
rack-test (2.0.2)
|
@@ -139,40 +153,40 @@ GEM
|
|
139
153
|
zeitwerk (~> 2.5)
|
140
154
|
rainbow (3.1.1)
|
141
155
|
rake (13.0.6)
|
142
|
-
regexp_parser (2.6.
|
156
|
+
regexp_parser (2.6.1)
|
143
157
|
rexml (3.2.5)
|
144
|
-
rspec (3.
|
145
|
-
rspec-core (~> 3.
|
146
|
-
rspec-expectations (~> 3.
|
147
|
-
rspec-mocks (~> 3.
|
148
|
-
rspec-core (3.
|
149
|
-
rspec-support (~> 3.
|
150
|
-
rspec-expectations (3.
|
158
|
+
rspec (3.12.0)
|
159
|
+
rspec-core (~> 3.12.0)
|
160
|
+
rspec-expectations (~> 3.12.0)
|
161
|
+
rspec-mocks (~> 3.12.0)
|
162
|
+
rspec-core (3.12.0)
|
163
|
+
rspec-support (~> 3.12.0)
|
164
|
+
rspec-expectations (3.12.0)
|
151
165
|
diff-lcs (>= 1.2.0, < 2.0)
|
152
|
-
rspec-support (~> 3.
|
153
|
-
rspec-mocks (3.
|
166
|
+
rspec-support (~> 3.12.0)
|
167
|
+
rspec-mocks (3.12.0)
|
154
168
|
diff-lcs (>= 1.2.0, < 2.0)
|
155
|
-
rspec-support (~> 3.
|
156
|
-
rspec-support (3.
|
157
|
-
rubocop (1.
|
169
|
+
rspec-support (~> 3.12.0)
|
170
|
+
rspec-support (3.12.0)
|
171
|
+
rubocop (1.39.0)
|
158
172
|
json (~> 2.3)
|
159
173
|
parallel (~> 1.10)
|
160
174
|
parser (>= 3.1.2.1)
|
161
175
|
rainbow (>= 2.2.2, < 4.0)
|
162
176
|
regexp_parser (>= 1.8, < 3.0)
|
163
177
|
rexml (>= 3.2.5, < 4.0)
|
164
|
-
rubocop-ast (>= 1.
|
178
|
+
rubocop-ast (>= 1.23.0, < 2.0)
|
165
179
|
ruby-progressbar (~> 1.7)
|
166
180
|
unicode-display_width (>= 1.4.0, < 3.0)
|
167
|
-
rubocop-ast (1.
|
181
|
+
rubocop-ast (1.23.0)
|
168
182
|
parser (>= 3.1.1.0)
|
169
|
-
rubocop-rails (2.
|
183
|
+
rubocop-rails (2.17.3)
|
170
184
|
activesupport (>= 4.2.0)
|
171
185
|
rack (>= 1.1)
|
172
186
|
rubocop (>= 1.33.0, < 2.0)
|
173
187
|
rubocop-rake (0.6.0)
|
174
188
|
rubocop (~> 1.0)
|
175
|
-
rubocop-rspec (2.
|
189
|
+
rubocop-rspec (2.15.0)
|
176
190
|
rubocop (~> 1.33)
|
177
191
|
ruby-progressbar (1.11.0)
|
178
192
|
thor (1.2.1)
|
@@ -184,6 +198,8 @@ GEM
|
|
184
198
|
websocket-driver (0.7.5)
|
185
199
|
websocket-extensions (>= 0.1.0)
|
186
200
|
websocket-extensions (0.1.5)
|
201
|
+
xpath (3.2.0)
|
202
|
+
nokogiri (~> 1.8)
|
187
203
|
yard (0.9.28)
|
188
204
|
webrick (~> 1.7.0)
|
189
205
|
zeitwerk (2.6.1)
|
@@ -193,16 +209,16 @@ PLATFORMS
|
|
193
209
|
x86_64-linux
|
194
210
|
|
195
211
|
DEPENDENCIES
|
196
|
-
bundler
|
212
|
+
bundler (~> 2.3)
|
213
|
+
capybara (~> 3.38.0)
|
197
214
|
crown_marketplace_utils!
|
198
|
-
rails
|
199
|
-
|
200
|
-
|
201
|
-
rubocop
|
202
|
-
rubocop-
|
203
|
-
rubocop-
|
204
|
-
|
205
|
-
yard
|
215
|
+
rails (>= 6.0)
|
216
|
+
rspec (~> 3.12)
|
217
|
+
rubocop (~> 1.36)
|
218
|
+
rubocop-rails (~> 2.16)
|
219
|
+
rubocop-rake (~> 0.6)
|
220
|
+
rubocop-rspec (~> 2.13)
|
221
|
+
yard (~> 0.9)
|
206
222
|
|
207
223
|
BUNDLED WITH
|
208
224
|
2.3.12
|
data/README.md
CHANGED
@@ -20,9 +20,23 @@ If bundler is not being used to manage dependencies, install the gem by executin
|
|
20
20
|
|
21
21
|
## Usage
|
22
22
|
|
23
|
-
To use this gem, simply
|
23
|
+
To use this gem, simply add it to your Gemfile (as described above).
|
24
|
+
|
25
|
+
### GOV.UK Helper
|
26
|
+
|
27
|
+
To include the helper methods from the `GovUkHelper` module, you can include it in your `app/helpers/application_helper.rb` like so:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
module ApplicationHelper
|
31
|
+
include CrownMarketplaceUtils::GovUkHelper
|
32
|
+
end
|
33
|
+
```
|
34
|
+
|
35
|
+
This will give you access to a variety of [GDS components](https://design-system.service.gov.uk/components) to use in your application views.
|
36
|
+
These are based on the components found in [GOV.UK Frontend v4.3.1](https://github.com/alphagov/govuk-frontend/releases/tag/v4.3.1).
|
24
37
|
|
25
38
|
Documentation for the helper methods can be found at [LINK TO RDOCS](#)
|
39
|
+
|
26
40
|
## Development
|
27
41
|
|
28
42
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -33,6 +47,35 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
33
47
|
|
34
48
|
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
49
|
|
50
|
+
### Helpers to create
|
51
|
+
- ~~Breadcrumbs~~
|
52
|
+
- ~~Button~~
|
53
|
+
- ~~Checkboxes~~
|
54
|
+
- ~~CharacterCount~~
|
55
|
+
- DateInput
|
56
|
+
- ~~Details~~
|
57
|
+
- ~~ErrorMessage~~
|
58
|
+
- ~~Fieldset~~
|
59
|
+
- ~~FormGroup~~
|
60
|
+
- ~~Header~~
|
61
|
+
- ~~Hint~~
|
62
|
+
- ~~Label~~
|
63
|
+
- ~~NotificationBanner~~
|
64
|
+
- ~~Pagination~~
|
65
|
+
- ~~Radios~~
|
66
|
+
- ~~Select~~
|
67
|
+
- ~~StepByStepNavigation~~
|
68
|
+
- ~~TextArea~~
|
69
|
+
- ~~TextInput~~
|
70
|
+
- ~~Tag~~
|
71
|
+
|
72
|
+
### CCS Helpers to look at after first release
|
73
|
+
- Accordion
|
74
|
+
- CCS Panel
|
75
|
+
- CCS Header
|
76
|
+
- Conditioanl Checkboxes
|
77
|
+
- Conditioanl Radios
|
78
|
+
|
36
79
|
## Contributing
|
37
80
|
|
38
81
|
Bug reports and pull requests are welcome on GitHub at https://github.com/tim-s-ccs/crown_marketplace_utils.
|
@@ -33,14 +33,17 @@ 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.
|
37
|
-
|
38
|
-
spec.add_development_dependency '
|
39
|
-
spec.add_development_dependency '
|
40
|
-
spec.add_development_dependency '
|
41
|
-
spec.add_development_dependency '
|
42
|
-
spec.add_development_dependency 'rubocop
|
43
|
-
spec.add_development_dependency '
|
36
|
+
spec.add_dependency 'actionview', '>= 6.0'
|
37
|
+
|
38
|
+
spec.add_development_dependency 'bundler', '~> 2.3'
|
39
|
+
spec.add_development_dependency 'capybara', '~> 3.38.0'
|
40
|
+
spec.add_development_dependency 'rails', '>= 6.0'
|
41
|
+
spec.add_development_dependency 'rspec', '~> 3.12'
|
42
|
+
spec.add_development_dependency 'rubocop', '~> 1.36'
|
43
|
+
spec.add_development_dependency 'rubocop-rails', '~> 2.16'
|
44
|
+
spec.add_development_dependency 'rubocop-rake', '~> 0.6'
|
45
|
+
spec.add_development_dependency 'rubocop-rspec', '~> 2.13'
|
46
|
+
spec.add_development_dependency 'yard', '~> 0.9'
|
44
47
|
|
45
48
|
# For more information and examples about making a new gem, check out our
|
46
49
|
# guide at: https://bundler.io/guides/creating_gem.html
|
@@ -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
|
20
|
+
# @param govuk_details_options [Hash] options that will be used in customising the HTML
|
15
21
|
#
|
16
|
-
# @option
|
17
|
-
# @option
|
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
|
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, **
|
30
|
+
def govuk_details(summary_text, **govuk_details_options, &block)
|
25
31
|
govuk_details_classes = ['govuk-details']
|
26
|
-
govuk_details_classes <<
|
27
|
-
|
28
|
-
(
|
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, **
|
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
|
21
|
+
# @param govuk_error_message_options [Hash] options that will be used in customising the HTML
|
16
22
|
#
|
17
|
-
# @option
|
18
|
-
# @option
|
19
|
-
# @option
|
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
|
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, **
|
30
|
+
def govuk_error_message(message, attribute, **govuk_error_message_options)
|
25
31
|
class_list = ['govuk-error-message']
|
26
|
-
class_list <<
|
27
|
-
visually_hidden_text =
|
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, **
|
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
|
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, **
|
48
|
-
govuk_error_message(model.errors[attribute].first, attribute, **
|
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
|