govuk_design_system_formbuilder 3.1.2 → 3.2.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: a538f7ffa0545474cbf27c732593366f6db00bb2941301ea8b747fd82dcb1f53
4
- data.tar.gz: 478a366c7d960553dd74095ac6ac63209883b75701dc2732e10c47106a52e169
3
+ metadata.gz: 23f730aaf4ab5716aabec97d5becffbfae9e7e4f5fcab7ccc0889f3e1989b733
4
+ data.tar.gz: 381ebbd696bf0de076b1218c40f255bd3d30badbfbb15ea7388a3b1eb384be46
5
5
  SHA512:
6
- metadata.gz: 1eb3291b77100cdd0f55db025e20d623ced134e966498c66cc949ecc4ee70ca132de885959ffaefb67fcce0a19aac0d587c620ffaccdca6a886c73b28d585f7f
7
- data.tar.gz: 98879a898f28df855ace670efe976749db0a3ab911f9090e096ffd73e803d9b6342e3a5d8a813c7927628e56af833d1ce3d430fe84ef4a53da79bbaf58010b67
6
+ metadata.gz: 03be873f3bdc9826d02282d9e19bbd4314225a70e5913a1fd7b830f8eed1b037fb9cd192d37d5ae73f440cb66e2ee964aac085798f4eb9e8c7dc5521f208c612
7
+ data.tar.gz: c33b0b4c947807befcf25cd6def07b1121fb45703d6a7a36ceeaf56686d4a0919b8a71cd848ceb0430f178a65e3e93bb970ec4c5a23db27afad087fff9678a3e
data/README.md CHANGED
@@ -6,15 +6,15 @@
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
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
- [![GOV.UK Design System Version](https://img.shields.io/badge/GOV.UK%20Design%20System-4.3.0-brightgreen)](https://design-system.service.gov.uk)
10
- [![Rails](https://img.shields.io/badge/Rails-6.1.5%20%E2%95%B1%207.0.3-E16D6D)](https://weblog.rubyonrails.org/releases/)
9
+ [![GOV.UK Design System Version](https://img.shields.io/badge/GOV.UK%20Design%20System-4.3.1-brightgreen)](https://design-system.service.gov.uk)
10
+ [![Rails](https://img.shields.io/badge/Rails-6.1.7%20%E2%95%B1%207.0.4-E16D6D)](https://weblog.rubyonrails.org/releases/)
11
11
  [![Ruby](https://img.shields.io/badge/Ruby-2.7.6%20%20%E2%95%B1%203.0.4%20%20%E2%95%B1%203.1.2-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
 
15
15
  It is intended to make creating forms **quick**, **easy** and **familiar** for Ruby on Rails developers.
16
16
 
17
- ## Documentation 📚
17
+ ## Documentation
18
18
 
19
19
  The gem comes with [a full guide](https://govuk-form-builder.netlify.app/) that
20
20
  covers most aspects of day-to-day use, along with code and output examples. The
@@ -23,7 +23,7 @@ be up to date.
23
23
 
24
24
  [![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)
25
25
 
26
- ## What's included 🧳
26
+ ## What's included
27
27
 
28
28
  * 100% compatibility with the GOV.UK Design System
29
29
  * Full control of labels, legends, hints, captions and fieldsets
@@ -38,7 +38,7 @@ be up to date.
38
38
  * An exhaustive test suite
39
39
  * [Extensive technical documentation](https://www.rubydoc.info/gems/govuk_design_system_formbuilder/GOVUKDesignSystemFormBuilder/Builder)
40
40
 
41
- ## Installation 🏗
41
+ ## Installation
42
42
 
43
43
  You can install the form builder gem by running the `gem install
44
44
  govuk_design_system_formbuilder` or by adding the following line
@@ -58,10 +58,10 @@ pre-configured template:
58
58
  * [DfE Rails Template](https://github.com/DFE-Digital/rails-template)
59
59
  * [DEFRA Ruby Template](https://github.com/DEFRA/defra-ruby-template)
60
60
 
61
- ## Setup 🔧
61
+ ## Setup
62
62
 
63
63
  To use the form builder in an ad hoc basis you can specify it as an argument to
64
- `form_for` or `form_with`. These examples are written in [Slim](https://slim-lang.com) but
64
+ `form_for` or `form_with`. These examples are written in [Slim](https://github.com/slim-template/slim) but
65
65
  other templating languages like ERB and [Haml](https://haml.info/) work just as well.
66
66
 
67
67
  ```slim
@@ -97,7 +97,7 @@ Now we can get started!
97
97
  = f.govuk_submit 'Away we go!'
98
98
  ```
99
99
 
100
- ## Developing and running the tests 👨🏻‍🏭
100
+ ## Developing and running the tests
101
101
 
102
102
  The form builder is tested with RSpec. To run all the tests first ensure that
103
103
  the development and testing prerequisite gems are installed. At the root of a
@@ -113,7 +113,7 @@ Now, if everything was successful, run RSpec:
113
113
  bundle exec rspec
114
114
  ```
115
115
 
116
- ## Contributing 📦
116
+ ## Contributing
117
117
 
118
118
  Bug reports and feature requests are most welcome, please raise an issue or
119
119
  submit a pull request.
@@ -143,7 +143,12 @@ here are a few from the <abbr title="Department for Education">DfE</abbr>, <abbr
143
143
  * [Trade Tariff duty calculator](https://www.github.com/trade-tariff/trade-tariff-duty-calculator)
144
144
  * [Report your official development assistance](https://www.github.com/UKGovernmentBEIS/beis-report-official-development-assistance)
145
145
 
146
- ## Thanks 👩🏽‍⚖️
146
+ ## Form building services using this library
147
+
148
+ * [MoJ Forms](https://moj-forms.service.justice.gov.uk/)
149
+ * [GOV.UK Forms](https://www.forms.service.gov.uk/)
150
+
151
+ ## Thanks
147
152
 
148
153
  This project was inspired by [Ministry of Justice's GovukElementsFormBuilder](https://github.com/ministryofjustice/govuk_elements_form_builder),
149
154
  but is leaner, more modular and written in a more idiomatic style.
@@ -2,6 +2,8 @@ module GOVUKDesignSystemFormBuilder
2
2
  module Elements
3
3
  class Caption < Base
4
4
  include Traits::Localisation
5
+ include Traits::HTMLAttributes
6
+ include Traits::HTMLClasses
5
7
 
6
8
  def initialize(builder, object_name, attribute_name, text: nil, size: config.default_caption_size, **kwargs)
7
9
  super(builder, object_name, attribute_name)
@@ -14,11 +16,15 @@ module GOVUKDesignSystemFormBuilder
14
16
  def html
15
17
  return unless active?
16
18
 
17
- tag.span(@text, class: @size_class, **@html_attributes)
19
+ tag.span(@text, **attributes(@html_attributes))
18
20
  end
19
21
 
20
22
  private
21
23
 
24
+ def options
25
+ { class: @size_class }
26
+ end
27
+
22
28
  def active?
23
29
  @text.present?
24
30
  end
@@ -28,13 +34,9 @@ module GOVUKDesignSystemFormBuilder
28
34
  end
29
35
 
30
36
  def size_class(size)
31
- case size
32
- when 'xl' then %(#{brand}-caption-xl)
33
- when 'l' then %(#{brand}-caption-l)
34
- when 'm' then %(#{brand}-caption-m)
35
- else
36
- fail ArgumentError, "invalid size '#{size}', must be xl, l or m"
37
- end
37
+ fail ArgumentError, "invalid size '#{size}', must be xl, l or m" unless size.in?(%w(xl l m))
38
+
39
+ %(#{brand}-caption-#{size})
38
40
  end
39
41
  end
40
42
  end
@@ -4,6 +4,8 @@ module GOVUKDesignSystemFormBuilder
4
4
  using PrefixableArray
5
5
 
6
6
  include Traits::Localisation
7
+ include Traits::HTMLAttributes
8
+ include Traits::HTMLClasses
7
9
 
8
10
  def initialize(builder, object_name, attribute_name, value: nil, text: nil, content: nil, radio: false, checkbox: false, **kwargs)
9
11
  super(builder, object_name, attribute_name)
@@ -27,7 +29,7 @@ module GOVUKDesignSystemFormBuilder
27
29
  def html
28
30
  return unless active?
29
31
 
30
- tag.div(**hint_options, **@html_attributes) { hint_body }
32
+ tag.div(**attributes(@html_attributes)) { hint_body }
31
33
  end
32
34
 
33
35
  def hint_id
@@ -38,7 +40,7 @@ module GOVUKDesignSystemFormBuilder
38
40
 
39
41
  private
40
42
 
41
- def hint_options
43
+ def options
42
44
  { class: classes, id: hint_id }
43
45
  end
44
46
 
@@ -5,6 +5,8 @@ module GOVUKDesignSystemFormBuilder
5
5
 
6
6
  include Traits::Caption
7
7
  include Traits::Localisation
8
+ include Traits::HTMLAttributes
9
+ include Traits::HTMLClasses
8
10
 
9
11
  def initialize(builder, object_name, attribute_name, text: nil, value: nil, size: nil, hidden: false, radio: false, checkbox: false, tag: nil, link_errors: true, content: nil, caption: nil, **kwargs)
10
12
  super(builder, object_name, attribute_name)
@@ -44,7 +46,7 @@ module GOVUKDesignSystemFormBuilder
44
46
  private
45
47
 
46
48
  def label
47
- @builder.label(@attribute_name, **options, **@html_attributes) do
49
+ @builder.label(@attribute_name, **attributes(@html_attributes)) do
48
50
  @content || safe_join([caption, @text])
49
51
  end
50
52
  end
@@ -63,7 +65,7 @@ module GOVUKDesignSystemFormBuilder
63
65
  {
64
66
  value: @value,
65
67
  for: field_id(link_errors: @link_errors),
66
- class: %w(label).prefix(brand).push(@size_class, @weight_class, radio_class, checkbox_class).compact
68
+ class: classes
67
69
  }
68
70
  end
69
71
 
@@ -71,28 +73,22 @@ module GOVUKDesignSystemFormBuilder
71
73
  caption_element.html unless [@radio, @checkbox].any?
72
74
  end
73
75
 
74
- def radio_class
75
- return unless @radio
76
-
77
- %(#{brand}-radios__label)
76
+ def classes
77
+ build_classes(
78
+ %(label),
79
+ @size_class,
80
+ @weight_class,
81
+ %(radios__label) => @radio,
82
+ %(checkboxes__label) => @checkbox,
83
+ ).prefix(brand)
78
84
  end
79
85
 
80
- def checkbox_class
81
- return unless @checkbox
86
+ def size_class(size)
87
+ return if size.blank?
82
88
 
83
- %(#{brand}-checkboxes__label)
84
- end
89
+ fail "invalid size '#{size}', must be xl, l, m, s or nil" unless size.in?(%w(xl l m s))
85
90
 
86
- def size_class(size)
87
- case size
88
- when 'xl' then %(#{brand}-label--xl)
89
- when 'l' then %(#{brand}-label--l)
90
- when 'm' then %(#{brand}-label--m)
91
- when 's' then %(#{brand}-label--s)
92
- when nil then nil
93
- else
94
- fail "invalid size '#{size}', must be xl, l, m, s or nil"
95
- end
91
+ %(label--#{size})
96
92
  end
97
93
  end
98
94
  end
@@ -1,8 +1,12 @@
1
1
  module GOVUKDesignSystemFormBuilder
2
2
  module Elements
3
3
  class Legend < Base
4
+ using PrefixableArray
5
+
4
6
  include Traits::Caption
5
7
  include Traits::Localisation
8
+ include Traits::HTMLAttributes
9
+ include Traits::HTMLClasses
6
10
 
7
11
  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
12
  super(builder, object_name, attribute_name)
@@ -33,7 +37,19 @@ module GOVUKDesignSystemFormBuilder
33
37
  def legend
34
38
  return unless active?
35
39
 
36
- tag.legend(legend_content, class: classes, **@html_attributes)
40
+ tag.legend(legend_content, **attributes(@html_attributes))
41
+ end
42
+
43
+ def options
44
+ { class: classes }
45
+ end
46
+
47
+ def classes
48
+ build_classes(
49
+ %(fieldset__legend),
50
+ @size_class,
51
+ %(visually-hidden) => @hidden
52
+ ).prefix(brand)
37
53
  end
38
54
 
39
55
  def legend_content
@@ -48,20 +64,10 @@ module GOVUKDesignSystemFormBuilder
48
64
  [supplied_text, localised_text(:legend), @attribute_name&.capitalize].find(&:presence)
49
65
  end
50
66
 
51
- def classes
52
- [%(#{brand}-fieldset__legend), @size_class, visually_hidden_class].compact
53
- end
54
-
55
67
  def size_class(size)
56
- if size.in?(%w(xl l m s))
57
- %(#{brand}-fieldset__legend--#{size})
58
- else
59
- fail "invalid size '#{size}', must be xl, l, m or s"
60
- end
61
- end
68
+ fail "invalid size '#{size}', must be xl, l, m or s" unless size.in?(%w(xl l m s))
62
69
 
63
- def visually_hidden_class
64
- %(#{brand}-visually-hidden) if @hidden
70
+ %(fieldset__legend--#{size})
65
71
  end
66
72
 
67
73
  def heading_classes
@@ -1,3 +1,3 @@
1
1
  module GOVUKDesignSystemFormBuilder
2
- VERSION = '3.1.2'.freeze
2
+ VERSION = '3.2.0'.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: 3.1.2
4
+ version: 3.2.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: 2022-08-15 00:00:00.000000000 Z
11
+ date: 2022-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: html-attributes-utils
@@ -78,14 +78,14 @@ dependencies:
78
78
  requirements:
79
79
  - - "~>"
80
80
  - !ruby/object:Gem::Version
81
- version: 0.13.0
81
+ version: 0.14.1
82
82
  type: :development
83
83
  prerelease: false
84
84
  version_requirements: !ruby/object:Gem::Requirement
85
85
  requirements:
86
86
  - - "~>"
87
87
  - !ruby/object:Gem::Version
88
- version: 0.13.0
88
+ version: 0.14.1
89
89
  - !ruby/object:Gem::Dependency
90
90
  name: pry-byebug
91
91
  requirement: !ruby/object:Gem::Requirement
@@ -126,28 +126,28 @@ dependencies:
126
126
  requirements:
127
127
  - - "~>"
128
128
  - !ruby/object:Gem::Version
129
- version: '5.0'
129
+ version: '6.0'
130
130
  type: :development
131
131
  prerelease: false
132
132
  version_requirements: !ruby/object:Gem::Requirement
133
133
  requirements:
134
134
  - - "~>"
135
135
  - !ruby/object:Gem::Version
136
- version: '5.0'
136
+ version: '6.0'
137
137
  - !ruby/object:Gem::Dependency
138
138
  name: rubocop-govuk
139
139
  requirement: !ruby/object:Gem::Requirement
140
140
  requirements:
141
141
  - - "~>"
142
142
  - !ruby/object:Gem::Version
143
- version: 4.6.0
143
+ version: 4.8.0
144
144
  type: :development
145
145
  prerelease: false
146
146
  version_requirements: !ruby/object:Gem::Requirement
147
147
  requirements:
148
148
  - - "~>"
149
149
  - !ruby/object:Gem::Version
150
- version: 4.6.0
150
+ version: 4.8.0
151
151
  - !ruby/object:Gem::Dependency
152
152
  name: simplecov
153
153
  requirement: !ruby/object:Gem::Requirement
@@ -196,14 +196,14 @@ dependencies:
196
196
  requirements:
197
197
  - - "~>"
198
198
  - !ruby/object:Gem::Version
199
- version: 3.30.0
199
+ version: 4.0.0
200
200
  type: :development
201
201
  prerelease: false
202
202
  version_requirements: !ruby/object:Gem::Requirement
203
203
  requirements:
204
204
  - - "~>"
205
205
  - !ruby/object:Gem::Version
206
- version: 3.30.0
206
+ version: 4.0.0
207
207
  - !ruby/object:Gem::Dependency
208
208
  name: rubypants
209
209
  requirement: !ruby/object:Gem::Requirement