govuk_design_system_formbuilder 2.3.0b1 → 2.3.0

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.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/lib/govuk_design_system_formbuilder/base.rb +9 -0
  3. data/lib/govuk_design_system_formbuilder/builder.rb +0 -1
  4. data/lib/govuk_design_system_formbuilder/containers/check_boxes_fieldset.rb +2 -2
  5. data/lib/govuk_design_system_formbuilder/containers/fieldset.rb +1 -1
  6. data/lib/govuk_design_system_formbuilder/containers/radio_buttons_fieldset.rb +2 -2
  7. data/lib/govuk_design_system_formbuilder/containers/supplemental.rb +1 -1
  8. data/lib/govuk_design_system_formbuilder/elements/caption.rb +3 -3
  9. data/lib/govuk_design_system_formbuilder/elements/check_boxes/collection.rb +2 -2
  10. data/lib/govuk_design_system_formbuilder/elements/check_boxes/collection_check_box.rb +2 -2
  11. data/lib/govuk_design_system_formbuilder/elements/date.rb +4 -4
  12. data/lib/govuk_design_system_formbuilder/elements/error_message.rb +1 -1
  13. data/lib/govuk_design_system_formbuilder/elements/error_summary.rb +1 -1
  14. data/lib/govuk_design_system_formbuilder/elements/file.rb +1 -1
  15. data/lib/govuk_design_system_formbuilder/elements/hint.rb +1 -1
  16. data/lib/govuk_design_system_formbuilder/elements/label.rb +3 -3
  17. data/lib/govuk_design_system_formbuilder/elements/legend.rb +3 -5
  18. data/lib/govuk_design_system_formbuilder/elements/radios/collection.rb +3 -3
  19. data/lib/govuk_design_system_formbuilder/elements/radios/collection_radio_button.rb +2 -2
  20. data/lib/govuk_design_system_formbuilder/elements/select.rb +1 -1
  21. data/lib/govuk_design_system_formbuilder/elements/submit.rb +5 -5
  22. data/lib/govuk_design_system_formbuilder/elements/text_area.rb +3 -3
  23. data/lib/govuk_design_system_formbuilder/traits/caption.rb +1 -1
  24. data/lib/govuk_design_system_formbuilder/traits/error.rb +2 -2
  25. data/lib/govuk_design_system_formbuilder/traits/fieldset_item.rb +2 -2
  26. data/lib/govuk_design_system_formbuilder/traits/hint.rb +2 -2
  27. data/lib/govuk_design_system_formbuilder/traits/input.rb +4 -4
  28. data/lib/govuk_design_system_formbuilder/traits/label.rb +1 -1
  29. data/lib/govuk_design_system_formbuilder/traits/supplemental.rb +2 -2
  30. data/lib/govuk_design_system_formbuilder/version.rb +1 -1
  31. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 641fbc9fbd19bc333cd0872da36c9286c7f956cdfe41ef5b9b234dbe264bc03a
4
- data.tar.gz: 30a0000fa3868e7f7f6bf67347a025cf8f85e5e02a77bff4026d343088c3fb3f
3
+ metadata.gz: 2f56b92f232ffd2b98c38637c49b2e4255f3be12cab3825f795a735cbfae0107
4
+ data.tar.gz: 0f4dfd572130559b3140a838310ce471a4adee41f46fed32ca5046cfa29ed9d0
5
5
  SHA512:
6
- metadata.gz: 53d6df89df5401b05190709bbad01273d0a2491484792d82307a1ffd6a054ef9de69f8d7d5ab7ae028c677603628bf203439959e70c8e2776504172c41fc2939
7
- data.tar.gz: 5fa7f1475a37d063bab13dc27e4238ca6a7429abbe805b51436a6d3a1310c98df7defe60ad51ff376968d4ae8de8f828611daf79fc75a4602a6dbfeef3ae47f7
6
+ metadata.gz: 67861fee01f6a14cac7bbf9db87d1633dcf13e569aaa2179f5e16d21f8aed5e7b7d553a5bd96e601ab5b4181e6c27c905fa5fd6d7e80c811a2cff28d42b1f83f
7
+ data.tar.gz: a889d6d02fd1978e73aa2328debc5b6268993eca88755b3cf31889dfe4c973d28e09dfb9d13bbe462347aeea74a1f46dfb8ba8f4f7c20ad3da5c2c8d1d6aa114
@@ -25,6 +25,15 @@ module GOVUKDesignSystemFormBuilder
25
25
 
26
26
  private
27
27
 
28
+ # returns the attributes bound to the object that are
29
+ # required to build all contained elements
30
+ #
31
+ # @return [GOVUKDesignSystemFormBuilder::FormBuilder, Symbol, Symbol] an array containing the
32
+ # builder, object name and attribute name
33
+ def bound
34
+ [@builder, @object_name, @attribute_name]
35
+ end
36
+
28
37
  def brand(override = nil)
29
38
  override || config.brand
30
39
  end
@@ -387,7 +387,6 @@ module GOVUKDesignSystemFormBuilder
387
387
  # @option label hidden [Boolean] control the visability of the label. Hidden labels will stil be read by screenreaders
388
388
  # @option label kwargs [Hash] additional arguments are applied as attributes on the +label+ element
389
389
  # @param options [Hash] Options hash passed through to Rails' +collection_select+ helper
390
- # @param html_options [Hash] HTML Options hash passed through to Rails' +collection_select+ helper
391
390
  # @param form_group [Hash] configures the form group
392
391
  # @option form_group classes [Array,String] sets the form group's classes
393
392
  # @option form_group kwargs [Hash] additional attributes added to the form group
@@ -18,8 +18,8 @@ module GOVUKDesignSystemFormBuilder
18
18
  end
19
19
 
20
20
  def html
21
- Containers::FormGroup.new(@builder, @object_name, @attribute_name, **@form_group).html do
22
- Containers::Fieldset.new(@builder, @object_name, @attribute_name, **fieldset_options).html do
21
+ Containers::FormGroup.new(*bound, **@form_group).html do
22
+ Containers::Fieldset.new(*bound, **fieldset_options).html do
23
23
  safe_join([hint_element, error_element, hidden_field, checkboxes])
24
24
  end
25
25
  end
@@ -36,7 +36,7 @@ module GOVUKDesignSystemFormBuilder
36
36
  @legend_element ||= if @legend.nil?
37
37
  Elements::Null.new
38
38
  else
39
- Elements::Legend.new(@builder, @object_name, @attribute_name, **legend_options)
39
+ Elements::Legend.new(*bound, **legend_options)
40
40
  end
41
41
  end
42
42
 
@@ -18,8 +18,8 @@ module GOVUKDesignSystemFormBuilder
18
18
  end
19
19
 
20
20
  def html
21
- Containers::FormGroup.new(@builder, @object_name, @attribute_name, **@form_group).html do
22
- Containers::Fieldset.new(@builder, @object_name, @attribute_name, **fieldset_options).html do
21
+ Containers::FormGroup.new(*bound, **@form_group).html do
22
+ Containers::Fieldset.new(*bound, **fieldset_options).html do
23
23
  safe_join([hint_element, error_element, radios])
24
24
  end
25
25
  end
@@ -8,7 +8,7 @@ module GOVUKDesignSystemFormBuilder
8
8
  end
9
9
 
10
10
  def html
11
- return nil if @content.blank?
11
+ return if @content.blank?
12
12
 
13
13
  tag.div(id: supplemental_id) { @content }
14
14
  end
@@ -3,7 +3,7 @@ module GOVUKDesignSystemFormBuilder
3
3
  class Caption < Base
4
4
  include Traits::Localisation
5
5
 
6
- def initialize(builder, object_name, attribute_name, text: nil, size: nil, **kwargs)
6
+ def initialize(builder, object_name, attribute_name, text: nil, size: config.default_caption_size, **kwargs)
7
7
  super(builder, object_name, attribute_name)
8
8
 
9
9
  @text = text(text)
@@ -12,7 +12,7 @@ module GOVUKDesignSystemFormBuilder
12
12
  end
13
13
 
14
14
  def html
15
- return nil unless active?
15
+ return unless active?
16
16
 
17
17
  tag.span(@text, class: @size_class, **@html_attributes)
18
18
  end
@@ -28,7 +28,7 @@ module GOVUKDesignSystemFormBuilder
28
28
  end
29
29
 
30
30
  def size_class(size)
31
- case size || config.default_caption_size
31
+ case size
32
32
  when 'xl' then %(#{brand}-caption-xl)
33
33
  when 'l' then %(#{brand}-caption-l)
34
34
  when 'm' then %(#{brand}-caption-m)
@@ -23,8 +23,8 @@ module GOVUKDesignSystemFormBuilder
23
23
  end
24
24
 
25
25
  def html
26
- Containers::FormGroup.new(@builder, @object_name, @attribute_name, **@form_group).html do
27
- Containers::Fieldset.new(@builder, @object_name, @attribute_name, **fieldset_options).html do
26
+ Containers::FormGroup.new(*bound, **@form_group).html do
27
+ Containers::Fieldset.new(*bound, **fieldset_options).html do
28
28
  safe_join([supplemental_content, hint_element, error_element, check_boxes])
29
29
  end
30
30
  end
@@ -36,11 +36,11 @@ module GOVUKDesignSystemFormBuilder
36
36
  end
37
37
 
38
38
  def label_element
39
- @label_element ||= Label.new(@builder, @object_name, @attribute_name, @checkbox, value: @value, link_errors: @link_errors)
39
+ @label_element ||= Label.new(*bound, @checkbox, value: @value, link_errors: @link_errors)
40
40
  end
41
41
 
42
42
  def hint_element
43
- @hint_element ||= Elements::Hint.new(@builder, @object_name, @attribute_name, **hint_options, **hint_content)
43
+ @hint_element ||= Elements::Hint.new(*bound, **hint_options, **hint_content)
44
44
  end
45
45
 
46
46
  def hint_options
@@ -23,8 +23,8 @@ module GOVUKDesignSystemFormBuilder
23
23
  end
24
24
 
25
25
  def html
26
- Containers::FormGroup.new(@builder, @object_name, @attribute_name, **@form_group, **@html_attributes).html do
27
- Containers::Fieldset.new(@builder, @object_name, @attribute_name, **fieldset_options).html do
26
+ Containers::FormGroup.new(*bound, **@form_group, **@html_attributes).html do
27
+ Containers::Fieldset.new(*bound, **fieldset_options).html do
28
28
  safe_join([supplemental_content, hint_element, error_element, date])
29
29
  end
30
30
  end
@@ -47,7 +47,7 @@ module GOVUKDesignSystemFormBuilder
47
47
  end
48
48
 
49
49
  def day
50
- return nil if omit_day?
50
+ return if omit_day?
51
51
 
52
52
  date_part(:day, width: 2, link_errors: true)
53
53
  end
@@ -125,7 +125,7 @@ module GOVUKDesignSystemFormBuilder
125
125
  end
126
126
 
127
127
  def date_of_birth_autocomplete_value(segment)
128
- return nil unless @date_of_birth
128
+ return unless @date_of_birth
129
129
 
130
130
  { day: 'bday-day', month: 'bday-month', year: 'bday-year' }.fetch(segment)
131
131
  end
@@ -6,7 +6,7 @@ module GOVUKDesignSystemFormBuilder
6
6
  include Traits::Error
7
7
 
8
8
  def html
9
- return nil unless has_errors?
9
+ return unless has_errors?
10
10
 
11
11
  tag.span(class: %(#{brand}-error-message), id: error_id) do
12
12
  safe_join([hidden_prefix, message])
@@ -13,7 +13,7 @@ module GOVUKDesignSystemFormBuilder
13
13
  end
14
14
 
15
15
  def html
16
- return nil unless object_has_errors?
16
+ return unless object_has_errors?
17
17
 
18
18
  tag.div(**attributes(@html_attributes)) do
19
19
  safe_join([title, summary])
@@ -20,7 +20,7 @@ module GOVUKDesignSystemFormBuilder
20
20
  end
21
21
 
22
22
  def html
23
- Containers::FormGroup.new(@builder, @object_name, @attribute_name, **@form_group).html do
23
+ Containers::FormGroup.new(*bound, **@form_group).html do
24
24
  safe_join([label_element, supplemental_content, hint_element, error_element, file])
25
25
  end
26
26
  end
@@ -31,7 +31,7 @@ module GOVUKDesignSystemFormBuilder
31
31
  end
32
32
 
33
33
  def hint_id
34
- return nil unless active?
34
+ return unless active?
35
35
 
36
36
  build_id('hint')
37
37
  end
@@ -28,7 +28,7 @@ module GOVUKDesignSystemFormBuilder
28
28
  end
29
29
 
30
30
  def html
31
- return nil unless active?
31
+ return unless active?
32
32
 
33
33
  if @tag.present?
34
34
  content_tag(@tag, class: %(#{brand}-label-wrapper)) { label }
@@ -72,13 +72,13 @@ module GOVUKDesignSystemFormBuilder
72
72
  end
73
73
 
74
74
  def radio_class
75
- return nil unless @radio
75
+ return unless @radio
76
76
 
77
77
  %(#{brand}-radios__label)
78
78
  end
79
79
 
80
80
  def checkbox_class
81
- return nil unless @checkbox
81
+ return unless @checkbox
82
82
 
83
83
  %(#{brand}-checkboxes__label)
84
84
  end
@@ -39,11 +39,9 @@ module GOVUKDesignSystemFormBuilder
39
39
  def legend_content
40
40
  caption_and_text = safe_join([caption_element, @text])
41
41
 
42
- if @tag.present?
43
- content_tag(@tag, class: heading_classes) { caption_and_text }
44
- else
45
- caption_and_text
46
- end
42
+ return caption_and_text if @tag.blank?
43
+
44
+ content_tag(@tag, class: heading_classes) { caption_and_text }
47
45
  end
48
46
 
49
47
  def retrieve_text(supplied_text)
@@ -25,8 +25,8 @@ module GOVUKDesignSystemFormBuilder
25
25
  end
26
26
 
27
27
  def html
28
- Containers::FormGroup.new(@builder, @object_name, @attribute_name, **@form_group).html do
29
- Containers::Fieldset.new(@builder, @object_name, @attribute_name, **fieldset_options).html do
28
+ Containers::FormGroup.new(*bound, **@form_group).html do
29
+ Containers::Fieldset.new(*bound, **fieldset_options).html do
30
30
  safe_join([hidden_field, supplemental_content, hint_element, error_element, radios])
31
31
  end
32
32
  end
@@ -56,7 +56,7 @@ module GOVUKDesignSystemFormBuilder
56
56
 
57
57
  def collection
58
58
  @collection.map.with_index do |item, i|
59
- Elements::Radios::CollectionRadioButton.new(@builder, @object_name, @attribute_name, item, **collection_options(i)).html
59
+ Elements::Radios::CollectionRadioButton.new(*bound, item, **collection_options(i)).html
60
60
  end
61
61
  end
62
62
 
@@ -41,7 +41,7 @@ module GOVUKDesignSystemFormBuilder
41
41
  end
42
42
 
43
43
  def hint_element
44
- @hint_element ||= Elements::Hint.new(@builder, @object_name, @attribute_name, **hint_options, **hint_content)
44
+ @hint_element ||= Elements::Hint.new(*bound, **hint_options, **hint_content)
45
45
  end
46
46
 
47
47
  def hint_content
@@ -53,7 +53,7 @@ module GOVUKDesignSystemFormBuilder
53
53
  end
54
54
 
55
55
  def label_element
56
- @label_element ||= Elements::Label.new(@builder, @object_name, @attribute_name, **label_options)
56
+ @label_element ||= Elements::Label.new(*bound, **label_options)
57
57
  end
58
58
 
59
59
  def label_options
@@ -28,7 +28,7 @@ module GOVUKDesignSystemFormBuilder
28
28
  end
29
29
 
30
30
  def html
31
- Containers::FormGroup.new(@builder, @object_name, @attribute_name, **@form_group).html do
31
+ Containers::FormGroup.new(*bound, **@form_group).html do
32
32
  safe_join([label_element, supplemental_content, hint_element, error_element, select])
33
33
  end
34
34
  end
@@ -21,19 +21,19 @@ module GOVUKDesignSystemFormBuilder
21
21
  end
22
22
 
23
23
  def html
24
- @block_content.present? ? button_group : buttons
24
+ @block_content.present? ? button_group : submit
25
25
  end
26
26
 
27
27
  private
28
28
 
29
- def buttons
30
- safe_join([submit, @block_content])
31
- end
32
-
33
29
  def button_group
34
30
  Containers::ButtonGroup.new(@builder, buttons).html
35
31
  end
36
32
 
33
+ def buttons
34
+ safe_join([submit, @block_content])
35
+ end
36
+
37
37
  def submit
38
38
  @builder.submit(@text, **attributes(@html_attributes))
39
39
  end
@@ -25,7 +25,7 @@ module GOVUKDesignSystemFormBuilder
25
25
 
26
26
  def html
27
27
  Containers::CharacterCount.new(@builder, **character_count_options).html do
28
- Containers::FormGroup.new(@builder, @object_name, @attribute_name, **@form_group).html do
28
+ Containers::FormGroup.new(*bound, **@form_group).html do
29
29
  safe_join([label_element, supplemental_content, hint_element, error_element, text_area, limit_description])
30
30
  end
31
31
  end
@@ -78,7 +78,7 @@ module GOVUKDesignSystemFormBuilder
78
78
  end
79
79
 
80
80
  def limit_description
81
- return nil unless limit?
81
+ return unless limit?
82
82
 
83
83
  tag.span(id: limit_id, class: limit_description_classes, aria: { live: 'polite' }) do
84
84
  "You can enter up to #{limit_quantity} #{limit_type}"
@@ -90,7 +90,7 @@ module GOVUKDesignSystemFormBuilder
90
90
  end
91
91
 
92
92
  def limit_description_id
93
- return nil unless limit?
93
+ return unless limit?
94
94
 
95
95
  limit_id
96
96
  end
@@ -7,7 +7,7 @@ module GOVUKDesignSystemFormBuilder
7
7
  @caption_element ||= if @caption.nil?
8
8
  Elements::Null.new
9
9
  else
10
- Elements::Caption.new(@builder, @object_name, @attribute_name, **@caption)
10
+ Elements::Caption.new(*bound, **@caption)
11
11
  end
12
12
  end
13
13
  end
@@ -2,7 +2,7 @@ module GOVUKDesignSystemFormBuilder
2
2
  module Traits
3
3
  module Error
4
4
  def error_id
5
- return nil unless has_errors?
5
+ return unless has_errors?
6
6
 
7
7
  build_id('error')
8
8
  end
@@ -10,7 +10,7 @@ module GOVUKDesignSystemFormBuilder
10
10
  private
11
11
 
12
12
  def error_element
13
- @error_element ||= Elements::ErrorMessage.new(@builder, @object_name, @attribute_name)
13
+ @error_element ||= Elements::ErrorMessage.new(*bound)
14
14
  end
15
15
  end
16
16
  end
@@ -7,7 +7,7 @@ module GOVUKDesignSystemFormBuilder
7
7
  @label_element ||= if @label.nil?
8
8
  Elements::Null.new
9
9
  else
10
- Elements::Label.new(@builder, @object_name, @attribute_name, **label_content, **label_options)
10
+ Elements::Label.new(*bound, **label_content, **label_options)
11
11
  end
12
12
  end
13
13
 
@@ -19,7 +19,7 @@ module GOVUKDesignSystemFormBuilder
19
19
  @hint_element ||= if @hint.nil?
20
20
  Elements::Null.new
21
21
  else
22
- Elements::Hint.new(@builder, @object_name, @attribute_name, **hint_options, **hint_content)
22
+ Elements::Hint.new(*bound, **hint_options, **hint_content)
23
23
  end
24
24
  end
25
25
 
@@ -2,7 +2,7 @@ module GOVUKDesignSystemFormBuilder
2
2
  module Traits
3
3
  module Hint
4
4
  def hint_id
5
- return nil unless hint_element.active?
5
+ return unless hint_element.active?
6
6
 
7
7
  build_id('hint')
8
8
  end
@@ -13,7 +13,7 @@ module GOVUKDesignSystemFormBuilder
13
13
  @hint_element ||= if @hint.nil?
14
14
  Elements::Null.new
15
15
  else
16
- Elements::Hint.new(@builder, @object_name, @attribute_name, **hint_content)
16
+ Elements::Hint.new(*bound, **hint_content)
17
17
  end
18
18
  end
19
19
 
@@ -15,7 +15,7 @@ module GOVUKDesignSystemFormBuilder
15
15
  end
16
16
 
17
17
  def html
18
- Containers::FormGroup.new(@builder, @object_name, @attribute_name, **@form_group).html do
18
+ Containers::FormGroup.new(*bound, **@form_group).html do
19
19
  safe_join([label_element, supplemental_content, hint_element, error_element, content])
20
20
  end
21
21
  end
@@ -31,7 +31,7 @@ module GOVUKDesignSystemFormBuilder
31
31
  end
32
32
 
33
33
  def affixed_input
34
- content_tag('div', class: %(#{brand}-input__wrapper)) do
34
+ tag.div(class: %(#{brand}-input__wrapper)) do
35
35
  safe_join([prefix, input, suffix])
36
36
  end
37
37
  end
@@ -86,13 +86,13 @@ module GOVUKDesignSystemFormBuilder
86
86
  end
87
87
 
88
88
  def prefix
89
- return nil if @prefix_text.blank?
89
+ return if @prefix_text.blank?
90
90
 
91
91
  tag.span(@prefix_text, class: %(#{brand}-input__prefix), **affix_options)
92
92
  end
93
93
 
94
94
  def suffix
95
- return nil if @suffix_text.blank?
95
+ return if @suffix_text.blank?
96
96
 
97
97
  tag.span(@suffix_text, class: %(#{brand}-input__suffix), **affix_options)
98
98
  end
@@ -7,7 +7,7 @@ module GOVUKDesignSystemFormBuilder
7
7
  @label_element ||= if @label.nil?
8
8
  Elements::Null.new
9
9
  else
10
- Elements::Label.new(@builder, @object_name, @attribute_name, caption: @caption, **label_content)
10
+ Elements::Label.new(*bound, caption: @caption, **label_content)
11
11
  end
12
12
  end
13
13
 
@@ -2,7 +2,7 @@ module GOVUKDesignSystemFormBuilder
2
2
  module Traits
3
3
  module Supplemental
4
4
  def supplemental_id
5
- return nil if @block_content.blank?
5
+ return if @block_content.blank?
6
6
 
7
7
  build_id('supplemental')
8
8
  end
@@ -10,7 +10,7 @@ module GOVUKDesignSystemFormBuilder
10
10
  private
11
11
 
12
12
  def supplemental_content
13
- @supplemental_content ||= Containers::Supplemental.new(@builder, @object_name, @attribute_name, @block_content)
13
+ @supplemental_content ||= Containers::Supplemental.new(*bound, @block_content)
14
14
  end
15
15
  end
16
16
  end
@@ -1,3 +1,3 @@
1
1
  module GOVUKDesignSystemFormBuilder
2
- VERSION = '2.3.0b1'.freeze
2
+ VERSION = '2.3.0'.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: 2.3.0b1
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Yates
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-18 00:00:00.000000000 Z
11
+ date: 2021-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: deep_merge
@@ -347,9 +347,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
347
347
  version: '0'
348
348
  required_rubygems_version: !ruby/object:Gem::Requirement
349
349
  requirements:
350
- - - ">"
350
+ - - ">="
351
351
  - !ruby/object:Gem::Version
352
- version: 1.3.1
352
+ version: '0'
353
353
  requirements: []
354
354
  rubygems_version: 3.1.4
355
355
  signing_key: