govuk_design_system_formbuilder 2.7.6 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 16dd3a6e9641b3d0aa7e91ee6318bcd0f993d10c00105e1c977f54120eb966d9
4
- data.tar.gz: 5aa914a964cac5770d3e1c002aa9e38a20b4bf21c612a9c78c5edfa503c8e98f
3
+ metadata.gz: 5431741c89f055b1f15ae71906531d15d2ecc0be3052bb7f532a485829b14f90
4
+ data.tar.gz: be2a909ef9dc527f086b62446a39e72be35fc893131e4218e3a1f1d138a0eeb6
5
5
  SHA512:
6
- metadata.gz: 870971ada7f130cd54a13cff52f852d07e1581dd8ebf04f802ae93ca2103325fa2e283e9812170c282da4c5b1a056490799828f0f8d374a7b8d92a053bc6114e
7
- data.tar.gz: 7e931f7fe3966909bdd2c4ff16ee3fe7d06e0c52925c03d36fb300a99d7105a842ee6f5aeac165b3824495efd7b3d189ac925378c4a10b7e57c37f8d4230eeb2
6
+ metadata.gz: 986679d3cb0ab2953a945c04ad46fae65788e0de23bdef6df1febb1884fd01a039552c2973130637e10851cc9f176d7b5f3c5a2db0ac9ddb1871484cd5186ccb
7
+ data.tar.gz: e9dc03abd08f7ae026d0ae95efb3d36ae32dc6530101747ea1f1fb236c18c4156670fa60654df88d5d2562251f319358b43c49e6fd819da4afd840997296eef5
data/README.md CHANGED
@@ -5,10 +5,10 @@
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/110136fb22341d3ba646/test_coverage)](https://codeclimate.com/github/DFE-Digital/govuk-formbuilder/test_coverage)
8
- [![GitHub license](https://img.shields.io/github/license/DFE-Digital/govuk_design_system_formbuilder)](https://github.com/DFE-Digital/govuk-formbuilder/blob/master/LICENSE)
8
+ [![GitHub license](https://img.shields.io/github/license/DFE-Digital/govuk_design_system_formbuilder)](https://github.com/DFE-Digital/govuk-formbuilder/blob/main/LICENSE)
9
9
  [![GOV.UK Design System Version](https://img.shields.io/badge/GOV.UK%20Design%20System-3.14.0-brightgreen)](https://design-system.service.gov.uk)
10
- [![Rails](https://img.shields.io/badge/Rails-6.0.4.1%20%E2%95%B1%206.1.4.1-E16D6D)](https://weblog.rubyonrails.org/releases/)
11
- [![Ruby](https://img.shields.io/badge/Ruby-2.6.8%20%E2%95%B1%202.7.4%20%E2%95%B1%203.0.2-E16D6D)](https://www.ruby-lang.org/en/downloads/)
10
+ [![Rails](https://img.shields.io/badge/Rails-6.1.4.4%20%E2%95%B1%207.0.1-E16D6D)](https://weblog.rubyonrails.org/releases/)
11
+ [![Ruby](https://img.shields.io/badge/Ruby-2.7.5%20%20%E2%95%B1%203.0.3%20%20%E2%95%B1%203.1.0-E16D6D)](https://www.ruby-lang.org/en/downloads/)
12
12
 
13
13
  This library provides an easy-to-use form builder for the [GOV.UK Design System](https://design-system.service.gov.uk/).
14
14
 
@@ -912,6 +912,7 @@ module GOVUKDesignSystemFormBuilder
912
912
  # @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
913
913
  # @option caption kwargs [Hash] additional arguments are applied as attributes on the caption +span+ element
914
914
  # @param omit_day [Boolean] do not render a day input, only capture month and year
915
+ # @param maxlength_enabled [Boolean] adds maxlength attribute to day, month and year inputs (2, 2, and 4, respectively)
915
916
  # @param wildcards [Boolean] add an 'X' to the day and month patterns so users can add approximate dates
916
917
  # @param form_group [Hash] configures the form group
917
918
  # @option form_group classes [Array,String] sets the form group's classes
@@ -936,8 +937,8 @@ module GOVUKDesignSystemFormBuilder
936
937
  # @example A date input with legend supplied as a proc
937
938
  # = f.govuk_date_field :finishes_on,
938
939
  # legend: -> { tag.h3('Which category do you belong to?') }
939
- def govuk_date_field(attribute_name, hint: {}, legend: {}, caption: {}, date_of_birth: false, omit_day: false, form_group: {}, wildcards: false, **kwargs, &block)
940
- Elements::Date.new(self, object_name, attribute_name, hint: hint, legend: legend, caption: caption, date_of_birth: date_of_birth, omit_day: omit_day, form_group: form_group, wildcards: wildcards, **kwargs, &block).html
940
+ def govuk_date_field(attribute_name, hint: {}, legend: {}, caption: {}, date_of_birth: false, omit_day: false, maxlength_enabled: false, form_group: {}, wildcards: false, **kwargs, &block)
941
+ Elements::Date.new(self, object_name, attribute_name, hint: hint, legend: legend, caption: caption, date_of_birth: date_of_birth, omit_day: omit_day, maxlength_enabled: maxlength_enabled, form_group: form_group, wildcards: wildcards, **kwargs, &block).html
941
942
  end
942
943
 
943
944
  # Generates a summary of errors in the form, each linking to the corresponding
@@ -6,21 +6,23 @@ module GOVUKDesignSystemFormBuilder
6
6
  include Traits::Error
7
7
  include Traits::Hint
8
8
  include Traits::Supplemental
9
+ include Traits::HTMLClasses
9
10
 
10
11
  SEGMENTS = { day: '3i', month: '2i', year: '1i' }.freeze
11
12
  MULTIPARAMETER_KEY = { day: 3, month: 2, year: 1 }.freeze
12
13
 
13
- def initialize(builder, object_name, attribute_name, legend:, caption:, hint:, omit_day:, form_group:, wildcards:, date_of_birth: false, **kwargs, &block)
14
+ def initialize(builder, object_name, attribute_name, legend:, caption:, hint:, omit_day:, maxlength_enabled:, form_group:, wildcards:, date_of_birth: false, **kwargs, &block)
14
15
  super(builder, object_name, attribute_name, &block)
15
16
 
16
- @legend = legend
17
- @caption = caption
18
- @hint = hint
19
- @date_of_birth = date_of_birth
20
- @omit_day = omit_day
21
- @form_group = form_group
22
- @wildcards = wildcards
23
- @html_attributes = kwargs
17
+ @legend = legend
18
+ @caption = caption
19
+ @hint = hint
20
+ @date_of_birth = date_of_birth
21
+ @omit_day = omit_day
22
+ @maxlength_enabled = maxlength_enabled
23
+ @form_group = form_group
24
+ @wildcards = wildcards
25
+ @html_attributes = kwargs
24
26
  end
25
27
 
26
28
  def html
@@ -47,6 +49,10 @@ module GOVUKDesignSystemFormBuilder
47
49
  @omit_day
48
50
  end
49
51
 
52
+ def maxlength_enabled?
53
+ @maxlength_enabled
54
+ end
55
+
50
56
  def day
51
57
  return if omit_day?
52
58
 
@@ -104,7 +110,8 @@ module GOVUKDesignSystemFormBuilder
104
110
  pattern: pattern(segment),
105
111
  inputmode: 'numeric',
106
112
  value: value,
107
- autocomplete: date_of_birth_autocomplete_value(segment)
113
+ autocomplete: date_of_birth_autocomplete_value(segment),
114
+ maxlength: (width if maxlength_enabled?),
108
115
  )
109
116
  end
110
117
 
@@ -115,10 +122,12 @@ module GOVUKDesignSystemFormBuilder
115
122
  end
116
123
 
117
124
  def classes(width)
118
- %w(input date-input__input).prefix(brand).tap do |classes|
119
- classes.push(%(#{brand}-input--width-#{width}))
120
- classes.push(%(#{brand}-input--error)) if has_errors?
121
- end
125
+ build_classes(
126
+ %(input),
127
+ %(date-input__input),
128
+ %(input--width-#{width}),
129
+ %(input--error) => has_errors?,
130
+ ).prefix(brand)
122
131
  end
123
132
 
124
133
  # if the field has errors we want the govuk_error_summary to
@@ -148,7 +157,7 @@ module GOVUKDesignSystemFormBuilder
148
157
  end
149
158
 
150
159
  def label_classes
151
- %w(label date-input__label).prefix(brand)
160
+ build_classes(%(label), %(date-input__label)).prefix(brand)
152
161
  end
153
162
  end
154
163
  end
@@ -8,7 +8,7 @@ module GOVUKDesignSystemFormBuilder
8
8
  def html
9
9
  return unless has_errors?
10
10
 
11
- tag.span(class: %(#{brand}-error-message), id: error_id) do
11
+ tag.p(class: %(#{brand}-error-message), id: error_id) do
12
12
  safe_join([hidden_prefix, message])
13
13
  end
14
14
  end
@@ -20,7 +20,7 @@ module GOVUKDesignSystemFormBuilder
20
20
  end
21
21
 
22
22
  def message
23
- @builder.object.errors.messages[@attribute_name]&.first
23
+ set_message_safety(@builder.object.errors.messages[@attribute_name]&.first)
24
24
  end
25
25
  end
26
26
  end
@@ -81,7 +81,9 @@ module GOVUKDesignSystemFormBuilder
81
81
  end
82
82
 
83
83
  def list_item(attribute, message, url = nil)
84
- tag.li(link_to(message, url || same_page_link(field_id(attribute)), **link_options))
84
+ target = url || same_page_link(field_id(attribute))
85
+
86
+ tag.li(link_to(set_message_safety(message), target, **link_options))
85
87
  end
86
88
 
87
89
  def same_page_link(target)
@@ -8,6 +8,7 @@ module GOVUKDesignSystemFormBuilder
8
8
  include Traits::Label
9
9
  include Traits::Supplemental
10
10
  include Traits::HTMLAttributes
11
+ include Traits::HTMLClasses
11
12
 
12
13
  def initialize(builder, object_name, attribute_name, hint:, label:, caption:, form_group:, **kwargs, &block)
13
14
  super(builder, object_name, attribute_name, &block)
@@ -40,9 +41,7 @@ module GOVUKDesignSystemFormBuilder
40
41
  end
41
42
 
42
43
  def classes
43
- %w(file-upload).prefix(brand).tap do |c|
44
- c.push(%(#{brand}-file-upload--error)) if has_errors?
45
- end
44
+ build_classes(%(file-upload), %(file-upload--error) => has_errors?).prefix(brand)
46
45
  end
47
46
  end
48
47
  end
@@ -27,7 +27,7 @@ module GOVUKDesignSystemFormBuilder
27
27
  def html
28
28
  return unless active?
29
29
 
30
- content_tag(hint_tag, **hint_options, **@html_attributes) { hint_body }
30
+ tag.div(**hint_options, **@html_attributes) { hint_body }
31
31
  end
32
32
 
33
33
  def hint_id
@@ -42,10 +42,6 @@ module GOVUKDesignSystemFormBuilder
42
42
  { class: classes, id: hint_id }
43
43
  end
44
44
 
45
- def hint_tag
46
- @raw.presence ? 'div' : 'span'
47
- end
48
-
49
45
  def hint_body
50
46
  @raw || @text
51
47
  end
@@ -8,6 +8,7 @@ module GOVUKDesignSystemFormBuilder
8
8
  include Traits::Label
9
9
  include Traits::Supplemental
10
10
  include Traits::HTMLAttributes
11
+ include Traits::HTMLClasses
11
12
 
12
13
  def initialize(builder, object_name, attribute_name, hint:, label:, caption:, rows:, max_words:, max_chars:, threshold:, form_group:, **kwargs, &block)
13
14
  super(builder, object_name, attribute_name, &block)
@@ -42,10 +43,7 @@ module GOVUKDesignSystemFormBuilder
42
43
  end
43
44
 
44
45
  def classes
45
- %w(textarea).prefix(brand).tap do |classes|
46
- classes.push(%(#{brand}-textarea--error)) if has_errors?
47
- classes.push(%(#{brand}-js-character-count)) if limit?
48
- end
46
+ build_classes(%(textarea), %(textarea--error) => has_errors?, %(js-character-count) => limit?).prefix(brand)
49
47
  end
50
48
 
51
49
  def options
@@ -86,7 +84,7 @@ module GOVUKDesignSystemFormBuilder
86
84
  end
87
85
 
88
86
  def limit_description_classes
89
- %w(hint character-count__message).prefix(brand)
87
+ build_classes(%(hint), %(character-count__message)).prefix(brand)
90
88
  end
91
89
 
92
90
  def limit_description_id
@@ -12,6 +12,10 @@ module GOVUKDesignSystemFormBuilder
12
12
  def error_element
13
13
  @error_element ||= Elements::ErrorMessage.new(*bound)
14
14
  end
15
+
16
+ def set_message_safety(message)
17
+ config.trust_error_messages ? message.html_safe : message
18
+ end
15
19
  end
16
20
  end
17
21
  end
@@ -0,0 +1,13 @@
1
+ module GOVUKDesignSystemFormBuilder
2
+ module Traits
3
+ module HTMLClasses
4
+ # combine all the classes in *args with any keys from **kwargs
5
+ # where the value is true. Roughly based on the behaviour from
6
+ # Rails' class_names, but recreated here as that returns a string
7
+ # where we want an array.
8
+ def build_classes(*args, **kwargs)
9
+ (args + kwargs.map { |k, v| k if v }).compact
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,3 +1,3 @@
1
1
  module GOVUKDesignSystemFormBuilder
2
- VERSION = '2.7.6'.freeze
2
+ VERSION = '3.0.0'.freeze
3
3
  end
@@ -71,6 +71,10 @@ module GOVUKDesignSystemFormBuilder
71
71
  #
72
72
  # * +:enable_logger+ controls whether or not the library will emit log
73
73
  # messages via Rails.logger.warn, defaults to +true+
74
+ #
75
+ # * +:trust_error_messages+ call html_safe on error messages before they're
76
+ # rendered. This allows formatting markup to be used to change the display
77
+ # of the error message. Defaults to +false+
74
78
  # ===
75
79
  DEFAULTS = {
76
80
  brand: 'govuk',
@@ -95,7 +99,8 @@ module GOVUKDesignSystemFormBuilder
95
99
  localisation_schema_legend: nil,
96
100
  localisation_schema_caption: nil,
97
101
 
98
- enable_logger: true
102
+ enable_logger: true,
103
+ trust_error_messages: false,
99
104
  }.freeze
100
105
 
101
106
  DEFAULTS.each_key { |k| config_accessor(k) { DEFAULTS[k] } }
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.7.6
4
+ version: 3.0.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-11-17 00:00:00.000000000 Z
11
+ date: 2022-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: deep_merge
@@ -30,56 +30,42 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '6.0'
33
+ version: '6.1'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '6.0'
40
+ version: '6.1'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: activemodel
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '6.0'
47
+ version: '6.1'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '6.0'
54
+ version: '6.1'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: activesupport
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '6.0'
61
+ version: '6.1'
62
62
  type: :runtime
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: '6.0'
69
- - !ruby/object:Gem::Dependency
70
- name: rubocop-govuk
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: 4.1.0
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: 4.1.0
68
+ version: '6.1'
83
69
  - !ruby/object:Gem::Dependency
84
70
  name: pry
85
71
  requirement: !ruby/object:Gem::Requirement
@@ -142,6 +128,20 @@ dependencies:
142
128
  - - "~>"
143
129
  - !ruby/object:Gem::Version
144
130
  version: '5.0'
131
+ - !ruby/object:Gem::Dependency
132
+ name: rubocop-govuk
133
+ requirement: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - "~>"
136
+ - !ruby/object:Gem::Version
137
+ version: 4.2.0
138
+ type: :development
139
+ prerelease: false
140
+ version_requirements: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - "~>"
143
+ - !ruby/object:Gem::Version
144
+ version: 4.2.0
145
145
  - !ruby/object:Gem::Dependency
146
146
  name: simplecov
147
147
  requirement: !ruby/object:Gem::Requirement
@@ -162,14 +162,14 @@ dependencies:
162
162
  requirements:
163
163
  - - "~>"
164
164
  - !ruby/object:Gem::Version
165
- version: 1.3.1
165
+ version: 1.4.1
166
166
  type: :development
167
167
  prerelease: false
168
168
  version_requirements: !ruby/object:Gem::Requirement
169
169
  requirements:
170
170
  - - "~>"
171
171
  - !ruby/object:Gem::Version
172
- version: 1.3.1
172
+ version: 1.4.1
173
173
  - !ruby/object:Gem::Dependency
174
174
  name: nanoc
175
175
  requirement: !ruby/object:Gem::Requirement
@@ -213,33 +213,33 @@ dependencies:
213
213
  - !ruby/object:Gem::Version
214
214
  version: 0.7.0
215
215
  - !ruby/object:Gem::Dependency
216
- name: sassc
216
+ name: sass
217
217
  requirement: !ruby/object:Gem::Requirement
218
218
  requirements:
219
- - - "~>"
219
+ - - ">="
220
220
  - !ruby/object:Gem::Version
221
- version: 2.4.0
221
+ version: '0'
222
222
  type: :development
223
223
  prerelease: false
224
224
  version_requirements: !ruby/object:Gem::Requirement
225
225
  requirements:
226
- - - "~>"
226
+ - - ">="
227
227
  - !ruby/object:Gem::Version
228
- version: 2.4.0
228
+ version: '0'
229
229
  - !ruby/object:Gem::Dependency
230
- name: sass
230
+ name: sassc
231
231
  requirement: !ruby/object:Gem::Requirement
232
232
  requirements:
233
- - - ">="
233
+ - - "~>"
234
234
  - !ruby/object:Gem::Version
235
- version: '0'
235
+ version: 2.4.0
236
236
  type: :development
237
237
  prerelease: false
238
238
  version_requirements: !ruby/object:Gem::Requirement
239
239
  requirements:
240
- - - ">="
240
+ - - "~>"
241
241
  - !ruby/object:Gem::Version
242
- version: '0'
242
+ version: 2.4.0
243
243
  - !ruby/object:Gem::Dependency
244
244
  name: slim
245
245
  requirement: !ruby/object:Gem::Requirement
@@ -255,33 +255,33 @@ dependencies:
255
255
  - !ruby/object:Gem::Version
256
256
  version: 4.1.0
257
257
  - !ruby/object:Gem::Dependency
258
- name: webrick
258
+ name: slim_lint
259
259
  requirement: !ruby/object:Gem::Requirement
260
260
  requirements:
261
261
  - - "~>"
262
262
  - !ruby/object:Gem::Version
263
- version: 1.7.0
263
+ version: 0.22.0
264
264
  type: :development
265
265
  prerelease: false
266
266
  version_requirements: !ruby/object:Gem::Requirement
267
267
  requirements:
268
268
  - - "~>"
269
269
  - !ruby/object:Gem::Version
270
- version: 1.7.0
270
+ version: 0.22.0
271
271
  - !ruby/object:Gem::Dependency
272
- name: slim_lint
272
+ name: webrick
273
273
  requirement: !ruby/object:Gem::Requirement
274
274
  requirements:
275
275
  - - "~>"
276
276
  - !ruby/object:Gem::Version
277
- version: 0.22.0
277
+ version: 1.7.0
278
278
  type: :development
279
279
  prerelease: false
280
280
  version_requirements: !ruby/object:Gem::Requirement
281
281
  requirements:
282
282
  - - "~>"
283
283
  - !ruby/object:Gem::Version
284
- version: 0.22.0
284
+ version: 1.7.0
285
285
  description: A Rails form builder that generates form inputs adhering to the GOV.UK
286
286
  Design System
287
287
  email:
@@ -340,6 +340,7 @@ files:
340
340
  - lib/govuk_design_system_formbuilder/traits/fieldset_item.rb
341
341
  - lib/govuk_design_system_formbuilder/traits/hint.rb
342
342
  - lib/govuk_design_system_formbuilder/traits/html_attributes.rb
343
+ - lib/govuk_design_system_formbuilder/traits/html_classes.rb
343
344
  - lib/govuk_design_system_formbuilder/traits/input.rb
344
345
  - lib/govuk_design_system_formbuilder/traits/label.rb
345
346
  - lib/govuk_design_system_formbuilder/traits/localisation.rb