govuk_design_system_formbuilder 2.5.1 → 2.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/govuk_design_system_formbuilder.rb +1 -1
- data/lib/govuk_design_system_formbuilder/base.rb +0 -8
- data/lib/govuk_design_system_formbuilder/elements/check_boxes/fieldset_check_box.rb +5 -35
- data/lib/govuk_design_system_formbuilder/elements/radios/fieldset_radio_button.rb +6 -31
- data/lib/govuk_design_system_formbuilder/refinements/prefixable_array.rb +9 -0
- data/lib/govuk_design_system_formbuilder/traits/fieldset_item.rb +51 -0
- data/lib/govuk_design_system_formbuilder/traits/html_attributes.rb +10 -17
- data/lib/govuk_design_system_formbuilder/version.rb +1 -1
- metadata +33 -15
- data/lib/govuk_design_system_formbuilder/traits/conditional.rb +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6307ddd694fd135e13d060b9cb742464e8c5579da4d1026dfffaffedb26c8c39
|
4
|
+
data.tar.gz: 7238c7b22b04727d86393822df54284c97a74197b2d887b2bf7f89e27fadfa2a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 63a462903bafafb449b2e6ec8d17e269360fc62fa75fd8f5ffda238a8529f23a6725080de31884c681bb8ce106f806d4e728b88e22a5e89dff96919a90addfc9
|
7
|
+
data.tar.gz: 5f78fdecbd0e4c67b3a9b6ea26854dfd1658a1cbd4da59b01527947ccb4ba89dc1444b39b1ffb03090820142a15fafd25ca2e444a1715259d7216a8a6e84f300
|
data/README.md
CHANGED
@@ -7,7 +7,7 @@
|
|
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.
|
10
|
+
[![GOV.UK Design System Version](https://img.shields.io/badge/GOV.UK%20Design%20System-3.12.0-brightgreen)](https://design-system.service.gov.uk)
|
11
11
|
[![Rails](https://img.shields.io/badge/Ruby-2.6.7%20%E2%95%B1%202.7.3%20%E2%95%B1%203.0.1-E16D6D)](https://www.ruby-lang.org/en/downloads/)
|
12
12
|
[![Ruby](https://img.shields.io/badge/Rails-6.0.3.6%20%E2%95%B1%206.1.3.1-E16D6D)](https://weblog.rubyonrails.org/releases/)
|
13
13
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'deep_merge/rails_compat'
|
2
2
|
require 'active_support/configurable'
|
3
3
|
|
4
|
-
[%w(traits *.rb), %w(*.rb), %w(elements ** *.rb), %w(containers ** *.rb)]
|
4
|
+
[%w(refinements *.rb), %w(traits *.rb), %w(*.rb), %w(elements ** *.rb), %w(containers ** *.rb)]
|
5
5
|
.flat_map { |matcher| Dir.glob(File.join(__dir__, 'govuk_design_system_formbuilder', *matcher)) }
|
6
6
|
.each { |file| require file }
|
7
7
|
|
@@ -1,12 +1,4 @@
|
|
1
1
|
module GOVUKDesignSystemFormBuilder
|
2
|
-
module PrefixableArray
|
3
|
-
refine Array do
|
4
|
-
def prefix(text, delimiter: '-')
|
5
|
-
map { |item| text + delimiter + item }
|
6
|
-
end
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
2
|
class Base
|
11
3
|
delegate :content_tag, :safe_join, :tag, :link_to, :capture, to: :@builder
|
12
4
|
delegate :config, to: GOVUKDesignSystemFormBuilder
|
@@ -2,13 +2,10 @@ module GOVUKDesignSystemFormBuilder
|
|
2
2
|
module Elements
|
3
3
|
module CheckBoxes
|
4
4
|
class FieldsetCheckBox < Base
|
5
|
-
using PrefixableArray
|
6
|
-
|
7
5
|
include Traits::Label
|
8
6
|
include Traits::Hint
|
9
|
-
include Traits::FieldsetItem
|
10
|
-
include Traits::Conditional
|
11
7
|
include Traits::HTMLAttributes
|
8
|
+
include Traits::FieldsetItem
|
12
9
|
|
13
10
|
def initialize(builder, object_name, attribute_name, value, unchecked_value, label:, hint:, link_errors:, multiple:, **kwargs, &block)
|
14
11
|
super(builder, object_name, attribute_name)
|
@@ -21,49 +18,22 @@ module GOVUKDesignSystemFormBuilder
|
|
21
18
|
@link_errors = link_errors
|
22
19
|
@html_attributes = kwargs
|
23
20
|
|
24
|
-
|
25
|
-
@conditional_content = wrap_conditional(block)
|
26
|
-
@conditional_id = conditional_id
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def html
|
31
|
-
safe_join([item, @conditional_content])
|
21
|
+
conditional_content(&block)
|
32
22
|
end
|
33
23
|
|
34
24
|
private
|
35
25
|
|
36
|
-
def
|
37
|
-
|
38
|
-
safe_join([check_box, label_element, hint_element])
|
39
|
-
end
|
26
|
+
def input_type
|
27
|
+
:checkboxes
|
40
28
|
end
|
41
29
|
|
42
|
-
def
|
30
|
+
def input
|
43
31
|
@builder.check_box(@attribute_name, attributes(@html_attributes), @value, @unchecked_value)
|
44
32
|
end
|
45
33
|
|
46
|
-
def options
|
47
|
-
{
|
48
|
-
id: field_id(link_errors: @link_errors),
|
49
|
-
class: classes,
|
50
|
-
multiple: @multiple,
|
51
|
-
aria: { describedby: [hint_id] },
|
52
|
-
data: { 'aria-controls' => @conditional_id }
|
53
|
-
}
|
54
|
-
end
|
55
|
-
|
56
|
-
def classes
|
57
|
-
%w(checkboxes__input).prefix(brand)
|
58
|
-
end
|
59
|
-
|
60
34
|
def fieldset_options
|
61
35
|
{ checkbox: true }
|
62
36
|
end
|
63
|
-
|
64
|
-
def conditional_classes
|
65
|
-
%w(checkboxes__conditional checkboxes__conditional--hidden).prefix(brand)
|
66
|
-
end
|
67
37
|
end
|
68
38
|
end
|
69
39
|
end
|
@@ -2,13 +2,10 @@ module GOVUKDesignSystemFormBuilder
|
|
2
2
|
module Elements
|
3
3
|
module Radios
|
4
4
|
class FieldsetRadioButton < Base
|
5
|
-
using PrefixableArray
|
6
|
-
|
7
5
|
include Traits::Label
|
8
6
|
include Traits::Hint
|
9
|
-
include Traits::FieldsetItem
|
10
|
-
include Traits::Conditional
|
11
7
|
include Traits::HTMLAttributes
|
8
|
+
include Traits::FieldsetItem
|
12
9
|
|
13
10
|
def initialize(builder, object_name, attribute_name, value, label:, hint:, link_errors:, **kwargs, &block)
|
14
11
|
super(builder, object_name, attribute_name)
|
@@ -19,43 +16,21 @@ module GOVUKDesignSystemFormBuilder
|
|
19
16
|
@link_errors = has_errors? && link_errors
|
20
17
|
@html_attributes = kwargs
|
21
18
|
|
22
|
-
|
23
|
-
@conditional_content = wrap_conditional(block)
|
24
|
-
@conditional_id = conditional_id
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def html
|
29
|
-
safe_join([radio, @conditional_content])
|
19
|
+
conditional_content(&block)
|
30
20
|
end
|
31
21
|
|
32
22
|
private
|
33
23
|
|
34
|
-
def
|
35
|
-
|
36
|
-
safe_join([input, label_element, hint_element])
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def fieldset_options
|
41
|
-
{ radio: true }
|
24
|
+
def input_type
|
25
|
+
:radios
|
42
26
|
end
|
43
27
|
|
44
28
|
def input
|
45
29
|
@builder.radio_button(@attribute_name, @value, **attributes(@html_attributes))
|
46
30
|
end
|
47
31
|
|
48
|
-
def
|
49
|
-
{
|
50
|
-
id: field_id(link_errors: @link_errors),
|
51
|
-
aria: { describedby: [hint_id] },
|
52
|
-
data: { 'aria-controls' => @conditional_id },
|
53
|
-
class: %w(radios__input).prefix(brand)
|
54
|
-
}
|
55
|
-
end
|
56
|
-
|
57
|
-
def conditional_classes
|
58
|
-
%w(radios__conditional radios__conditional--hidden).prefix(brand)
|
32
|
+
def fieldset_options
|
33
|
+
{ radio: true }
|
59
34
|
end
|
60
35
|
end
|
61
36
|
end
|
@@ -1,8 +1,38 @@
|
|
1
1
|
module GOVUKDesignSystemFormBuilder
|
2
2
|
module Traits
|
3
3
|
module FieldsetItem
|
4
|
+
using PrefixableArray
|
5
|
+
|
6
|
+
def html
|
7
|
+
safe_join([item, @conditional])
|
8
|
+
end
|
9
|
+
|
4
10
|
private
|
5
11
|
|
12
|
+
def class_prefix
|
13
|
+
%(#{brand}-#{input_type})
|
14
|
+
end
|
15
|
+
|
16
|
+
def item
|
17
|
+
tag.div(class: %(#{class_prefix}__item)) do
|
18
|
+
safe_join([input, label_element, hint_element])
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def options
|
23
|
+
{
|
24
|
+
id: field_id(link_errors: @link_errors),
|
25
|
+
class: classes,
|
26
|
+
multiple: @multiple,
|
27
|
+
aria: { describedby: [hint_id] },
|
28
|
+
data: { 'aria-controls' => @conditional_id }
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
def classes
|
33
|
+
[%(#{class_prefix}__input)]
|
34
|
+
end
|
35
|
+
|
6
36
|
def label_element
|
7
37
|
@label_element ||= if @label.nil?
|
8
38
|
Elements::Null.new
|
@@ -26,6 +56,27 @@ module GOVUKDesignSystemFormBuilder
|
|
26
56
|
def hint_options
|
27
57
|
{ value: @value }.merge(fieldset_options)
|
28
58
|
end
|
59
|
+
|
60
|
+
def conditional_id
|
61
|
+
build_id('conditional')
|
62
|
+
end
|
63
|
+
|
64
|
+
def conditional_content(&block)
|
65
|
+
if (conditional_block_content = block_given? && block.call.presence)
|
66
|
+
@conditional = conditional_container(conditional_block_content)
|
67
|
+
@conditional_id = conditional_id
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def conditional_container(content)
|
72
|
+
tag.div(class: conditional_classes, id: conditional_id) do
|
73
|
+
capture { content }
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def conditional_classes
|
78
|
+
%w(__conditional __conditional--hidden).prefix(class_prefix, delimiter: nil)
|
79
|
+
end
|
29
80
|
end
|
30
81
|
end
|
31
82
|
end
|
@@ -6,16 +6,11 @@ module GOVUKDesignSystemFormBuilder
|
|
6
6
|
# present
|
7
7
|
# * joins the arrays into strings to maintain Rails 6.0.3 compatibility
|
8
8
|
class Attributes
|
9
|
-
#
|
10
|
-
#
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
%i(title),
|
15
|
-
%i(alt),
|
16
|
-
%i(href),
|
17
|
-
%i(aria label)
|
18
|
-
].freeze
|
9
|
+
# Rather than attempt to combine these attributes, just overwrite the
|
10
|
+
# form internally-generated values with those that are passed in. This
|
11
|
+
# prevents the merge/unique value logic from affecting the content
|
12
|
+
# (i.e. by remvoving duplicated words).
|
13
|
+
UNMERGEABLE = [%i(id), %i(value), %i(title), %i(alt), %i(href), %i(aria label)].freeze
|
19
14
|
|
20
15
|
def initialize(defaults, custom)
|
21
16
|
@merged = defaults.deeper_merge(deep_split_values(custom))
|
@@ -33,19 +28,17 @@ module GOVUKDesignSystemFormBuilder
|
|
33
28
|
when Hash
|
34
29
|
deep_split_values(value, key)
|
35
30
|
when String
|
36
|
-
|
31
|
+
split_mergeable(key, value, parent)
|
37
32
|
else
|
38
33
|
value
|
39
34
|
end
|
40
35
|
end
|
41
36
|
end
|
42
37
|
|
43
|
-
def
|
44
|
-
if [parent, key].compact.in?(
|
45
|
-
|
46
|
-
|
47
|
-
value.split
|
48
|
-
end
|
38
|
+
def split_mergeable(key, value, parent = nil)
|
39
|
+
return value if [parent, key].compact.in?(UNMERGEABLE)
|
40
|
+
|
41
|
+
value.split
|
49
42
|
end
|
50
43
|
|
51
44
|
def deep_join_values(hash)
|
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.5.
|
4
|
+
version: 2.5.2
|
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
|
+
date: 2021-06-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: deep_merge
|
@@ -28,58 +28,76 @@ dependencies:
|
|
28
28
|
name: actionview
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 6.1.3.1
|
31
34
|
- - ">="
|
32
35
|
- !ruby/object:Gem::Version
|
33
|
-
version: '6.
|
36
|
+
version: '6.1'
|
34
37
|
type: :runtime
|
35
38
|
prerelease: false
|
36
39
|
version_requirements: !ruby/object:Gem::Requirement
|
37
40
|
requirements:
|
41
|
+
- - "~>"
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 6.1.3.1
|
38
44
|
- - ">="
|
39
45
|
- !ruby/object:Gem::Version
|
40
|
-
version: '6.
|
46
|
+
version: '6.1'
|
41
47
|
- !ruby/object:Gem::Dependency
|
42
48
|
name: activemodel
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|
44
50
|
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 6.1.3.1
|
45
54
|
- - ">="
|
46
55
|
- !ruby/object:Gem::Version
|
47
|
-
version: '6.
|
56
|
+
version: '6.1'
|
48
57
|
type: :runtime
|
49
58
|
prerelease: false
|
50
59
|
version_requirements: !ruby/object:Gem::Requirement
|
51
60
|
requirements:
|
61
|
+
- - "~>"
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: 6.1.3.1
|
52
64
|
- - ">="
|
53
65
|
- !ruby/object:Gem::Version
|
54
|
-
version: '6.
|
66
|
+
version: '6.1'
|
55
67
|
- !ruby/object:Gem::Dependency
|
56
68
|
name: activesupport
|
57
69
|
requirement: !ruby/object:Gem::Requirement
|
58
70
|
requirements:
|
71
|
+
- - "~>"
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: 6.1.3.1
|
59
74
|
- - ">="
|
60
75
|
- !ruby/object:Gem::Version
|
61
|
-
version: '6.
|
76
|
+
version: '6.1'
|
62
77
|
type: :runtime
|
63
78
|
prerelease: false
|
64
79
|
version_requirements: !ruby/object:Gem::Requirement
|
65
80
|
requirements:
|
81
|
+
- - "~>"
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: 6.1.3.1
|
66
84
|
- - ">="
|
67
85
|
- !ruby/object:Gem::Version
|
68
|
-
version: '6.
|
86
|
+
version: '6.1'
|
69
87
|
- !ruby/object:Gem::Dependency
|
70
88
|
name: rubocop-govuk
|
71
89
|
requirement: !ruby/object:Gem::Requirement
|
72
90
|
requirements:
|
73
|
-
- -
|
91
|
+
- - "~>"
|
74
92
|
- !ruby/object:Gem::Version
|
75
|
-
version: 4.0.0
|
93
|
+
version: 4.0.0
|
76
94
|
type: :development
|
77
95
|
prerelease: false
|
78
96
|
version_requirements: !ruby/object:Gem::Requirement
|
79
97
|
requirements:
|
80
|
-
- -
|
98
|
+
- - "~>"
|
81
99
|
- !ruby/object:Gem::Version
|
82
|
-
version: 4.0.0
|
100
|
+
version: 4.0.0
|
83
101
|
- !ruby/object:Gem::Dependency
|
84
102
|
name: pry
|
85
103
|
requirement: !ruby/object:Gem::Requirement
|
@@ -274,14 +292,14 @@ dependencies:
|
|
274
292
|
requirements:
|
275
293
|
- - "~>"
|
276
294
|
- !ruby/object:Gem::Version
|
277
|
-
version: 0.
|
295
|
+
version: 0.21.1
|
278
296
|
type: :development
|
279
297
|
prerelease: false
|
280
298
|
version_requirements: !ruby/object:Gem::Requirement
|
281
299
|
requirements:
|
282
300
|
- - "~>"
|
283
301
|
- !ruby/object:Gem::Version
|
284
|
-
version: 0.
|
302
|
+
version: 0.21.1
|
285
303
|
description: A Rails form builder that generates form inputs adhering to the GOV.UK
|
286
304
|
Design System
|
287
305
|
email:
|
@@ -330,9 +348,9 @@ files:
|
|
330
348
|
- lib/govuk_design_system_formbuilder/elements/select.rb
|
331
349
|
- lib/govuk_design_system_formbuilder/elements/submit.rb
|
332
350
|
- lib/govuk_design_system_formbuilder/elements/text_area.rb
|
351
|
+
- lib/govuk_design_system_formbuilder/refinements/prefixable_array.rb
|
333
352
|
- lib/govuk_design_system_formbuilder/traits/caption.rb
|
334
353
|
- lib/govuk_design_system_formbuilder/traits/collection_item.rb
|
335
|
-
- lib/govuk_design_system_formbuilder/traits/conditional.rb
|
336
354
|
- lib/govuk_design_system_formbuilder/traits/error.rb
|
337
355
|
- lib/govuk_design_system_formbuilder/traits/fieldset_item.rb
|
338
356
|
- lib/govuk_design_system_formbuilder/traits/hint.rb
|
@@ -1,17 +0,0 @@
|
|
1
|
-
module GOVUKDesignSystemFormBuilder
|
2
|
-
module Traits
|
3
|
-
module Conditional
|
4
|
-
private
|
5
|
-
|
6
|
-
def conditional_id
|
7
|
-
build_id('conditional')
|
8
|
-
end
|
9
|
-
|
10
|
-
def wrap_conditional(block)
|
11
|
-
tag.div(class: conditional_classes, id: conditional_id) do
|
12
|
-
capture { block.call }
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|