govuk_design_system_formbuilder 1.1.10 → 1.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d20300d83e65da38b6ae0b3a20a6e4e1bbdd9d04a9911ecf29829417abe5ba6f
4
- data.tar.gz: a62f856b0804bc22eacfabcf7c31166651cee64d2dee82d8454b92a693a4b553
3
+ metadata.gz: d9fcd048d44600ed48957b2c4d18d67a9d705878f897bc8206576f3a7ffebe37
4
+ data.tar.gz: 2958f99bb9a5d74432da272a4a7bae6563ec5c898626fcfe276e9385b0e860dc
5
5
  SHA512:
6
- metadata.gz: 586414dba6e14f1f4d8f16638b6634c1aedbadf600e4fbaf2ea67fd7bcae93cca3046a247187d08df5a609ceec318526f0effa4183fe8f903288f76926535e0a
7
- data.tar.gz: 323c190132caefde2e449f6b8f9088fdd13a58a520c166a17c43b35d53bc13c613c770b4fea82efc470ad5c90fdcf0e976226bc61811430ff1e301f5d8e1a66c
6
+ metadata.gz: 42f2696075a68ee286b0e8f45980247aabbbb5da7c64e57f90ef06858efce3ee2d80c551753aaa50c454567bdb1abbe1947a1c864639a7e5453f67c0799dd3f5
7
+ data.tar.gz: 7354580f9774a3b35e163c64e2531da89be06a1e1a8f6b535fcb38e215350953c20b5339ff9bf9cd6e8ac40dd25a2d505eacd51c0fc47d2baa5c384445c51ef3
@@ -24,6 +24,14 @@ module GOVUKDesignSystemFormBuilder
24
24
  # hint_text: 'It says it on your birth certificate',
25
25
  # required: true,
26
26
  # placeholder: 'Ralph Wiggum'
27
+ #
28
+ # @example A text field with injected content
29
+ # = f.govuk_text_field :pseudonym,
30
+ # label: { text: 'Pseudonym' } do
31
+ #
32
+ # p.govuk-inset-text
33
+ # | Ensure your stage name is unique
34
+ #
27
35
  def govuk_text_field(attribute_name, hint_text: nil, label: {}, width: nil, **args, &block)
28
36
  Elements::Inputs::Text.new(self, object_name, attribute_name, hint_text: hint_text, label: label, width: width, **args, &block).html
29
37
  end
@@ -51,6 +59,14 @@ module GOVUKDesignSystemFormBuilder
51
59
  # hint_text: 'Include the dialling code',
52
60
  # required: true,
53
61
  # placeholder: '0123 456 789'
62
+ #
63
+ # @example A phone field with injected content
64
+ # = f.govuk_phone_field :fax_number,
65
+ # label: { text: 'Fax number' } do
66
+ #
67
+ # p.govuk-inset-text
68
+ # | Yes, fax machines are still a thing
69
+ #
54
70
  def govuk_phone_field(attribute_name, hint_text: nil, label: {}, width: nil, **args, &block)
55
71
  Elements::Inputs::Phone.new(self, object_name, attribute_name, hint_text: hint_text, label: label, width: width, **args, &block).html
56
72
  end
@@ -76,6 +92,14 @@ module GOVUKDesignSystemFormBuilder
76
92
  # = f.govuk_email_field :email_address,
77
93
  # label: { text: 'Enter your email address' },
78
94
  # placeholder: 'ralph.wiggum@springfield.edu'
95
+ #
96
+ # @example A email field with injected content
97
+ # = f.govuk_phone_field :email_address,
98
+ # label: { text: 'Email address' } do
99
+ #
100
+ # p.govuk-inset-text
101
+ # | Use your work address
102
+ #
79
103
  def govuk_email_field(attribute_name, hint_text: nil, label: {}, width: nil, **args, &block)
80
104
  Elements::Inputs::Email.new(self, object_name, attribute_name, hint_text: hint_text, label: label, width: width, **args, &block).html
81
105
  end
@@ -100,6 +124,14 @@ module GOVUKDesignSystemFormBuilder
100
124
  # @example A password field
101
125
  # = f.govuk_password_field :password,
102
126
  # label: { text: 'Enter your password' }
127
+ #
128
+ # @example A password field with injected content
129
+ # = f.govuk_password_field :password,
130
+ # label: { text: 'Password' } do
131
+ #
132
+ # p.govuk-inset-text
133
+ # | Ensure your password is at least 16 characters long
134
+ #
103
135
  def govuk_password_field(attribute_name, hint_text: nil, label: {}, width: nil, **args, &block)
104
136
  Elements::Inputs::Password.new(self, object_name, attribute_name, hint_text: hint_text, label: label, width: width, **args, &block).html
105
137
  end
@@ -125,6 +157,14 @@ module GOVUKDesignSystemFormBuilder
125
157
  # label: { text: 'Enter your favourite website' },
126
158
  # placeholder: 'https://www.gov.uk',
127
159
  # autocomplete: 'url'
160
+ #
161
+ # @example A url field with injected content
162
+ # = f.govuk_url_field :personal_website,
163
+ # label: { text: 'Enter your website' } do
164
+ #
165
+ # p.govuk-inset-text
166
+ # | This will be visible on your profile
167
+ #
128
168
  def govuk_url_field(attribute_name, hint_text: nil, label: {}, width: nil, **args, &block)
129
169
  Elements::Inputs::URL.new(self, object_name, attribute_name, hint_text: hint_text, label: label, width: width, **args, &block).html
130
170
  end
@@ -152,6 +192,15 @@ module GOVUKDesignSystemFormBuilder
152
192
  # min: 80,
153
193
  # max: 150,
154
194
  # step: 5
195
+ #
196
+ # @example A number field with injected content
197
+ # = f.govuk_number_field :height_in_cm,
198
+ # label: { text: 'Height in centimetres' } do
199
+ #
200
+ # p.govuk-inset-text
201
+ # | If you haven't measured your height in the last 6 months
202
+ # do it now
203
+ #
155
204
  def govuk_number_field(attribute_name, hint_text: nil, label: {}, width: nil, **args, &block)
156
205
  Elements::Inputs::Number.new(self, object_name, attribute_name, hint_text: hint_text, label: label, width: width, **args, &block).html
157
206
  end
@@ -183,6 +232,14 @@ module GOVUKDesignSystemFormBuilder
183
232
  # label: { text: 'Tell us about your work history' },
184
233
  # rows: 8,
185
234
  # max_words: 300
235
+ #
236
+ # @example A text area with injected content
237
+ # = f.govuk_number_field :description,
238
+ # label: { text: 'Where did the incident take place?' } do
239
+ #
240
+ # p.govuk-inset-text
241
+ # | If you don't know exactly leave this section blank
242
+ #
186
243
  def govuk_text_area(attribute_name, hint_text: nil, label: {}, max_words: nil, max_chars: nil, rows: 5, threshold: nil, **args, &block)
187
244
  Elements::TextArea.new(self, object_name, attribute_name, hint_text: hint_text, label: label, max_words: max_words, max_chars: max_chars, rows: rows, threshold: threshold, **args, &block).html
188
245
  end
@@ -200,6 +257,22 @@ module GOVUKDesignSystemFormBuilder
200
257
  # @option label hidden [Boolean] control the visability of the label. Hidden labels will stil be read by screenreaders
201
258
  # @param block [Block] arbitrary HTML that will be rendered between the hint and the input
202
259
  # @return [ActiveSupport::SafeBuffer] HTML output
260
+ #
261
+ # @example A select box with hint
262
+ # = f.govuk_number_field :grade,
263
+ # @grades,
264
+ # :id,
265
+ # :name,
266
+ # hint_text: "If you took the test more than once enter your highest grade"
267
+ #
268
+ # @example A select box with injected content
269
+ # = f.govuk_number_field :favourite_colour,
270
+ # @colours,
271
+ # :id,
272
+ # :name do
273
+ #
274
+ # p.govuk-inset-text
275
+ # | Select the closest match
203
276
  def govuk_collection_select(attribute_name, collection, value_method, text_method, options: {}, html_options: {}, hint_text: nil, label: {}, &block)
204
277
  Elements::Select.new(
205
278
  self,
@@ -229,10 +302,12 @@ module GOVUKDesignSystemFormBuilder
229
302
  # @param collection [Enumerable<Object>] Options to be added to the +select+ element
230
303
  # @param value_method [Symbol, Proc] The method called against each member of the collection to provide the value.
231
304
  # When a +Proc+ is provided it must take a single argument that is a single member of the collection
232
- # @param text_method [Symbol, Proc] The method called against each member of the collection to provide the label text.
233
- # When a +Proc+ is provided it must take a single argument that is a single member of the collection
234
- # @param hint_method [Symbol, Proc] The method called against each member of the collection to provide the hint text.
235
- # When a +Proc+ is provided it must take a single argument that is a single member of the collection
305
+ # @param text_method [Symbol, Proc, nil] The method called against each member of the collection to provide the label text.
306
+ # When a +Proc+ is provided it must take a single argument that is a single member of the collection.
307
+ # When a +nil+ value is provided the label text will be retrieved from the locale.
308
+ # @param hint_method [Symbol, Proc, nil] The method called against each member of the collection to provide the hint text.
309
+ # When a +Proc+ is provided it must take a single argument that is a single member of the collection.
310
+ # When a +nil+ value is provided the hint text will be retrieved from the locale. This is the default and param can be omitted.
236
311
  # @param hint_text [String] The content of the fieldset hint. No hint will be injected if left +nil+
237
312
  # @param legend [Hash] options for configuring the legend
238
313
  # @param inline [Boolean] controls whether the radio buttons are displayed inline or not
@@ -241,7 +316,8 @@ module GOVUKDesignSystemFormBuilder
241
316
  # @param classes [String] Classes to add to the radio button container.
242
317
  # @option legend text [String] the fieldset legend's text content
243
318
  # @option legend size [String] the size of the fieldset legend font, can be +xl+, +l+, +m+ or +s+
244
- # @option legend tag [Symbol,String] the tag used for the fieldset's header, defaults to +h1+, defaults to +h1+
319
+ # @option legend tag [Symbol,String] the tag used for the fieldset's header, defaults to +h1+
320
+ # @option legend hidden [Boolean] control the visibility of the legend. Hidden legends will still be read by screenreaders
245
321
  # @return [ActiveSupport::SafeBuffer] HTML output
246
322
  #
247
323
  # @example A collection of radio buttons for favourite colours, labels capitalised via a proc
@@ -259,6 +335,15 @@ module GOVUKDesignSystemFormBuilder
259
335
  # legend: { text: 'Pick your favourite colour', size: 'm' },
260
336
  # hint_text: 'If you cannot find the exact match choose something close',
261
337
  # inline: false
338
+ #
339
+ # @example A collection of radio buttons for grades with injected content
340
+ # = f.govuk_collection_radio_buttons :favourite_colour,
341
+ # @grades,
342
+ # :id,
343
+ # :name do
344
+ #
345
+ # p.govuk-inset-text
346
+ # | If you took the test more than once enter your highest grade
262
347
  def govuk_collection_radio_buttons(attribute_name, collection, value_method, text_method, hint_method = nil, hint_text: nil, legend: {}, inline: false, small: false, bold_labels: false, classes: nil, &block)
263
348
  Elements::Radios::Collection.new(
264
349
  self,
@@ -290,6 +375,7 @@ module GOVUKDesignSystemFormBuilder
290
375
  # @option legend text [String] the fieldset legend's text content
291
376
  # @option legend size [String] the size of the fieldset legend font, can be +xl+, +l+, +m+ or +s+
292
377
  # @option legend tag [Symbol,String] the tag used for the fieldset's header, defaults to +h1+
378
+ # @option legend hidden [Boolean] control the visibility of the legend. Hidden legends will still be read by screenreaders
293
379
  # @param block [Block] a block of HTML that will be used to populate the fieldset
294
380
  # @param classes [String] Classes to add to the radio button container.
295
381
  # @see https://design-system.service.gov.uk/components/radios/ GOV.UK Radios
@@ -315,6 +401,7 @@ module GOVUKDesignSystemFormBuilder
315
401
  # @option legend text [String] the fieldset legend's text content
316
402
  # @option legend size [String] the size of the fieldset legend font, can be +xl+, +l+, +m+ or +s+
317
403
  # @option legend tag [Symbol,String] the tag used for the fieldset's header, defaults to +h1+
404
+ # @option legend hidden [Boolean] control the visibility of the legend. Hidden legends will still be read by screenreaders
318
405
  # @see https://design-system.service.gov.uk/components/radios/ GOV.UK Radios
319
406
  # @param block [Block] Any supplied HTML will be wrapped in a conditional
320
407
  # container and only revealed when the radio button is picked
@@ -325,7 +412,7 @@ module GOVUKDesignSystemFormBuilder
325
412
  # @example A collection of radio buttons for favourite colours with a divider
326
413
  #
327
414
  # = f.govuk_collection_radio_buttons :favourite_colour, inline: false do
328
- # = f.govuk_radio_button :favourite_colour, :red, label: { text: 'Red' } do
415
+ # = f.govuk_radio_button :favourite_colour, :red, label: { text: 'Red' }
329
416
  #
330
417
  def govuk_radio_button(attribute_name, value, hint_text: nil, label: {}, link_errors: false, &block)
331
418
  Elements::Radios::FieldsetRadioButton.new(self, object_name, attribute_name, value, hint_text: hint_text, label: label, link_errors: link_errors, &block).html
@@ -358,6 +445,7 @@ module GOVUKDesignSystemFormBuilder
358
445
  # @option legend text [String] the fieldset legend's text content
359
446
  # @option legend size [String] the size of the fieldset legend font, can be +xl+, +l+, +m+ or +s+
360
447
  # @option legend tag [Symbol,String] the tag used for the fieldset's header, defaults to +h1+
448
+ # @option legend hidden [Boolean] control the visibility of the legend. Hidden legends will still be read by screenreaders
361
449
  # @param block [Block] any HTML passed in will be injected into the fieldset, after the hint and before the checkboxes
362
450
  # @return [ActiveSupport::SafeBuffer] HTML output
363
451
  #
@@ -377,6 +465,15 @@ module GOVUKDesignSystemFormBuilder
377
465
  # hint_text: "If it isn't listed here, tough luck",
378
466
  # inline: false,
379
467
  # classes: 'app-overflow-scroll',
468
+ #
469
+ # @example A collection of check boxes for types of bread
470
+ # = f.govuk_collection_radio_buttons :bread,
471
+ # @variety,
472
+ # :id,
473
+ # :name do
474
+ #
475
+ # p.govuk-inset-text
476
+ # | Only Hearty Italian is available with the meal deal menu
380
477
  def govuk_collection_check_boxes(attribute_name, collection, value_method, text_method, hint_method = nil, hint_text: nil, legend: {}, small: false, classes: nil, &block)
381
478
  Elements::CheckBoxes::Collection.new(
382
479
  self,
@@ -403,6 +500,7 @@ module GOVUKDesignSystemFormBuilder
403
500
  # @option legend text [String] the fieldset legend's text content
404
501
  # @option legend size [String] the size of the fieldset legend font, can be +xl+, +l+, +m+ or +s+
405
502
  # @option legend tag [Symbol,String] the tag used for the fieldset's header, defaults to +h1+
503
+ # @option legend hidden [Boolean] control the visibility of the legend. Hidden legends will still be read by screenreaders
406
504
  # @param classes [String] Classes to add to the checkbox container.
407
505
  # @param block [Block] a block of HTML that will be used to populate the fieldset
408
506
  # @return [ActiveSupport::SafeBuffer] HTML output
@@ -469,6 +567,7 @@ module GOVUKDesignSystemFormBuilder
469
567
  # @param secondary [Boolean] makes the button grey ({https://design-system.service.gov.uk/components/button/#secondary-buttons secondary}) when true
470
568
  # @todo The GOV.UK design system also supports {https://design-system.service.gov.uk/components/button/#disabled-buttons disabled buttons}, they
471
569
  # should probably be supported too
570
+ # @param classes [String] Classes to add to the submit button
472
571
  # @param prevent_double_click [Boolean] adds JavaScript to safeguard the
473
572
  # form from being submitted more than once
474
573
  # @param validate [Boolean] adds the formnovalidate to the submit button when true, this disables all
@@ -488,8 +587,8 @@ module GOVUKDesignSystemFormBuilder
488
587
  # = f.govuk_submit "Proceed", prevent_double_click: true do
489
588
  # = link_to 'Cancel', some_other_path, class: 'govuk-button__secondary'
490
589
  #
491
- def govuk_submit(text = config.default_submit_button_text, warning: false, secondary: false, prevent_double_click: true, validate: false, &block)
492
- Elements::Submit.new(self, text, warning: warning, secondary: secondary, prevent_double_click: prevent_double_click, validate: validate, &block).html
590
+ def govuk_submit(text = config.default_submit_button_text, warning: false, secondary: false, classes: nil, prevent_double_click: true, validate: false, &block)
591
+ Elements::Submit.new(self, text, warning: warning, secondary: secondary, classes: classes, prevent_double_click: prevent_double_click, validate: validate, &block).html
493
592
  end
494
593
 
495
594
  # Generates three inputs for the +day+, +month+ and +year+ components of a date
@@ -503,6 +602,7 @@ module GOVUKDesignSystemFormBuilder
503
602
  # @option legend text [String] the fieldset legend's text content
504
603
  # @option legend size [String] the size of the fieldset legend font, can be +xl+, +l+, +m+ or +s+
505
604
  # @option legend tag [Symbol,String] the tag used for the fieldset's header, defaults to +h1+
605
+ # @option legend hidden [Boolean] control the visibility of the legend. Hidden legends will still be read by screenreaders
506
606
  # @param omit_day [Boolean] do not render a day input, only capture month and year
507
607
  # @param block [Block] arbitrary HTML that will be rendered between the hint and the input group
508
608
  # @param date_of_birth [Boolean] if +true+ {https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete#Values birth date auto completion attributes}
@@ -511,10 +611,14 @@ module GOVUKDesignSystemFormBuilder
511
611
  #
512
612
  # @see https://github.com/alphagov/govuk-frontend/issues/1449 GOV.UK date input element attributes, using text instead of number
513
613
  #
514
- # @example A regular date input with a legend and hint
614
+ # @example A regular date input with a legend, hint and injected content
515
615
  # = f.govuk_date_field :starts_on,
516
616
  # legend: { 'When does your event start?' },
517
- # hint_text: 'Leave this field blank if you don't know exactly' }
617
+ # hint_text: 'Leave this field blank if you don't know exactly' } do
618
+ #
619
+ # p.govuk-inset-text
620
+ # | If you don't fill this in you won't be eligable for a refund
621
+ #
518
622
  def govuk_date_field(attribute_name, hint_text: nil, legend: {}, date_of_birth: false, omit_day: false, &block)
519
623
  Elements::Date.new(self, object_name, attribute_name, hint_text: hint_text, legend: legend, date_of_birth: date_of_birth, omit_day: omit_day, &block).html
520
624
  end
@@ -545,6 +649,7 @@ module GOVUKDesignSystemFormBuilder
545
649
  # @option legend text [String] the fieldset legend's text content
546
650
  # @option legend size [String] the size of the fieldset legend font, can be +xl+, +l+, +m+ or +s+
547
651
  # @option legend tag [Symbol,String] the tag used for the fieldset's header, defaults to +h1+
652
+ # @option legend hidden [Boolean] control the visibility of the legend. Hidden legends will still be read by screenreaders
548
653
  #
549
654
  # @example A fieldset containing address fields
550
655
  # = f.govuk_fieldset legend: { text: 'Address' }
@@ -555,7 +660,7 @@ module GOVUKDesignSystemFormBuilder
555
660
  # @see https://design-system.service.gov.uk/components/fieldset/ GOV.UK fieldset
556
661
  # @return [ActiveSupport::SafeBuffer] HTML output
557
662
  def govuk_fieldset(legend: { text: 'Fieldset heading' }, described_by: nil, &block)
558
- Containers::Fieldset.new(self, legend: legend, described_by: described_by).html(&block)
663
+ Containers::Fieldset.new(self, legend: legend, described_by: described_by, &block).html
559
664
  end
560
665
 
561
666
  # Generates an input of type +file+
@@ -569,8 +674,11 @@ module GOVUKDesignSystemFormBuilder
569
674
  # @option args [Hash] args additional arguments are applied as attributes to +input+ element
570
675
  # @param block [Block] arbitrary HTML that will be rendered between the hint and the input
571
676
  #
572
- # @example A photo upload field with file type specifier
573
- # = f.govuk_file_field :photo, label: { text: 'Upload your photo' }, accept: 'image/*'
677
+ # @example A photo upload field with file type specifier and injected content
678
+ # = f.govuk_file_field :photo, label: { text: 'Upload your photo' }, accept: 'image/*' do
679
+ #
680
+ # p.govuk-inset-text
681
+ # | Explicit images will result in account termination
574
682
  #
575
683
  # @see https://design-system.service.gov.uk/components/file-upload/ GOV.UK file upload
576
684
  # @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file MDN documentation for file upload
@@ -5,8 +5,8 @@ module GOVUKDesignSystemFormBuilder
5
5
 
6
6
  LEGEND_SIZES = %w(xl l m s).freeze
7
7
 
8
- def initialize(builder, object_name = nil, attribute_name = nil, legend: {}, described_by: nil)
9
- super(builder, object_name, attribute_name)
8
+ def initialize(builder, object_name = nil, attribute_name = nil, legend: {}, described_by: nil, &block)
9
+ super(builder, object_name, attribute_name, &block)
10
10
 
11
11
  @legend = legend_defaults.merge(legend)
12
12
  @described_by = described_by(described_by)
@@ -15,7 +15,7 @@ module GOVUKDesignSystemFormBuilder
15
15
 
16
16
  def html
17
17
  content_tag('fieldset', class: fieldset_classes, aria: { describedby: @described_by }) do
18
- safe_join([build_legend, yield])
18
+ safe_join([build_legend, (@block_content || yield)])
19
19
  end
20
20
  end
21
21
 
@@ -23,6 +23,7 @@ module GOVUKDesignSystemFormBuilder
23
23
 
24
24
  def legend_defaults
25
25
  {
26
+ hidden: false,
26
27
  text: nil,
27
28
  tag: config.default_legend_tag,
28
29
  size: config.default_legend_size
@@ -49,7 +50,10 @@ module GOVUKDesignSystemFormBuilder
49
50
  size = @legend.dig(:size)
50
51
  fail "invalid size '#{size}', must be #{LEGEND_SIZES.join(', ')}" unless size.in?(LEGEND_SIZES)
51
52
 
52
- ["govuk-fieldset__legend", "govuk-fieldset__legend--#{size}"]
53
+ classes = %W(govuk-fieldset__legend govuk-fieldset__legend--#{size})
54
+ classes.push('govuk-visually-hidden') if @legend.dig(:hidden)
55
+
56
+ classes
53
57
  end
54
58
 
55
59
  def legend_heading_classes
@@ -38,7 +38,7 @@ module GOVUKDesignSystemFormBuilder
38
38
  end
39
39
 
40
40
  def hint_element
41
- @hint_element ||= Hint.new(@builder, @object_name, @attribute_name, @hint_text, value: @value)
41
+ @hint_element ||= Elements::Hint.new(@builder, @object_name, @attribute_name, @hint_text, @value, checkbox: true)
42
42
  end
43
43
  end
44
44
  end
@@ -2,6 +2,8 @@ module GOVUKDesignSystemFormBuilder
2
2
  module Elements
3
3
  module CheckBoxes
4
4
  class Label < Base
5
+ include Traits::Localisation
6
+
5
7
  def initialize(builder, object_name, attribute_name, checkbox, value:, link_errors: true)
6
8
  super(builder, object_name, attribute_name)
7
9
 
@@ -11,7 +13,9 @@ module GOVUKDesignSystemFormBuilder
11
13
  end
12
14
 
13
15
  def html
14
- @checkbox.label(for: field_id(link_errors: @link_errors), class: label_classes)
16
+ @checkbox.label(for: field_id(link_errors: @link_errors), class: label_classes) do
17
+ [localised_text(:label), @checkbox.text, @value].compact.first
18
+ end
15
19
  end
16
20
 
17
21
  private
@@ -105,11 +105,12 @@ module GOVUKDesignSystemFormBuilder
105
105
  end
106
106
 
107
107
  def date_attribute_name(segment)
108
- "%<object_name>s[%<attribute_name>s(%<segment>s)]" % {
108
+ format(
109
+ "%<object_name>s[%<attribute_name>s(%<segment>s)]",
109
110
  object_name: @object_name,
110
111
  attribute_name: @attribute_name,
111
112
  segment: SEGMENTS.fetch(segment)
112
- }
113
+ )
113
114
  end
114
115
 
115
116
  def date_of_birth_autocomplete_value(segment)
@@ -6,8 +6,8 @@ module GOVUKDesignSystemFormBuilder
6
6
  def initialize(builder, object_name, attribute_name, text: nil, value: nil, size: nil, hidden: false, radio: false, checkbox: false, tag: nil, link_errors: true)
7
7
  super(builder, object_name, attribute_name)
8
8
 
9
- @text = label_text(text, hidden)
10
9
  @value = value # used by field_id
10
+ @text = label_text(text, hidden)
11
11
  @size_class = label_size_class(size)
12
12
  @radio_class = radio_class(radio)
13
13
  @checkbox_class = checkbox_class(checkbox)
@@ -39,7 +39,7 @@ module GOVUKDesignSystemFormBuilder
39
39
  end
40
40
 
41
41
  def label_text(option_text, hidden)
42
- text = [option_text, @value, localised_text(:label), @attribute_name.capitalize].compact.first.to_s
42
+ text = [option_text, localised_text(:label), @attribute_name.capitalize].compact.first.to_s
43
43
 
44
44
  if hidden
45
45
  tag.span(text, class: %w(govuk-visually-hidden))
@@ -1,7 +1,7 @@
1
1
  module GOVUKDesignSystemFormBuilder
2
2
  module Elements
3
3
  class Submit < Base
4
- def initialize(builder, text, warning:, secondary:, prevent_double_click:, validate:, &block)
4
+ def initialize(builder, text, warning:, secondary:, classes:, prevent_double_click:, validate:, &block)
5
5
  fail ArgumentError, 'buttons can be warning or secondary' if warning && secondary
6
6
 
7
7
  @builder = builder
@@ -9,6 +9,7 @@ module GOVUKDesignSystemFormBuilder
9
9
  @prevent_double_click = prevent_double_click
10
10
  @warning = warning
11
11
  @secondary = secondary
12
+ @classes = classes
12
13
  @validate = validate
13
14
  @block_content = capture { block.call } if block_given?
14
15
  end
@@ -21,6 +22,7 @@ module GOVUKDesignSystemFormBuilder
21
22
  class: %w(govuk-button).push(
22
23
  warning_class,
23
24
  secondary_class,
25
+ @classes,
24
26
  padding_class(@block_content.present?)
25
27
  ).compact,
26
28
  **extra_args
@@ -51,7 +51,6 @@ module GOVUKDesignSystemFormBuilder
51
51
  return if @width.blank?
52
52
 
53
53
  case @width
54
- when nil then nil
55
54
 
56
55
  # fixed (character) widths
57
56
  when 20 then 'govuk-input--width-20'
@@ -4,28 +4,34 @@ module GOVUKDesignSystemFormBuilder
4
4
  private
5
5
 
6
6
  def localised_text(context)
7
- key = localisation_key(context)
7
+ return unless @object_name.present? && @attribute_name.present?
8
8
 
9
- # `I18n.exists?(nil)` returns true when `config.i18n.fallbacks` is
10
- # enabled, so only proceed if the key is present too
11
- return nil unless key.present? && I18n.exists?(key)
12
-
13
- I18n.translate(key)
9
+ localise(context) || localise_html(context)
14
10
  end
15
11
 
16
- def localisation_key(context)
17
- return nil unless @object_name.present? && @attribute_name.present?
12
+ def localise(context)
13
+ I18n.translate(schema(context), default: nil)
14
+ end
18
15
 
19
- schema(context)
16
+ def localise_html(context)
17
+ I18n.translate("#{schema(context)}_html", default: nil).try(:html_safe)
20
18
  end
21
19
 
22
20
  def schema(context)
23
21
  schema_root(context)
24
- .push(@object_name, @attribute_name)
22
+ .push(*schema_path)
25
23
  .map { |e| e == :__context__ ? context : e }
26
24
  .join('.')
27
25
  end
28
26
 
27
+ def schema_path
28
+ if @value.present?
29
+ [@object_name, "#{@attribute_name}_options", @value]
30
+ else
31
+ [@object_name, @attribute_name]
32
+ end
33
+ end
34
+
29
35
  def schema_root(context)
30
36
  contextual_schema = case context
31
37
  when :legend
@@ -1,3 +1,3 @@
1
1
  module GOVUKDesignSystemFormBuilder
2
- VERSION = '1.1.10'.freeze
2
+ VERSION = '1.1.11'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk_design_system_formbuilder
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.10
4
+ version: 1.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Yates
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-30 00:00:00.000000000 Z
11
+ date: 2020-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionview
@@ -56,16 +56,16 @@ dependencies:
56
56
  name: rubocop-govuk
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - '='
60
60
  - !ruby/object:Gem::Version
61
- version: '3.7'
61
+ version: 3.9.0
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - '='
67
67
  - !ruby/object:Gem::Version
68
- version: '3.7'
68
+ version: 3.9.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: pry
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -134,42 +134,14 @@ dependencies:
134
134
  requirements:
135
135
  - - "~>"
136
136
  - !ruby/object:Gem::Version
137
- version: '0'
138
- type: :development
139
- prerelease: false
140
- version_requirements: !ruby/object:Gem::Requirement
141
- requirements:
142
- - - "~>"
143
- - !ruby/object:Gem::Version
144
- version: '0'
145
- - !ruby/object:Gem::Dependency
146
- name: adsf
147
- requirement: !ruby/object:Gem::Requirement
148
- requirements:
149
- - - "~>"
150
- - !ruby/object:Gem::Version
151
- version: 1.4.2
152
- type: :development
153
- prerelease: false
154
- version_requirements: !ruby/object:Gem::Requirement
155
- requirements:
156
- - - "~>"
157
- - !ruby/object:Gem::Version
158
- version: 1.4.2
159
- - !ruby/object:Gem::Dependency
160
- name: adsf-live
161
- requirement: !ruby/object:Gem::Requirement
162
- requirements:
163
- - - "~>"
164
- - !ruby/object:Gem::Version
165
- version: 1.4.2
137
+ version: 0.17.1
166
138
  type: :development
167
139
  prerelease: false
168
140
  version_requirements: !ruby/object:Gem::Requirement
169
141
  requirements:
170
142
  - - "~>"
171
143
  - !ruby/object:Gem::Version
172
- version: 1.4.2
144
+ version: 0.17.1
173
145
  - !ruby/object:Gem::Dependency
174
146
  name: htmlbeautifier
175
147
  requirement: !ruby/object:Gem::Requirement
@@ -204,14 +176,14 @@ dependencies:
204
176
  requirements:
205
177
  - - "~>"
206
178
  - !ruby/object:Gem::Version
207
- version: 3.17.0
179
+ version: 3.18.0
208
180
  type: :development
209
181
  prerelease: false
210
182
  version_requirements: !ruby/object:Gem::Requirement
211
183
  requirements:
212
184
  - - "~>"
213
185
  - !ruby/object:Gem::Version
214
- version: 3.17.0
186
+ version: 3.18.0
215
187
  - !ruby/object:Gem::Dependency
216
188
  name: rubypants
217
189
  requirement: !ruby/object:Gem::Requirement
@@ -232,14 +204,14 @@ dependencies:
232
204
  requirements:
233
205
  - - "~>"
234
206
  - !ruby/object:Gem::Version
235
- version: 2.2.1
207
+ version: 2.3.0
236
208
  type: :development
237
209
  prerelease: false
238
210
  version_requirements: !ruby/object:Gem::Requirement
239
211
  requirements:
240
212
  - - "~>"
241
213
  - !ruby/object:Gem::Version
242
- version: 2.2.1
214
+ version: 2.3.0
243
215
  - !ruby/object:Gem::Dependency
244
216
  name: sass
245
217
  requirement: !ruby/object:Gem::Requirement
@@ -291,7 +263,6 @@ files:
291
263
  - lib/govuk_design_system_formbuilder/elements/check_boxes/collection.rb
292
264
  - lib/govuk_design_system_formbuilder/elements/check_boxes/collection_check_box.rb
293
265
  - lib/govuk_design_system_formbuilder/elements/check_boxes/fieldset_check_box.rb
294
- - lib/govuk_design_system_formbuilder/elements/check_boxes/hint.rb
295
266
  - lib/govuk_design_system_formbuilder/elements/check_boxes/label.rb
296
267
  - lib/govuk_design_system_formbuilder/elements/date.rb
297
268
  - lib/govuk_design_system_formbuilder/elements/error_message.rb
@@ -1,32 +0,0 @@
1
- module GOVUKDesignSystemFormBuilder
2
- module Elements
3
- module CheckBoxes
4
- class Hint < Base
5
- include Traits::Hint
6
-
7
- def initialize(builder, object_name, attribute_name, hint_text, value:)
8
- super(builder, object_name, attribute_name)
9
-
10
- @value = value
11
- @hint_text = hint_text
12
- end
13
-
14
- def html
15
- return nil if @hint_text.blank?
16
-
17
- tag.span(@hint_text, class: hint_classes, id: id)
18
- end
19
-
20
- def id
21
- hint_id
22
- end
23
-
24
- private
25
-
26
- def hint_classes
27
- %w(govuk-hint govuk-checkboxes__hint)
28
- end
29
- end
30
- end
31
- end
32
- end