govuk_design_system_formbuilder 0.9.7 → 0.9.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/lib/govuk_design_system_formbuilder/base.rb +5 -3
  4. data/lib/govuk_design_system_formbuilder/builder.rb +3 -2
  5. data/lib/govuk_design_system_formbuilder/containers/character_count.rb +1 -1
  6. data/lib/govuk_design_system_formbuilder/containers/check_boxes.rb +1 -1
  7. data/lib/govuk_design_system_formbuilder/containers/check_boxes_fieldset.rb +2 -2
  8. data/lib/govuk_design_system_formbuilder/containers/fieldset.rb +4 -4
  9. data/lib/govuk_design_system_formbuilder/containers/form_group.rb +1 -1
  10. data/lib/govuk_design_system_formbuilder/containers/radio_buttons_fieldset.rb +2 -2
  11. data/lib/govuk_design_system_formbuilder/containers/radios.rb +1 -1
  12. data/lib/govuk_design_system_formbuilder/containers/supplemental.rb +1 -1
  13. data/lib/govuk_design_system_formbuilder/elements/check_boxes/collection.rb +1 -1
  14. data/lib/govuk_design_system_formbuilder/elements/check_boxes/collection_check_box.rb +2 -2
  15. data/lib/govuk_design_system_formbuilder/elements/check_boxes/fieldset_check_box.rb +3 -3
  16. data/lib/govuk_design_system_formbuilder/elements/check_boxes/hint.rb +1 -1
  17. data/lib/govuk_design_system_formbuilder/elements/date.rb +31 -17
  18. data/lib/govuk_design_system_formbuilder/elements/error_message.rb +3 -3
  19. data/lib/govuk_design_system_formbuilder/elements/error_summary.rb +8 -8
  20. data/lib/govuk_design_system_formbuilder/elements/file.rb +1 -1
  21. data/lib/govuk_design_system_formbuilder/elements/hint.rb +1 -1
  22. data/lib/govuk_design_system_formbuilder/elements/inputs/base.rb +1 -1
  23. data/lib/govuk_design_system_formbuilder/elements/label.rb +3 -3
  24. data/lib/govuk_design_system_formbuilder/elements/radios/collection.rb +2 -2
  25. data/lib/govuk_design_system_formbuilder/elements/radios/collection_radio_button.rb +2 -2
  26. data/lib/govuk_design_system_formbuilder/elements/radios/fieldset_radio_button.rb +3 -3
  27. data/lib/govuk_design_system_formbuilder/elements/select.rb +1 -1
  28. data/lib/govuk_design_system_formbuilder/elements/submit.rb +3 -3
  29. data/lib/govuk_design_system_formbuilder/elements/text_area.rb +1 -1
  30. data/lib/govuk_design_system_formbuilder/version.rb +1 -1
  31. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e2e5af4cfd336ab70886054fa8b6dc83ac646e9f4fb9006025ecc6138cdb4604
4
- data.tar.gz: ac67744826513c36b483444de6e5ab71ea58ce63259f628c89245c677b42a680
3
+ metadata.gz: 34191822b2322a27884781b5fdc5d494385f0386b349c8253c213f76cef55600
4
+ data.tar.gz: dc0d69655c5d8bcbeaa967b852566abec1b821ad9ef43a6f0a4bc65afafc841a
5
5
  SHA512:
6
- metadata.gz: c05a5ecfb4c14e61498cb22b78fc93668dae12113e35a653ba56b0e70aedcb1fa4de4297de1d54a71e0e4375dc32c276e90aedf14e8f352362ba871673eeff31
7
- data.tar.gz: 0000e348e1f846431398d16b6d1364062f2d6442a83f39d94293ad84a27436e80d063381d5c5765c5ad1af7ca5e6179b6785290199d7cbf221588ab7ea521738
6
+ metadata.gz: 21f8a1d3f15d4de5f01bb54804fbb700ca902f6cb7dee40ab686b500d3d9133f2c3983b48fb4ee040ffcb24c19d03c5511736dc9ca732d3204caeb45ad185e20
7
+ data.tar.gz: 154333ebb09be62fd38a1d4c0b3449d0a140d2c732e1010f2a164b095f93cd1d67c6870fbf6908729cc8a78cc02ea131f67677f685cef680a276611706b1b2b6
data/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  [![Netlify Status](https://api.netlify.com/api/v1/badges/d4c50b8d-6ca3-4797-9ab3-6e0731c72b44/deploy-status)](https://app.netlify.com/sites/govuk-form-builder/deploys)
8
8
 
9
9
  This gem provides a easy-to-use form builder that generates forms that are
10
- fully-compliant with version 3.2.0 of the [GOV.UK Design System](https://design-system.service.gov.uk/),
10
+ fully-compliant with version 3.3.0 of the [GOV.UK Design System](https://design-system.service.gov.uk/),
11
11
  minimising the amount of markup you need to write.
12
12
 
13
13
  The latest version of this gem that supports GOV.UK Design System version 2 is
@@ -1,10 +1,12 @@
1
1
  module GOVUKDesignSystemFormBuilder
2
2
  class Base
3
+ delegate :capture, :content_tag, :safe_join, :tag, :raw, :link_to, to: :@builder
4
+
3
5
  def initialize(builder, object_name, attribute_name, &block)
4
6
  @builder = builder
5
7
  @object_name = object_name
6
8
  @attribute_name = attribute_name
7
- @block_content = @builder.capture { block.call } if block_given?
9
+ @block_content = capture { block.call } if block_given?
8
10
  end
9
11
 
10
12
  def hint_element
@@ -72,8 +74,8 @@ module GOVUKDesignSystemFormBuilder
72
74
  end
73
75
 
74
76
  def wrap_conditional(block)
75
- @builder.content_tag('div', class: conditional_classes, id: conditional_id) do
76
- @builder.capture { block.call }
77
+ content_tag('div', class: conditional_classes, id: conditional_id) do
78
+ capture { block.call }
77
79
  end
78
80
  end
79
81
 
@@ -465,6 +465,7 @@ module GOVUKDesignSystemFormBuilder
465
465
  # @option legend text [String] the fieldset legend's text content
466
466
  # @option legend size [String] the size of the fieldset legend font, can be +xl+, +l+, +m+ or +s+
467
467
  # @option legend tag [Symbol,String] the tag used for the fieldset's header, defaults to +h1+
468
+ # @param omit_day [Boolean] do not render a day input, only capture month and year
468
469
  # @param block [Block] arbitrary HTML that will be rendered between the hint and the input group
469
470
  # @param date_of_birth [Boolean] if +true+ {https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete#Values birth date auto completion attributes}
470
471
  # will be added to the inputs
@@ -476,8 +477,8 @@ module GOVUKDesignSystemFormBuilder
476
477
  # = f.govuk_date_field :starts_on,
477
478
  # legend: { 'When does your event start?' },
478
479
  # hint_text: 'Leave this field blank if you don't know exactly' }
479
- def govuk_date_field(attribute_name, hint_text: nil, legend: {}, date_of_birth: false, &block)
480
- Elements::Date.new(self, object_name, attribute_name, hint_text: hint_text, legend: legend, date_of_birth: date_of_birth, &block).html
480
+ def govuk_date_field(attribute_name, hint_text: nil, legend: {}, date_of_birth: false, omit_day: false, &block)
481
+ 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
481
482
  end
482
483
 
483
484
  # Generates a summary of errors in the form, each linking to the corresponding
@@ -14,7 +14,7 @@ module GOVUKDesignSystemFormBuilder
14
14
  def html
15
15
  return yield unless limit?
16
16
 
17
- @builder.content_tag(
17
+ content_tag(
18
18
  'div',
19
19
  class: 'govuk-character-count',
20
20
  data: { module: 'govuk-character-count' }.merge(**limit, **threshold).compact
@@ -7,7 +7,7 @@ module GOVUKDesignSystemFormBuilder
7
7
  end
8
8
 
9
9
  def html
10
- @builder.content_tag('div', class: check_boxes_classes, data: { module: 'govuk-checkboxes' }) do
10
+ content_tag('div', class: check_boxes_classes, data: { module: 'govuk-checkboxes' }) do
11
11
  yield
12
12
  end
13
13
  end
@@ -7,13 +7,13 @@ module GOVUKDesignSystemFormBuilder
7
7
  @legend = legend
8
8
  @hint_text = hint_text
9
9
  @small = small
10
- @block_content = @builder.capture { block.call }
10
+ @block_content = capture { block.call }
11
11
  end
12
12
 
13
13
  def html
14
14
  Containers::FormGroup.new(@builder, @object_name, @attribute_name).html do
15
15
  Containers::Fieldset.new(@builder, legend: @legend, described_by: [error_element.error_id, hint_element.hint_id]).html do
16
- @builder.safe_join(
16
+ safe_join(
17
17
  [
18
18
  hint_element.html,
19
19
  error_element.html,
@@ -11,8 +11,8 @@ module GOVUKDesignSystemFormBuilder
11
11
  end
12
12
 
13
13
  def html
14
- @builder.content_tag('fieldset', class: fieldset_classes, aria: { describedby: @described_by }) do
15
- @builder.safe_join([build_legend, yield])
14
+ content_tag('fieldset', class: fieldset_classes, aria: { describedby: @described_by }) do
15
+ safe_join([build_legend, yield])
16
16
  end
17
17
  end
18
18
 
@@ -20,8 +20,8 @@ module GOVUKDesignSystemFormBuilder
20
20
 
21
21
  def build_legend
22
22
  if @legend.dig(:text).present?
23
- @builder.content_tag('legend', class: legend_classes) do
24
- @builder.tag.send(@legend.dig(:tag), @legend.dig(:text), class: legend_heading_classes)
23
+ content_tag('legend', class: legend_classes) do
24
+ tag.send(@legend.dig(:tag), @legend.dig(:text), class: legend_heading_classes)
25
25
  end
26
26
  end
27
27
  end
@@ -6,7 +6,7 @@ module GOVUKDesignSystemFormBuilder
6
6
  end
7
7
 
8
8
  def html
9
- @builder.content_tag('div', class: form_group_classes) do
9
+ content_tag('div', class: form_group_classes) do
10
10
  yield
11
11
  end
12
12
  end
@@ -8,13 +8,13 @@ module GOVUKDesignSystemFormBuilder
8
8
  @small = small
9
9
  @legend = legend
10
10
  @hint_text = hint_text
11
- @block_content = @builder.capture { block.call }
11
+ @block_content = capture { block.call }
12
12
  end
13
13
 
14
14
  def html
15
15
  Containers::FormGroup.new(@builder, @object_name, @attribute_name).html do
16
16
  Containers::Fieldset.new(@builder, legend: @legend, described_by: [error_element.error_id, hint_element.hint_id]).html do
17
- @builder.safe_join(
17
+ safe_join(
18
18
  [
19
19
  hint_element.html,
20
20
  error_element.html,
@@ -8,7 +8,7 @@ module GOVUKDesignSystemFormBuilder
8
8
  end
9
9
 
10
10
  def html
11
- @builder.content_tag('div', class: radios_classes, data: { module: 'govuk-radios' }) do
11
+ content_tag('div', class: radios_classes, data: { module: 'govuk-radios' }) do
12
12
  yield
13
13
  end
14
14
  end
@@ -11,7 +11,7 @@ module GOVUKDesignSystemFormBuilder
11
11
  def html
12
12
  return nil unless @content.present?
13
13
 
14
- @builder.content_tag('div', id: supplemental_id) do
14
+ content_tag('div', id: supplemental_id) do
15
15
  @content
16
16
  end
17
17
  end
@@ -17,7 +17,7 @@ module GOVUKDesignSystemFormBuilder
17
17
  def html
18
18
  Containers::FormGroup.new(@builder, @object_name, @attribute_name).html do
19
19
  Containers::Fieldset.new(@builder, legend: @legend, described_by: [error_id, hint_id, supplemental_id]).html do
20
- @builder.safe_join(
20
+ safe_join(
21
21
  [
22
22
  hint_element.html,
23
23
  error_element.html,
@@ -12,8 +12,8 @@ module GOVUKDesignSystemFormBuilder
12
12
  end
13
13
 
14
14
  def html
15
- @builder.content_tag('div', class: 'govuk-checkboxes__item') do
16
- @builder.safe_join(
15
+ content_tag('div', class: 'govuk-checkboxes__item') do
16
+ safe_join(
17
17
  [
18
18
  @checkbox.check_box(
19
19
  id: field_id(link_errors: @link_errors),
@@ -18,10 +18,10 @@ module GOVUKDesignSystemFormBuilder
18
18
  end
19
19
 
20
20
  def html
21
- @builder.safe_join(
21
+ safe_join(
22
22
  [
23
- @builder.content_tag('div', class: 'govuk-checkboxes__item') do
24
- @builder.safe_join(
23
+ content_tag('div', class: 'govuk-checkboxes__item') do
24
+ safe_join(
25
25
  [
26
26
  input,
27
27
  label_element.html,
@@ -12,7 +12,7 @@ module GOVUKDesignSystemFormBuilder
12
12
  def html
13
13
  return nil if @hint_text.blank?
14
14
 
15
- @builder.tag.span(@hint_text, class: hint_classes, id: id)
15
+ tag.span(@hint_text, class: hint_classes, id: id)
16
16
  end
17
17
 
18
18
  def id
@@ -3,29 +3,25 @@ module GOVUKDesignSystemFormBuilder
3
3
  class Date < GOVUKDesignSystemFormBuilder::Base
4
4
  SEGMENTS = { day: '3i', month: '2i', year: '1i' }.freeze
5
5
 
6
- def initialize(builder, object_name, attribute_name, legend:, hint_text:, date_of_birth: false, &block)
6
+ def initialize(builder, object_name, attribute_name, legend:, hint_text:, date_of_birth: false, omit_day:, &block)
7
7
  super(builder, object_name, attribute_name, &block)
8
- @legend = legend
9
- @hint_text = hint_text
8
+
9
+ @legend = legend
10
+ @hint_text = hint_text
10
11
  @date_of_birth = date_of_birth
12
+ @omit_day = omit_day
11
13
  end
12
14
 
13
15
  def html
14
16
  Containers::FormGroup.new(@builder, @object_name, @attribute_name).html do
15
17
  Containers::Fieldset.new(@builder, legend: @legend, described_by: [error_id, hint_id, supplemental_id]).html do
16
- @builder.safe_join(
18
+ safe_join(
17
19
  [
18
20
  hint_element.html,
19
21
  error_element.html,
20
22
  supplemental_content.html,
21
- @builder.content_tag('div', class: 'govuk-date-input') do
22
- @builder.safe_join(
23
- [
24
- date_input_item(:day, link_errors: true),
25
- date_input_item(:month),
26
- date_input_item(:year, width: 4)
27
- ]
28
- )
23
+ content_tag('div', class: 'govuk-date-input') do
24
+ safe_join([day, month, year])
29
25
  end
30
26
  ]
31
27
  )
@@ -35,20 +31,38 @@ module GOVUKDesignSystemFormBuilder
35
31
 
36
32
  private
37
33
 
34
+ def omit_day?
35
+ @omit_day
36
+ end
37
+
38
+ def day
39
+ return nil if omit_day?
40
+
41
+ date_input_item(:day, link_errors: true)
42
+ end
43
+
44
+ def month
45
+ date_input_item(:month, link_errors: omit_day?)
46
+ end
47
+
48
+ def year
49
+ date_input_item(:year, width: 4)
50
+ end
51
+
38
52
  def date_input_item(segment, width: 2, link_errors: false)
39
53
  value = @builder.object.try(@attribute_name).try(segment)
40
54
 
41
- @builder.content_tag('div', class: %w(govuk-date-input__item)) do
42
- @builder.content_tag('div', class: %w(govuk-form-group)) do
43
- @builder.safe_join(
55
+ content_tag('div', class: %w(govuk-date-input__item)) do
56
+ content_tag('div', class: %w(govuk-form-group)) do
57
+ safe_join(
44
58
  [
45
- @builder.tag.label(
59
+ tag.label(
46
60
  segment.capitalize,
47
61
  class: date_input_label_classes,
48
62
  for: date_attribute_id(segment, link_errors)
49
63
  ),
50
64
 
51
- @builder.tag.input(
65
+ tag.input(
52
66
  id: date_attribute_id(segment, link_errors),
53
67
  class: date_input_classes(width),
54
68
  name: date_attribute_name(segment),
@@ -8,10 +8,10 @@ module GOVUKDesignSystemFormBuilder
8
8
  def html
9
9
  return nil unless has_errors?
10
10
 
11
- @builder.content_tag('span', class: 'govuk-error-message', id: error_id) do
12
- @builder.safe_join(
11
+ content_tag('span', class: 'govuk-error-message', id: error_id) do
12
+ safe_join(
13
13
  [
14
- @builder.tag.span('Error: ', class: 'govuk-visually-hidden'),
14
+ tag.span('Error: ', class: 'govuk-visually-hidden'),
15
15
  message
16
16
  ]
17
17
  )
@@ -10,13 +10,13 @@ module GOVUKDesignSystemFormBuilder
10
10
  def html
11
11
  return nil unless object_has_errors?
12
12
 
13
- @builder.content_tag('div', class: summary_class, **error_summary_attributes) do
14
- @builder.safe_join(
13
+ content_tag('div', class: summary_class, **error_summary_attributes) do
14
+ safe_join(
15
15
  [
16
- @builder.tag.h2(@title, id: error_summary_title_id, class: summary_class('title')),
17
- @builder.content_tag('div', class: summary_class('body')) do
18
- @builder.content_tag('ul', class: ['govuk-list', summary_class('list')]) do
19
- @builder.safe_join(
16
+ tag.h2(@title, id: error_summary_title_id, class: summary_class('title')),
17
+ content_tag('div', class: summary_class('body')) do
18
+ content_tag('ul', class: ['govuk-list', summary_class('list')]) do
19
+ safe_join(
20
20
  @builder.object.errors.messages.map do |attribute, messages|
21
21
  error_list_item(attribute, messages.first)
22
22
  end
@@ -31,8 +31,8 @@ module GOVUKDesignSystemFormBuilder
31
31
  private
32
32
 
33
33
  def error_list_item(attribute, message)
34
- @builder.content_tag('li') do
35
- @builder.link_to(
34
+ content_tag('li') do
35
+ link_to(
36
36
  message,
37
37
  same_page_link(field_id(attribute)),
38
38
  data: {
@@ -11,7 +11,7 @@ module GOVUKDesignSystemFormBuilder
11
11
 
12
12
  def html
13
13
  Containers::FormGroup.new(@builder, @object_name, @attribute_name).html do
14
- @builder.safe_join(
14
+ safe_join(
15
15
  [
16
16
  label_element.html,
17
17
  hint_element.html,
@@ -13,7 +13,7 @@ module GOVUKDesignSystemFormBuilder
13
13
  def html
14
14
  return nil if @hint_text.blank?
15
15
 
16
- @builder.tag.span(@hint_text, class: hint_classes, id: hint_id)
16
+ tag.span(@hint_text, class: hint_classes, id: hint_id)
17
17
  end
18
18
 
19
19
  private
@@ -13,7 +13,7 @@ module GOVUKDesignSystemFormBuilder
13
13
 
14
14
  def html
15
15
  Containers::FormGroup.new(@builder, @object_name, @attribute_name).html do
16
- @builder.safe_join(
16
+ safe_join(
17
17
  [
18
18
  label_element.html,
19
19
  hint_element.html,
@@ -17,7 +17,7 @@ module GOVUKDesignSystemFormBuilder
17
17
  return nil if @text.blank?
18
18
 
19
19
  if @tag.present?
20
- @builder.content_tag(@tag, class: 'govuk-label-wrapper') { build_label }
20
+ content_tag(@tag, class: 'govuk-label-wrapper') { build_label }
21
21
  else
22
22
  build_label
23
23
  end
@@ -40,9 +40,9 @@ module GOVUKDesignSystemFormBuilder
40
40
  text = [option_text, @value, @attribute_name.capitalize].compact.first
41
41
 
42
42
  if hidden
43
- @builder.tag.span(text, class: %w(govuk-visually-hidden))
43
+ tag.span(text, class: %w(govuk-visually-hidden))
44
44
  else
45
- @builder.raw(text)
45
+ raw(text)
46
46
  end
47
47
  end
48
48
 
@@ -19,13 +19,13 @@ module GOVUKDesignSystemFormBuilder
19
19
  def html
20
20
  Containers::FormGroup.new(@builder, @object_name, @attribute_name).html do
21
21
  Containers::Fieldset.new(@builder, legend: @legend, described_by: [error_id, hint_id, supplemental_id]).html do
22
- @builder.safe_join(
22
+ safe_join(
23
23
  [
24
24
  hint_element.html,
25
25
  error_element.html,
26
26
  supplemental_content.html,
27
27
  Containers::Radios.new(@builder, inline: @inline, small: @small).html do
28
- @builder.safe_join(build_collection)
28
+ safe_join(build_collection)
29
29
  end
30
30
  ]
31
31
  )
@@ -17,8 +17,8 @@ module GOVUKDesignSystemFormBuilder
17
17
  end
18
18
 
19
19
  def html
20
- @builder.content_tag('div', class: 'govuk-radios__item') do
21
- @builder.safe_join(
20
+ content_tag('div', class: 'govuk-radios__item') do
21
+ safe_join(
22
22
  [
23
23
  @builder.radio_button(
24
24
  @attribute_name,
@@ -17,10 +17,10 @@ module GOVUKDesignSystemFormBuilder
17
17
  end
18
18
 
19
19
  def html
20
- @builder.safe_join(
20
+ safe_join(
21
21
  [
22
- @builder.content_tag('div', class: 'govuk-radios__item') do
23
- @builder.safe_join(
22
+ content_tag('div', class: 'govuk-radios__item') do
23
+ safe_join(
24
24
  [
25
25
  input,
26
26
  label_element.html,
@@ -15,7 +15,7 @@ module GOVUKDesignSystemFormBuilder
15
15
 
16
16
  def html
17
17
  Containers::FormGroup.new(@builder, @object_name, @attribute_name).html do
18
- @builder.safe_join(
18
+ safe_join(
19
19
  [
20
20
  label_element.html,
21
21
  hint_element.html,
@@ -10,12 +10,12 @@ module GOVUKDesignSystemFormBuilder
10
10
  @warning = warning
11
11
  @secondary = secondary
12
12
  @validate = validate
13
- @block_content = @builder.capture { block.call } if block_given?
13
+ @block_content = capture { block.call } if block_given?
14
14
  end
15
15
 
16
16
  def html
17
- @builder.content_tag('div', class: %w(govuk-form-group)) do
18
- @builder.safe_join(
17
+ content_tag('div', class: %w(govuk-form-group)) do
18
+ safe_join(
19
19
  [
20
20
  @builder.submit(
21
21
  @text,
@@ -15,7 +15,7 @@ module GOVUKDesignSystemFormBuilder
15
15
  def html
16
16
  Containers::CharacterCount.new(@builder, max_words: @max_words, max_chars: @max_chars, threshold: @threshold).html do
17
17
  Containers::FormGroup.new(@builder, @object_name, @attribute_name).html do
18
- @builder.safe_join(
18
+ safe_join(
19
19
  [
20
20
  [label_element, hint_element, error_element, supplemental_content].map(&:html),
21
21
  @builder.text_area(
@@ -1,3 +1,3 @@
1
1
  module GOVUKDesignSystemFormBuilder
2
- VERSION = '0.9.7'.freeze
2
+ VERSION = '0.9.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: 0.9.7
4
+ version: 0.9.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Yates
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-12 00:00:00.000000000 Z
11
+ date: 2019-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionview