govuk_design_system_formbuilder 2.1.5 → 2.1.8

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: f2892780c7524701d967f5ed6c409ad4eb741b5a3e6cfaf4ec65389dbaf504a4
4
- data.tar.gz: 5a231ba3dfebdf493b8563fc2d7c4b11ba66d27963512e24ef6cd9647ba8bee9
3
+ metadata.gz: 8c234131d78ff639d142f65d670b23876a8fb38eddea46a83e21aeb3d9f6daa2
4
+ data.tar.gz: 211981c7246de88afb294f72a06b6e0432f2e5f38f26449b43d7c5fc87f36c7e
5
5
  SHA512:
6
- metadata.gz: 46966873483f3cec59d97458b1e211ab013d7056c6d18e6bd40749f393e6e5eff96e93ddf38d6888da4316cd26db7d3a6dbd9e744e40d3fa6b2b4ac5386281b8
7
- data.tar.gz: cff65a82d937855335ef59346acb8d4e2a07e21ca615897c8dd9b0c873e2e919a794ac46dcfdde27054211f573c7be030d1b64a8b5fd1fa325f34ae1ecd8811d
6
+ metadata.gz: cd8d23e033c5ca4770b258c12b6ac59eca551da6c55838f5bf76ceeb98549ce8beb7ebd3c0c412942687aa60ad9596e96dc6324b783a262f3d02028bc5862298
7
+ data.tar.gz: 482d6efa88f4b02b305f51b5e897550e076390ccb69281d4ae533d043e9761b341078ec4f06943bf6f8582c37b906a5c902e84eeca4b6e42000ed3ba349878c8
data/README.md CHANGED
@@ -1,13 +1,15 @@
1
1
  # GOV.UK Design System Form Builder for Rails
2
2
 
3
- [![Tests](https://github.com/DFE-Digital/govuk_design_system_formbuilder/workflows/Testing/badge.svg)](https://github.com/DFE-Digital/govuk_design_system_formbuilder/actions)
3
+ [![Tests](https://github.com/DFE-Digital/govuk_design_system_formbuilder/workflows/Tests/badge.svg)](https://github.com/DFE-Digital/govuk_design_system_formbuilder/actions)
4
4
  [![Maintainability](https://api.codeclimate.com/v1/badges/fde73b5dc9476197281b/maintainability)](https://codeclimate.com/github/DFE-Digital/govuk_design_system_formbuilder/maintainability)
5
5
  [![Gem Version](https://badge.fury.io/rb/govuk_design_system_formbuilder.svg)](https://badge.fury.io/rb/govuk_design_system_formbuilder)
6
6
  [![Gem](https://img.shields.io/gem/dt/govuk_design_system_formbuilder?logo=rubygems)](https://rubygems.org/gems/govuk_design_system_formbuilder)
7
7
  [![Test Coverage](https://api.codeclimate.com/v1/badges/fde73b5dc9476197281b/test_coverage)](https://codeclimate.com/github/DFE-Digital/govuk_design_system_formbuilder/test_coverage)
8
8
  [![Dependabot Status](https://api.dependabot.com/badges/status?host=github&repo=DFE-Digital/govuk_design_system_formbuilder)](https://dependabot.com)
9
9
  [![GitHub license](https://img.shields.io/github/license/DFE-Digital/govuk_design_system_formbuilder)](https://github.com/DFE-Digital/govuk_design_system_formbuilder/blob/master/LICENSE)
10
- [![GOV.UK Design System Version](https://img.shields.io/badge/GOV.UK%20Design%20System-3.9.1-brightgreen)](https://design-system.service.gov.uk)
10
+ [![GOV.UK Design System Version](https://img.shields.io/badge/GOV.UK%20Design%20System-3.11.0-brightgreen)](https://design-system.service.gov.uk)
11
+ [![Rails](https://img.shields.io/badge/Ruby-2.5.8%20%E2%95%B1%202.6.6%20%E2%95%B1%202.7.2-E16D6D)](https://weblog.rubyonrails.org/releases/)
12
+ [![Ruby](https://img.shields.io/badge/Rails-5.2.4%20%E2%95%B1%206.0.3%20%E2%95%B1%206.1.0-E16D6D)](https://www.ruby-lang.org/en/downloads/)
11
13
 
12
14
  This library provides an easy-to-use form builder for the [GOV.UK Design System](https://design-system.service.gov.uk/).
13
15
 
@@ -53,7 +53,7 @@ module GOVUKDesignSystemFormBuilder
53
53
  def has_errors?
54
54
  @builder.object.respond_to?(:errors) &&
55
55
  @builder.object.errors.any? &&
56
- @builder.object.errors.messages.dig(@attribute_name).present?
56
+ @builder.object.errors.messages[@attribute_name].present?
57
57
  end
58
58
 
59
59
  def described_by(*ids)
@@ -456,6 +456,7 @@ module GOVUKDesignSystemFormBuilder
456
456
  # @param inline [Boolean] controls whether the radio buttons are displayed inline or not
457
457
  # @param small [Boolean] controls whether small radio buttons are used instead of regular-sized ones
458
458
  # @param bold_labels [Boolean] controls whether the radio button labels are bold
459
+ # @param include_hidden [Boolean] controls whether a hidden field is inserted to allow for empty submissions
459
460
  # @param classes [Array,String] Classes to add to the radio button container.
460
461
  # @option legend text [String] the fieldset legend's text content
461
462
  # @option legend size [String] the size of the fieldset legend font, can be +xl+, +l+, +m+ or +s+
@@ -500,7 +501,7 @@ module GOVUKDesignSystemFormBuilder
500
501
  # :name,
501
502
  # legend: -> { tag.h3('Which category do you belong to?') }
502
503
  #
503
- def govuk_collection_radio_buttons(attribute_name, collection, value_method, text_method = nil, hint_method = nil, hint: {}, legend: {}, caption: {}, inline: false, small: false, bold_labels: false, classes: nil, form_group: {}, &block)
504
+ def govuk_collection_radio_buttons(attribute_name, collection, value_method, text_method = nil, hint_method = nil, hint: {}, legend: {}, caption: {}, inline: false, small: false, bold_labels: false, classes: nil, include_hidden: false, form_group: {}, &block)
504
505
  Elements::Radios::Collection.new(
505
506
  self,
506
507
  object_name,
@@ -517,6 +518,7 @@ module GOVUKDesignSystemFormBuilder
517
518
  bold_labels: bold_labels,
518
519
  classes: classes,
519
520
  form_group: form_group,
521
+ include_hidden: include_hidden,
520
522
  &block
521
523
  ).html
522
524
  end
@@ -809,9 +811,9 @@ module GOVUKDesignSystemFormBuilder
809
811
  # client-side validation provided by the browser. This is to provide a more consistent and accessible user
810
812
  # experience
811
813
  # @param disabled [Boolean] makes the button disabled when true
812
- # @param block [Block] Any supplied HTML will be inserted immediately after
813
- # the submit button. It is intended for other buttons directly related to
814
- # the form's operation, such as 'Cancel' or 'Safe draft'
814
+ # @param block [Block] When content is passed in via a block the submit element and the block content will
815
+ # be wrapped in a +<div class="govuk-button-group">+ which will space the buttons and links within
816
+ # evenly.
815
817
  # @raise [ArgumentError] raised if both +warning+ and +secondary+ are true
816
818
  # @return [ActiveSupport::SafeBuffer] HTML output
817
819
  # @note Only the first additional button or link (passed in via a block) will be given the
@@ -850,7 +852,7 @@ module GOVUKDesignSystemFormBuilder
850
852
  # @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
851
853
  # @option caption kwargs [Hash] additional arguments are applied as attributes on the caption +span+ element
852
854
  # @param omit_day [Boolean] do not render a day input, only capture month and year
853
- # @param wildcards [Boolean] add an 'X' to the date wildcards so users can add approximate dates
855
+ # @param wildcards [Boolean] add an 'X' to the day and month patterns so users can add approximate dates
854
856
  # @param form_group [Hash] configures the form group
855
857
  # @option form_group classes [Array,String] sets the form group's classes
856
858
  # @option form_group kwargs [Hash] additional attributes added to the form group
@@ -0,0 +1,15 @@
1
+ module GOVUKDesignSystemFormBuilder
2
+ module Containers
3
+ class ButtonGroup < Base
4
+ def initialize(builder, buttons)
5
+ super(builder, nil, nil)
6
+
7
+ @buttons = buttons
8
+ end
9
+
10
+ def html
11
+ tag.div(@buttons, class: %(#{brand}-button-group))
12
+ end
13
+ end
14
+ end
15
+ end
@@ -2,7 +2,7 @@ module GOVUKDesignSystemFormBuilder
2
2
  module Containers
3
3
  class CharacterCount < Base
4
4
  def initialize(builder, max_words:, max_chars:, threshold:)
5
- @builder = builder
5
+ super(builder, nil, nil)
6
6
 
7
7
  fail ArgumentError, 'limit can be words or chars' if max_words && max_chars
8
8
 
@@ -11,10 +11,10 @@ module GOVUKDesignSystemFormBuilder
11
11
  @threshold = threshold
12
12
  end
13
13
 
14
- def html
14
+ def html(&block)
15
15
  return yield unless limit?
16
16
 
17
- tag.div(**options) { yield }
17
+ tag.div(**options, &block)
18
18
  end
19
19
 
20
20
  private
@@ -2,13 +2,14 @@ module GOVUKDesignSystemFormBuilder
2
2
  module Containers
3
3
  class CheckBoxes < Base
4
4
  def initialize(builder, small:, classes: nil)
5
- @builder = builder
5
+ super(builder, nil, nil)
6
+
6
7
  @small = small
7
8
  @classes = classes
8
9
  end
9
10
 
10
- def html
11
- tag.div(**options) { yield }
11
+ def html(&block)
12
+ tag.div(**options, &block)
12
13
  end
13
14
 
14
15
  private
@@ -8,8 +8,8 @@ module GOVUKDesignSystemFormBuilder
8
8
  @html_attributes = kwargs
9
9
  end
10
10
 
11
- def html
12
- tag.div(class: classes, **@html_attributes) { yield }
11
+ def html(&block)
12
+ tag.div(class: classes, **@html_attributes, &block)
13
13
  end
14
14
 
15
15
  private
@@ -4,14 +4,15 @@ module GOVUKDesignSystemFormBuilder
4
4
  include Traits::Hint
5
5
 
6
6
  def initialize(builder, inline:, small:, classes:)
7
- @builder = builder
7
+ super(builder, nil, nil)
8
+
8
9
  @inline = inline
9
10
  @small = small
10
11
  @classes = classes
11
12
  end
12
13
 
13
- def html
14
- tag.div(**options) { yield }
14
+ def html(&block)
15
+ tag.div(**options, &block)
15
16
  end
16
17
 
17
18
  private
@@ -6,7 +6,7 @@ module GOVUKDesignSystemFormBuilder
6
6
  include Traits::Hint
7
7
  include Traits::Supplemental
8
8
 
9
- def initialize(builder, object_name, attribute_name, collection, value_method:, text_method:, hint_method: nil, hint:, legend:, caption:, small:, classes:, form_group:, &block)
9
+ def initialize(builder, object_name, attribute_name, collection, value_method:, text_method:, hint:, legend:, caption:, small:, classes:, form_group:, hint_method: nil, &block)
10
10
  super(builder, object_name, attribute_name, &block)
11
11
 
12
12
  @collection = collection
@@ -16,7 +16,7 @@ module GOVUKDesignSystemFormBuilder
16
16
 
17
17
  def html
18
18
  @checkbox.label(for: field_id(link_errors: @link_errors), class: label_classes) do
19
- [localised_text(:label), @checkbox.text, @value].compact.first
19
+ [localised_text(:label), @checkbox.text, @value].compact.first.to_s
20
20
  end
21
21
  end
22
22
 
@@ -9,7 +9,7 @@ module GOVUKDesignSystemFormBuilder
9
9
 
10
10
  SEGMENTS = { day: '3i', month: '2i', year: '1i' }.freeze
11
11
 
12
- def initialize(builder, object_name, attribute_name, legend:, caption:, hint:, date_of_birth: false, omit_day:, form_group:, wildcards:, &block)
12
+ def initialize(builder, object_name, attribute_name, legend:, caption:, hint:, omit_day:, form_group:, wildcards:, date_of_birth: false, &block)
13
13
  super(builder, object_name, attribute_name, &block)
14
14
 
15
15
  @legend = legend
@@ -5,10 +5,6 @@ module GOVUKDesignSystemFormBuilder
5
5
 
6
6
  include Traits::Error
7
7
 
8
- def initialize(builder, object_name, attribute_name)
9
- super(builder, object_name, attribute_name)
10
- end
11
-
12
8
  def html
13
9
  return nil unless has_errors?
14
10
 
@@ -4,8 +4,8 @@ module GOVUKDesignSystemFormBuilder
4
4
  include Traits::Error
5
5
 
6
6
  def initialize(builder, object_name, title, link_base_errors_to:)
7
- @builder = builder
8
- @object_name = object_name
7
+ super(builder, object_name, nil)
8
+
9
9
  @title = title
10
10
  @link_base_errors_to = link_base_errors_to
11
11
  end
@@ -1,7 +1,9 @@
1
1
  module GOVUKDesignSystemFormBuilder
2
2
  module Elements
3
3
  class Null < Base
4
- def initialize; end
4
+ def initialize
5
+ super(nil, nil, nil)
6
+ end
5
7
 
6
8
  def html
7
9
  nil
@@ -6,27 +6,28 @@ module GOVUKDesignSystemFormBuilder
6
6
  include Traits::Hint
7
7
  include Traits::Supplemental
8
8
 
9
- def initialize(builder, object_name, attribute_name, collection, value_method:, text_method:, hint_method:, hint:, legend:, caption:, inline:, small:, bold_labels:, classes:, form_group:, &block)
9
+ def initialize(builder, object_name, attribute_name, collection, value_method:, text_method:, hint_method:, hint:, legend:, caption:, inline:, small:, bold_labels:, classes:, form_group:, include_hidden:, &block)
10
10
  super(builder, object_name, attribute_name, &block)
11
11
 
12
- @collection = collection
13
- @value_method = value_method
14
- @text_method = text_method
15
- @hint_method = hint_method
16
- @inline = inline
17
- @small = small
18
- @legend = legend
19
- @caption = caption
20
- @hint = hint
21
- @classes = classes
22
- @form_group = form_group
23
- @bold_labels = hint_method.present? || bold_labels
12
+ @collection = collection
13
+ @value_method = value_method
14
+ @text_method = text_method
15
+ @hint_method = hint_method
16
+ @inline = inline
17
+ @small = small
18
+ @legend = legend
19
+ @caption = caption
20
+ @hint = hint
21
+ @classes = classes
22
+ @form_group = form_group
23
+ @include_hidden = include_hidden
24
+ @bold_labels = hint_method.present? || bold_labels
24
25
  end
25
26
 
26
27
  def html
27
28
  Containers::FormGroup.new(@builder, @object_name, @attribute_name, **@form_group).html do
28
29
  Containers::Fieldset.new(@builder, @object_name, @attribute_name, **fieldset_options).html do
29
- safe_join([supplemental_content, hint_element, error_element, radios])
30
+ safe_join([hidden_field, supplemental_content, hint_element, error_element, radios])
30
31
  end
31
32
  end
32
33
  end
@@ -47,6 +48,12 @@ module GOVUKDesignSystemFormBuilder
47
48
  end
48
49
  end
49
50
 
51
+ def hidden_field
52
+ return unless @include_hidden
53
+
54
+ @builder.hidden_field(@attribute_name, value: "")
55
+ end
56
+
50
57
  def collection
51
58
  @collection.map.with_index do |item, i|
52
59
  Elements::Radios::CollectionRadioButton.new(@builder, @object_name, @attribute_name, item, **collection_options(i)).html
@@ -6,7 +6,7 @@ module GOVUKDesignSystemFormBuilder
6
6
  include Traits::Hint
7
7
  include Traits::Supplemental
8
8
 
9
- def initialize(builder, object_name, attribute_name, collection, value_method:, text_method:, options: {}, html_options: {}, hint:, label:, caption:, form_group:, &block)
9
+ def initialize(builder, object_name, attribute_name, collection, value_method:, text_method:, hint:, label:, caption:, form_group:, options: {}, html_options: {}, &block)
10
10
  super(builder, object_name, attribute_name, &block)
11
11
 
12
12
  @collection = collection
@@ -49,7 +49,7 @@ module GOVUKDesignSystemFormBuilder
49
49
  end
50
50
 
51
51
  def custom_classes
52
- @html_options.dig(:class)
52
+ @html_options[:class]
53
53
  end
54
54
  end
55
55
  end
@@ -4,9 +4,10 @@ module GOVUKDesignSystemFormBuilder
4
4
  using PrefixableArray
5
5
 
6
6
  def initialize(builder, text, warning:, secondary:, classes:, prevent_double_click:, validate:, disabled:, &block)
7
+ super(builder, nil, nil)
8
+
7
9
  fail ArgumentError, 'buttons can be warning or secondary' if warning && secondary
8
10
 
9
- @builder = builder
10
11
  @text = text
11
12
  @prevent_double_click = prevent_double_click
12
13
  @warning = warning
@@ -18,11 +19,19 @@ module GOVUKDesignSystemFormBuilder
18
19
  end
19
20
 
20
21
  def html
21
- safe_join([submit, @block_content])
22
+ @block_content.present? ? button_group : buttons
22
23
  end
23
24
 
24
25
  private
25
26
 
27
+ def buttons
28
+ safe_join([submit, @block_content])
29
+ end
30
+
31
+ def button_group
32
+ Containers::ButtonGroup.new(@builder, buttons).html
33
+ end
34
+
26
35
  def submit
27
36
  @builder.submit(@text, class: classes, **options)
28
37
  end
@@ -30,7 +39,7 @@ module GOVUKDesignSystemFormBuilder
30
39
  def classes
31
40
  %w(button)
32
41
  .prefix(brand)
33
- .push(warning_class, secondary_class, disabled_class, padding_class, custom_classes)
42
+ .push(warning_class, secondary_class, disabled_class, custom_classes)
34
43
  .flatten
35
44
  .compact
36
45
  end
@@ -54,10 +63,6 @@ module GOVUKDesignSystemFormBuilder
54
63
  %(#{brand}-button--secondary) if @secondary
55
64
  end
56
65
 
57
- def padding_class
58
- %(#{brand}-!-margin-right-1) if @block_content
59
- end
60
-
61
66
  def disabled_class
62
67
  %(#{brand}-button--disabled) if @disabled
63
68
  end
@@ -8,7 +8,7 @@ module GOVUKDesignSystemFormBuilder
8
8
  when Symbol, String
9
9
  item.send(method)
10
10
  when Proc
11
- capture { method.call(item) }
11
+ capture { method.call(item).to_s }
12
12
  end
13
13
  end
14
14
  end
@@ -1,3 +1,3 @@
1
1
  module GOVUKDesignSystemFormBuilder
2
- VERSION = '2.1.5'.freeze
2
+ VERSION = '2.1.8'.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.1.5
4
+ version: 2.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Yates
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-28 00:00:00.000000000 Z
11
+ date: 2021-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionview
@@ -134,14 +134,14 @@ dependencies:
134
134
  requirements:
135
135
  - - "~>"
136
136
  - !ruby/object:Gem::Version
137
- version: 0.17.1
137
+ version: '0.20'
138
138
  type: :development
139
139
  prerelease: false
140
140
  version_requirements: !ruby/object:Gem::Requirement
141
141
  requirements:
142
142
  - - "~>"
143
143
  - !ruby/object:Gem::Version
144
- version: 0.17.1
144
+ version: '0.20'
145
145
  - !ruby/object:Gem::Dependency
146
146
  name: htmlbeautifier
147
147
  requirement: !ruby/object:Gem::Requirement
@@ -176,14 +176,14 @@ dependencies:
176
176
  requirements:
177
177
  - - "~>"
178
178
  - !ruby/object:Gem::Version
179
- version: 3.24.0
179
+ version: 3.26.0
180
180
  type: :development
181
181
  prerelease: false
182
182
  version_requirements: !ruby/object:Gem::Requirement
183
183
  requirements:
184
184
  - - "~>"
185
185
  - !ruby/object:Gem::Version
186
- version: 3.24.0
186
+ version: 3.26.0
187
187
  - !ruby/object:Gem::Dependency
188
188
  name: rubypants
189
189
  requirement: !ruby/object:Gem::Requirement
@@ -252,6 +252,7 @@ files:
252
252
  - lib/govuk_design_system_formbuilder.rb
253
253
  - lib/govuk_design_system_formbuilder/base.rb
254
254
  - lib/govuk_design_system_formbuilder/builder.rb
255
+ - lib/govuk_design_system_formbuilder/containers/button_group.rb
255
256
  - lib/govuk_design_system_formbuilder/containers/character_count.rb
256
257
  - lib/govuk_design_system_formbuilder/containers/check_boxes.rb
257
258
  - lib/govuk_design_system_formbuilder/containers/check_boxes_fieldset.rb
@@ -305,7 +306,7 @@ metadata:
305
306
  documentation_uri: https://www.rubydoc.info/gems/govuk_design_system_formbuilder/GOVUKDesignSystemFormBuilder/Builder
306
307
  homepage_uri: https://govuk-form-builder.netlify.app
307
308
  source_code_uri: https://github.com/DFE-Digital/govuk_design_system_formbuilder
308
- post_install_message:
309
+ post_install_message:
309
310
  rdoc_options: []
310
311
  require_paths:
311
312
  - lib
@@ -320,8 +321,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
320
321
  - !ruby/object:Gem::Version
321
322
  version: '0'
322
323
  requirements: []
323
- rubygems_version: 3.1.2
324
- signing_key:
324
+ rubygems_version: 3.1.4
325
+ signing_key:
325
326
  specification_version: 4
326
327
  summary: GOV.UK-compliant Rails form builder
327
328
  test_files: []