govuk_design_system_formbuilder 0.9.8 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +40 -35
- data/lib/govuk_design_system_formbuilder/base.rb +21 -46
- data/lib/govuk_design_system_formbuilder/builder.rb +528 -111
- data/lib/govuk_design_system_formbuilder/containers/character_count.rb +8 -7
- data/lib/govuk_design_system_formbuilder/containers/check_boxes.rb +20 -8
- data/lib/govuk_design_system_formbuilder/containers/check_boxes_fieldset.rb +39 -14
- data/lib/govuk_design_system_formbuilder/containers/fieldset.rb +21 -25
- data/lib/govuk_design_system_formbuilder/containers/form_group.rb +20 -9
- data/lib/govuk_design_system_formbuilder/containers/radio_buttons_fieldset.rb +28 -14
- data/lib/govuk_design_system_formbuilder/containers/radios.rb +27 -10
- data/lib/govuk_design_system_formbuilder/containers/supplemental.rb +8 -9
- data/lib/govuk_design_system_formbuilder/elements/caption.rb +41 -0
- data/lib/govuk_design_system_formbuilder/elements/check_boxes/collection.rb +34 -22
- data/lib/govuk_design_system_formbuilder/elements/check_boxes/collection_check_box.rb +28 -18
- data/lib/govuk_design_system_formbuilder/elements/check_boxes/fieldset_check_box.rb +47 -40
- data/lib/govuk_design_system_formbuilder/elements/check_boxes/label.rb +9 -3
- data/lib/govuk_design_system_formbuilder/elements/date.rb +65 -53
- data/lib/govuk_design_system_formbuilder/elements/error_message.rb +13 -8
- data/lib/govuk_design_system_formbuilder/elements/error_summary.rb +30 -31
- data/lib/govuk_design_system_formbuilder/elements/file.rb +31 -24
- data/lib/govuk_design_system_formbuilder/elements/hint.rb +50 -14
- data/lib/govuk_design_system_formbuilder/elements/inputs/email.rb +8 -0
- data/lib/govuk_design_system_formbuilder/elements/inputs/number.rb +6 -0
- data/lib/govuk_design_system_formbuilder/elements/inputs/password.rb +17 -0
- data/lib/govuk_design_system_formbuilder/elements/inputs/phone.rb +6 -0
- data/lib/govuk_design_system_formbuilder/elements/inputs/text.rb +6 -0
- data/lib/govuk_design_system_formbuilder/elements/inputs/url.rb +6 -0
- data/lib/govuk_design_system_formbuilder/elements/label.rb +63 -34
- data/lib/govuk_design_system_formbuilder/elements/legend.rb +87 -0
- data/lib/govuk_design_system_formbuilder/elements/radios/collection.rb +51 -35
- data/lib/govuk_design_system_formbuilder/elements/radios/collection_radio_button.rb +41 -19
- data/lib/govuk_design_system_formbuilder/elements/radios/fieldset_radio_button.rb +37 -24
- data/lib/govuk_design_system_formbuilder/elements/select.rb +34 -32
- data/lib/govuk_design_system_formbuilder/elements/submit.rb +39 -29
- data/lib/govuk_design_system_formbuilder/elements/text_area.rb +76 -32
- data/lib/govuk_design_system_formbuilder/traits/caption.rb +15 -0
- data/lib/govuk_design_system_formbuilder/traits/collection_item.rb +16 -0
- data/lib/govuk_design_system_formbuilder/traits/conditional.rb +17 -0
- data/lib/govuk_design_system_formbuilder/traits/error.rb +17 -0
- data/lib/govuk_design_system_formbuilder/traits/hint.rb +30 -0
- data/lib/govuk_design_system_formbuilder/traits/input.rb +105 -0
- data/lib/govuk_design_system_formbuilder/traits/label.rb +22 -0
- data/lib/govuk_design_system_formbuilder/traits/localisation.rb +51 -0
- data/lib/govuk_design_system_formbuilder/traits/supplemental.rb +17 -0
- data/lib/govuk_design_system_formbuilder/version.rb +1 -1
- data/lib/govuk_design_system_formbuilder.rb +89 -44
- metadata +62 -52
- data/lib/govuk_design_system_formbuilder/elements/check_boxes/hint.rb +0 -30
- data/lib/govuk_design_system_formbuilder/elements/inputs/base.rb +0 -79
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f87c2ecd9fbd0615a3061159d7e87b42254115db22f59c260a6e4209f7ff742d
|
|
4
|
+
data.tar.gz: a167bde412b2158d9ed303af32e730d5ae27876b1ac4ee80d675b9bc81d15126
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4d184b3fa9ed93c35ea9ef15a72bf79f3520632fd3f501d93cc089a2e4b4e73fb73c2078083a9e0785f812802f2b406c972b568033148c9875bf1c4906ee9122
|
|
7
|
+
data.tar.gz: 3462d38207e9220b41bc3bc899d5218bc9ef982e609e2c96f58abbe0d8d20d9e9bd515b1be4566f77b37a4b543e0929a02fd9fa18bb0001815067aa0e6b07ea9
|
data/README.md
CHANGED
|
@@ -2,44 +2,42 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://travis-ci.com/DFE-Digital/govuk_design_system_formbuilder)
|
|
4
4
|
[](https://codeclimate.com/github/DFE-Digital/govuk_design_system_formbuilder/maintainability)
|
|
5
|
-
[](https://codeclimate.com/github/DFE-Digital/govuk_design_system_formbuilder/test_coverage)
|
|
6
5
|
[](https://badge.fury.io/rb/govuk_design_system_formbuilder)
|
|
7
|
-
[](https://rubygems.org/gems/govuk_design_system_formbuilder)
|
|
7
|
+
[](https://codeclimate.com/github/DFE-Digital/govuk_design_system_formbuilder/test_coverage)
|
|
8
|
+
[](https://dependabot.com)
|
|
9
|
+
[](https://github.com/DFE-Digital/govuk_design_system_formbuilder/blob/master/LICENSE)
|
|
10
|
+
[](https://design-system.service.gov.uk)
|
|
8
11
|
|
|
9
|
-
This
|
|
10
|
-
fully-compliant with version 3.3.0 of the [GOV.UK Design System](https://design-system.service.gov.uk/),
|
|
11
|
-
minimising the amount of markup you need to write.
|
|
12
|
+
This library provides an easy-to-use form builder for the [GOV.UK Design System](https://design-system.service.gov.uk/).
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
[0.7.10](https://github.com/DFE-Digital/govuk_design_system_formbuilder/releases/tag/v0.7.10).
|
|
14
|
+
It is intended to make creating forms **quick**, **easy** and **familiar** for Ruby on Rails developers.
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
System is exposed via the API. Adding [JavaScript-enhanced word count
|
|
18
|
-
checking](https://govuk-form-builder.netlify.com/form-elements/text-area/)
|
|
19
|
-
to text areas or [setting the size and weight of
|
|
20
|
-
labels](https://govuk-form-builder.netlify.com/introduction/labels-hints-and-legends/)
|
|
21
|
-
on text fields requires only a single argument.
|
|
16
|
+
## Documentation 📚
|
|
22
17
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
18
|
+
The gem comes with [a full guide](https://govuk-form-builder.netlify.app/) that
|
|
19
|
+
covers most aspects of day-to-day use, along with code and output examples. The
|
|
20
|
+
examples in the guide are generated from the builder itself so it will always
|
|
21
|
+
be up to date.
|
|
22
|
+
|
|
23
|
+
[](https://app.netlify.com/sites/govuk-form-builder/deploys)
|
|
27
24
|
|
|
28
|
-
## What's included
|
|
25
|
+
## What's included 🧳
|
|
29
26
|
|
|
30
27
|
* 100% compatibility with the GOV.UK Design System
|
|
31
|
-
* Full control of labels, hints,
|
|
28
|
+
* Full control of labels, legends, hints, captions and fieldsets
|
|
32
29
|
* No overwriting of Rails' default form helpers
|
|
33
30
|
* Automatic ARIA associations between hints, errors and inputs
|
|
34
31
|
* Most helpers take blocks for arbitrary content
|
|
35
32
|
* Additional params for programmatically adding hints to check box and radio
|
|
36
33
|
button collections
|
|
34
|
+
* Full I18n support
|
|
35
|
+
* Automatic handling of ActiveRecord validation error messages
|
|
37
36
|
* No external dependencies
|
|
38
37
|
* An exhaustive test suite
|
|
39
|
-
* [Extensive documentation](https://www.rubydoc.info/gems/govuk_design_system_formbuilder/GOVUKDesignSystemFormBuilder/Builder)
|
|
40
|
-
* [A full guide](https://govuk-form-builder.netlify.com/)
|
|
38
|
+
* [Extensive technical documentation](https://www.rubydoc.info/gems/govuk_design_system_formbuilder/GOVUKDesignSystemFormBuilder/Builder)
|
|
41
39
|
|
|
42
|
-
## Installation
|
|
40
|
+
## Installation 🏗
|
|
43
41
|
|
|
44
42
|
You can install the form builder gem by running the `gem install
|
|
45
43
|
govuk_design_system_formbuilder` or by adding the following line
|
|
@@ -59,10 +57,11 @@ pre-configured template:
|
|
|
59
57
|
* [DfE Boilerplate](https://github.com/DFE-Digital/govuk-rails-boilerplate)
|
|
60
58
|
* [MoJ Rails Template](https://github.com/ministryofjustice/moj_rails_template)
|
|
61
59
|
|
|
62
|
-
## Setup
|
|
60
|
+
## Setup 🔧
|
|
63
61
|
|
|
64
|
-
To use the form builder in an ad hoc basis you can specify it
|
|
65
|
-
|
|
62
|
+
To use the form builder in an ad hoc basis you can specify it as an argument to
|
|
63
|
+
`form_for` or `form_with`. These examples are written in [Slim](https://slim-lang.com) but
|
|
64
|
+
other templating languages like ERB and [Haml](https://haml.info/) work just as well.
|
|
66
65
|
|
|
67
66
|
```slim
|
|
68
67
|
= form_for @some_object, builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f|
|
|
@@ -77,7 +76,7 @@ class ApplicationController < ActionController::Base
|
|
|
77
76
|
end
|
|
78
77
|
```
|
|
79
78
|
|
|
80
|
-
Now we can get started!
|
|
79
|
+
Now we can get started!
|
|
81
80
|
|
|
82
81
|
```slim
|
|
83
82
|
= form_for @person do |f|
|
|
@@ -92,16 +91,16 @@ Now we can get started! 🎉
|
|
|
92
91
|
:name,
|
|
93
92
|
:description,
|
|
94
93
|
label: { text: "Which department do you work for?" },
|
|
95
|
-
|
|
94
|
+
hint: { text: "If you don't know ask your manager" }
|
|
96
95
|
|
|
97
96
|
= f.govuk_submit 'Away we go!'
|
|
98
97
|
```
|
|
99
98
|
|
|
100
|
-
## Developing and running the tests
|
|
99
|
+
## Developing and running the tests 👨🏻🏭
|
|
101
100
|
|
|
102
|
-
The form builder is
|
|
103
|
-
|
|
104
|
-
|
|
101
|
+
The form builder is tested with RSpec. To run all the tests first ensure that
|
|
102
|
+
the development and testing prerequisite gems are installed. At the root of a
|
|
103
|
+
freshly-cloned repo run:
|
|
105
104
|
|
|
106
105
|
```sh
|
|
107
106
|
bundle
|
|
@@ -110,10 +109,10 @@ bundle
|
|
|
110
109
|
Now, if everything was successful, run RSpec:
|
|
111
110
|
|
|
112
111
|
```sh
|
|
113
|
-
bundle exec rspec
|
|
112
|
+
bundle exec rspec
|
|
114
113
|
```
|
|
115
114
|
|
|
116
|
-
## Contributing
|
|
115
|
+
## Contributing 📦
|
|
117
116
|
|
|
118
117
|
Bug reports and feature requests are most welcome, please raise an issue or
|
|
119
118
|
submit a pull request.
|
|
@@ -122,7 +121,13 @@ Currently we're using [GOVUK Lint](https://github.com/alphagov/govuk-lint) to
|
|
|
122
121
|
ensure code meets the GOV.UK guidelines. Please ensure that any PRs also adhere
|
|
123
122
|
to this standard.
|
|
124
123
|
|
|
125
|
-
|
|
124
|
+
To help keep the logs clean and tidy, please configure git to use your full name:
|
|
125
|
+
|
|
126
|
+
```sh
|
|
127
|
+
git config --global user.name "Julius Hibbert"
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## Thanks 👩🏽⚖️
|
|
126
131
|
|
|
127
|
-
This project was inspired by [
|
|
132
|
+
This project was inspired by [Ministry of Justice's GovukElementsFormBuilder](https://github.com/ministryofjustice/govuk_elements_form_builder),
|
|
128
133
|
but is leaner, more modular and written in a more idiomatic style.
|
|
@@ -1,28 +1,32 @@
|
|
|
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
|
+
|
|
2
10
|
class Base
|
|
3
|
-
delegate :
|
|
11
|
+
delegate :content_tag, :safe_join, :tag, :link_to, :capture, to: :@builder
|
|
12
|
+
delegate :config, to: GOVUKDesignSystemFormBuilder
|
|
4
13
|
|
|
5
14
|
def initialize(builder, object_name, attribute_name, &block)
|
|
6
|
-
@builder
|
|
7
|
-
@object_name
|
|
15
|
+
@builder = builder
|
|
16
|
+
@object_name = object_name
|
|
8
17
|
@attribute_name = attribute_name
|
|
9
|
-
@block_content
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def hint_element
|
|
13
|
-
@hint_element ||= Elements::Hint.new(@builder, @object_name, @attribute_name, @hint_text)
|
|
18
|
+
@block_content = capture { block.call } if block_given?
|
|
14
19
|
end
|
|
15
20
|
|
|
16
|
-
|
|
17
|
-
|
|
21
|
+
# objects that implement #to_s can be passed directly into #safe_join
|
|
22
|
+
def to_s
|
|
23
|
+
html || ''
|
|
18
24
|
end
|
|
19
25
|
|
|
20
|
-
|
|
21
|
-
@label_element ||= Elements::Label.new(@builder, @object_name, @attribute_name, **@label)
|
|
22
|
-
end
|
|
26
|
+
private
|
|
23
27
|
|
|
24
|
-
def
|
|
25
|
-
|
|
28
|
+
def brand(override = nil)
|
|
29
|
+
override || config.brand
|
|
26
30
|
end
|
|
27
31
|
|
|
28
32
|
# returns the id value used for the input
|
|
@@ -46,45 +50,16 @@ module GOVUKDesignSystemFormBuilder
|
|
|
46
50
|
end
|
|
47
51
|
end
|
|
48
52
|
|
|
49
|
-
def hint_id
|
|
50
|
-
return nil unless @hint_text.present?
|
|
51
|
-
|
|
52
|
-
build_id('hint')
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
def error_id
|
|
56
|
-
return nil unless has_errors?
|
|
57
|
-
|
|
58
|
-
build_id('error')
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
def conditional_id
|
|
62
|
-
build_id('conditional')
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
def supplemental_id
|
|
66
|
-
return nil unless @block_content.present?
|
|
67
|
-
|
|
68
|
-
build_id('supplemental')
|
|
69
|
-
end
|
|
70
|
-
|
|
71
53
|
def has_errors?
|
|
72
|
-
@builder.object.errors
|
|
54
|
+
@builder.object.respond_to?(:errors) &&
|
|
55
|
+
@builder.object.errors.any? &&
|
|
73
56
|
@builder.object.errors.messages.dig(@attribute_name).present?
|
|
74
57
|
end
|
|
75
58
|
|
|
76
|
-
def wrap_conditional(block)
|
|
77
|
-
content_tag('div', class: conditional_classes, id: conditional_id) do
|
|
78
|
-
capture { block.call }
|
|
79
|
-
end
|
|
80
|
-
end
|
|
81
|
-
|
|
82
59
|
def described_by(*ids)
|
|
83
60
|
ids.flatten.compact.join(' ').presence
|
|
84
61
|
end
|
|
85
62
|
|
|
86
|
-
private
|
|
87
|
-
|
|
88
63
|
# Builds the values used for HTML id attributes throughout the builder
|
|
89
64
|
#
|
|
90
65
|
# @param id_type [String] a description of the id's type, eg +hint+, +error+
|