govuk_design_system_formbuilder 2.1.3 → 2.1.4

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: 5bf39d8cfcafbc412e81222f437a8a4b6ccd446fbbf8a389a3ce95fc8ac5b403
4
- data.tar.gz: 211f72eccb795874319dcda270d7dd43d79cf446ea4fd4ee1ae20a2bfde35f37
3
+ metadata.gz: 2b243fcaf512a7b1edd2455a06cb36368db533c9aa76661fc907d8725a916ecc
4
+ data.tar.gz: 2ac392952f097e0730dc1d10b4b159d273a17335682ddcf8c8a5d589c7d0e53f
5
5
  SHA512:
6
- metadata.gz: da6cfc65ca96b181110a040339c39073f22652ec3d71dc20124cefe592cfa87d2faba5ddbaa3eed554c511a7775680b82576bd2fcff2152027f1d974b2967bcf
7
- data.tar.gz: 80726be73183e18389a990c66f39b7a19089a87f6ccc252c58eaff92b242e012d34ea656d87898199fff64d00cf778b30df9fcea08bb28e2eca4a4798aa65c9f
6
+ metadata.gz: b4ff3afdcc29348497365e6e04f4a2848c9db92e57fe6db4098a011d5cefd00e3f0a6e38240e7eb4b5776b79a29f36f64785bbfdeb0181b9efed8d5c46813359
7
+ data.tar.gz: 28c9f927dbfbe0b7176184ececf28c6de7ad229613728f7e57d5aed9d5f93c2d49d2d81ff474bad47a809a85dd847a4658d0af9695cdfa5a10a9705272ed926c
@@ -38,7 +38,14 @@ module GOVUKDesignSystemFormBuilder
38
38
  end
39
39
 
40
40
  def legend_options
41
- { legend: @legend, caption: @caption }
41
+ case @legend
42
+ when Hash
43
+ @legend.merge(caption: @caption)
44
+ when Proc
45
+ { content: @legend }
46
+ else
47
+ fail(ArgumentError, %(legend must be a Proc or Hash))
48
+ end
42
49
  end
43
50
  end
44
51
  end
@@ -4,46 +4,39 @@ module GOVUKDesignSystemFormBuilder
4
4
  include Traits::Caption
5
5
  include Traits::Localisation
6
6
 
7
- def initialize(builder, object_name, attribute_name, legend:, caption:, **kwargs)
7
+ def initialize(builder, object_name, attribute_name, text: nil, size: config.default_legend_size, hidden: false, tag: config.default_legend_tag, caption: nil, content: nil, **kwargs)
8
8
  super(builder, object_name, attribute_name)
9
9
 
10
- @html_attributes = kwargs
11
-
12
- case legend
13
- when NilClass
14
- # do nothing
15
- when Proc
16
- @raw = capture { legend.call }
17
- when Hash
18
- defaults.merge(legend).tap do |l|
19
- @text = retrieve_text(l.dig(:text))
20
- @hidden = l.dig(:hidden)
21
- @tag = l.dig(:tag)
22
- @size = l.dig(:size)
23
- @caption = caption
24
- end
10
+ if content
11
+ @content = capture { content.call }
25
12
  else
26
- fail(ArgumentError, %(legend must be a NilClass, Proc or Hash))
13
+ @text = retrieve_text(text)
14
+ @tag = tag
15
+ @size_class = size_class(size)
16
+ @tag = tag
17
+ @caption = caption
18
+ @hidden = hidden
19
+ @html_attributes = kwargs
27
20
  end
28
21
  end
29
22
 
30
23
  def html
31
- @raw || content
24
+ @content || legend
32
25
  end
33
26
 
34
27
  private
35
28
 
36
29
  def active?
37
- [@text, @raw].any?(&:present?)
30
+ [@text, @content].any?(&:present?)
38
31
  end
39
32
 
40
- def content
33
+ def legend
41
34
  return unless active?
42
35
 
43
- tag.legend(legend_text, class: classes, **@html_attributes)
36
+ tag.legend(legend_content, class: classes, **@html_attributes)
44
37
  end
45
38
 
46
- def legend_text
39
+ def legend_content
47
40
  caption_and_text = safe_join([caption_element, @text])
48
41
 
49
42
  if @tag.present?
@@ -58,17 +51,14 @@ module GOVUKDesignSystemFormBuilder
58
51
  end
59
52
 
60
53
  def classes
61
- [%(#{brand}-fieldset__legend), size_class, visually_hidden_class].compact
54
+ [%(#{brand}-fieldset__legend), @size_class, visually_hidden_class].compact
62
55
  end
63
56
 
64
- def size_class
65
- case @size
66
- when 'xl' then %(#{brand}-fieldset__legend--xl)
67
- when 'l' then %(#{brand}-fieldset__legend--l)
68
- when 'm' then %(#{brand}-fieldset__legend--m)
69
- when 's' then %(#{brand}-fieldset__legend--s)
57
+ def size_class(size)
58
+ if size.in?(%w(xl l m s))
59
+ %(#{brand}-fieldset__legend--#{size})
70
60
  else
71
- fail "invalid size '#{@size}', must be xl, l, m or s"
61
+ fail "invalid size '#{size}', must be xl, l, m or s"
72
62
  end
73
63
  end
74
64
 
@@ -79,15 +69,6 @@ module GOVUKDesignSystemFormBuilder
79
69
  def heading_classes
80
70
  %(#{brand}-fieldset__heading)
81
71
  end
82
-
83
- def defaults
84
- {
85
- hidden: false,
86
- text: nil,
87
- tag: config.default_legend_tag,
88
- size: config.default_legend_size
89
- }
90
- end
91
72
  end
92
73
  end
93
74
  end
@@ -1,3 +1,3 @@
1
1
  module GOVUKDesignSystemFormBuilder
2
- VERSION = '2.1.3'.freeze
2
+ VERSION = '2.1.4'.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.3
4
+ version: 2.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Yates
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-03 00:00:00.000000000 Z
11
+ date: 2020-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionview