formtastic_tristate_radio 0.2.3 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/Gemfile.lock +110 -92
- data/README.md +2 -2
- data/app/inputs/tristate_radio_input.rb +3 -38
- data/formtastic_tristate_radio.gemspec +4 -14
- data/lib/formtastic_tristate_radio/configuration.rb +19 -1
- data/lib/formtastic_tristate_radio/engine.rb +1 -1
- data/lib/formtastic_tristate_radio/i18n/error.rb +46 -0
- data/lib/formtastic_tristate_radio/version.rb +1 -1
- data/lib/formtastic_tristate_radio.rb +2 -4
- metadata +9 -19
- data/lib/formtastic_tristate_radio/missing_translation_error.rb +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 355453579baccba71ec78676458a00f491e1fa6399b82303ddbb56b949246502
|
4
|
+
data.tar.gz: 2077db53b19458a472d679d995c1f4b095f1d7cb18c97a5f477db9652f6cee0b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 963540ae9ce2fbe2ed1877692bcd6c175dce1306014f4a8b4870a514b178e088c4511434f17d2bf92eedea34aaf478d53cfd29f829144430d4f5d6974dc093b8
|
7
|
+
data.tar.gz: 514b296071cc8e6cd9901d568b95a61b4523a2fca1f5107fd413db6b7e6ff8b1e05e5a2dc794ffb29cd8475eda6b56b98f2d232a8626389d8427b796dab66923
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## [0.2.5] - 2021-11-10
|
4
|
+
|
5
|
+
- Corrects an error introduced in 0.2.4
|
6
|
+
- Moves error-related code into a new module
|
7
|
+
- Type-checks the `unset_value` passed into configuration
|
8
|
+
|
9
|
+
## [0.2.4] - 2021-11-09
|
10
|
+
|
11
|
+
- Add translations into most popular languages (although the problem with loading them seems to persist)
|
12
|
+
|
3
13
|
## [0.2.2] - 2021-11-05
|
4
14
|
|
5
15
|
- Make the gem configurable
|
data/Gemfile.lock
CHANGED
@@ -1,84 +1,91 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
formtastic_tristate_radio (0.2.
|
4
|
+
formtastic_tristate_radio (0.2.6)
|
5
5
|
formtastic (>= 3, < 5)
|
6
|
-
rails (>= 4, <
|
6
|
+
rails (>= 4, < 8)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
actioncable (
|
12
|
-
actionpack (=
|
13
|
-
activesupport (=
|
11
|
+
actioncable (7.0.3)
|
12
|
+
actionpack (= 7.0.3)
|
13
|
+
activesupport (= 7.0.3)
|
14
14
|
nio4r (~> 2.0)
|
15
15
|
websocket-driver (>= 0.6.1)
|
16
|
-
actionmailbox (
|
17
|
-
actionpack (=
|
18
|
-
activejob (=
|
19
|
-
activerecord (=
|
20
|
-
activestorage (=
|
21
|
-
activesupport (=
|
16
|
+
actionmailbox (7.0.3)
|
17
|
+
actionpack (= 7.0.3)
|
18
|
+
activejob (= 7.0.3)
|
19
|
+
activerecord (= 7.0.3)
|
20
|
+
activestorage (= 7.0.3)
|
21
|
+
activesupport (= 7.0.3)
|
22
22
|
mail (>= 2.7.1)
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
net-imap
|
24
|
+
net-pop
|
25
|
+
net-smtp
|
26
|
+
actionmailer (7.0.3)
|
27
|
+
actionpack (= 7.0.3)
|
28
|
+
actionview (= 7.0.3)
|
29
|
+
activejob (= 7.0.3)
|
30
|
+
activesupport (= 7.0.3)
|
28
31
|
mail (~> 2.5, >= 2.5.4)
|
32
|
+
net-imap
|
33
|
+
net-pop
|
34
|
+
net-smtp
|
29
35
|
rails-dom-testing (~> 2.0)
|
30
|
-
actionpack (
|
31
|
-
actionview (=
|
32
|
-
activesupport (=
|
33
|
-
rack (~> 2.0, >= 2.0
|
36
|
+
actionpack (7.0.3)
|
37
|
+
actionview (= 7.0.3)
|
38
|
+
activesupport (= 7.0.3)
|
39
|
+
rack (~> 2.0, >= 2.2.0)
|
34
40
|
rack-test (>= 0.6.3)
|
35
41
|
rails-dom-testing (~> 2.0)
|
36
42
|
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
37
|
-
actiontext (
|
38
|
-
actionpack (=
|
39
|
-
activerecord (=
|
40
|
-
activestorage (=
|
41
|
-
activesupport (=
|
43
|
+
actiontext (7.0.3)
|
44
|
+
actionpack (= 7.0.3)
|
45
|
+
activerecord (= 7.0.3)
|
46
|
+
activestorage (= 7.0.3)
|
47
|
+
activesupport (= 7.0.3)
|
48
|
+
globalid (>= 0.6.0)
|
42
49
|
nokogiri (>= 1.8.5)
|
43
|
-
actionview (
|
44
|
-
activesupport (=
|
50
|
+
actionview (7.0.3)
|
51
|
+
activesupport (= 7.0.3)
|
45
52
|
builder (~> 3.1)
|
46
53
|
erubi (~> 1.4)
|
47
54
|
rails-dom-testing (~> 2.0)
|
48
55
|
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
49
|
-
activejob (
|
50
|
-
activesupport (=
|
56
|
+
activejob (7.0.3)
|
57
|
+
activesupport (= 7.0.3)
|
51
58
|
globalid (>= 0.3.6)
|
52
|
-
activemodel (
|
53
|
-
activesupport (=
|
54
|
-
activerecord (
|
55
|
-
activemodel (=
|
56
|
-
activesupport (=
|
57
|
-
activestorage (
|
58
|
-
actionpack (=
|
59
|
-
activejob (=
|
60
|
-
activerecord (=
|
61
|
-
activesupport (=
|
62
|
-
marcel (~> 1.0
|
59
|
+
activemodel (7.0.3)
|
60
|
+
activesupport (= 7.0.3)
|
61
|
+
activerecord (7.0.3)
|
62
|
+
activemodel (= 7.0.3)
|
63
|
+
activesupport (= 7.0.3)
|
64
|
+
activestorage (7.0.3)
|
65
|
+
actionpack (= 7.0.3)
|
66
|
+
activejob (= 7.0.3)
|
67
|
+
activerecord (= 7.0.3)
|
68
|
+
activesupport (= 7.0.3)
|
69
|
+
marcel (~> 1.0)
|
63
70
|
mini_mime (>= 1.1.0)
|
64
|
-
activesupport (
|
71
|
+
activesupport (7.0.3)
|
65
72
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
66
73
|
i18n (>= 1.6, < 2)
|
67
74
|
minitest (>= 5.1)
|
68
75
|
tzinfo (~> 2.0)
|
69
|
-
zeitwerk (~> 2.3)
|
70
76
|
builder (3.2.4)
|
71
|
-
concurrent-ruby (1.1.
|
77
|
+
concurrent-ruby (1.1.10)
|
72
78
|
crass (1.0.6)
|
73
|
-
diff-lcs (1.
|
79
|
+
diff-lcs (1.5.0)
|
80
|
+
digest (3.1.0)
|
74
81
|
erubi (1.10.0)
|
75
82
|
formtastic (4.0.0)
|
76
83
|
actionpack (>= 5.2.0)
|
77
|
-
globalid (0.
|
84
|
+
globalid (1.0.0)
|
78
85
|
activesupport (>= 5.0)
|
79
|
-
i18n (1.
|
86
|
+
i18n (1.10.0)
|
80
87
|
concurrent-ruby (~> 1.0)
|
81
|
-
loofah (2.
|
88
|
+
loofah (2.18.0)
|
82
89
|
crass (~> 1.0.2)
|
83
90
|
nokogiri (>= 1.5.9)
|
84
91
|
mail (2.7.1)
|
@@ -86,72 +93,83 @@ GEM
|
|
86
93
|
marcel (1.0.2)
|
87
94
|
method_source (1.0.0)
|
88
95
|
mini_mime (1.1.2)
|
89
|
-
minitest (5.
|
96
|
+
minitest (5.15.0)
|
97
|
+
net-imap (0.2.3)
|
98
|
+
digest
|
99
|
+
net-protocol
|
100
|
+
strscan
|
101
|
+
net-pop (0.1.1)
|
102
|
+
digest
|
103
|
+
net-protocol
|
104
|
+
timeout
|
105
|
+
net-protocol (0.1.3)
|
106
|
+
timeout
|
107
|
+
net-smtp (0.3.1)
|
108
|
+
digest
|
109
|
+
net-protocol
|
110
|
+
timeout
|
90
111
|
nio4r (2.5.8)
|
91
|
-
nokogiri (1.
|
112
|
+
nokogiri (1.13.6-arm64-darwin)
|
92
113
|
racc (~> 1.4)
|
93
114
|
racc (1.6.0)
|
94
|
-
rack (2.2.3)
|
115
|
+
rack (2.2.3.1)
|
95
116
|
rack-test (1.1.0)
|
96
117
|
rack (>= 1.0, < 3)
|
97
|
-
rails (
|
98
|
-
actioncable (=
|
99
|
-
actionmailbox (=
|
100
|
-
actionmailer (=
|
101
|
-
actionpack (=
|
102
|
-
actiontext (=
|
103
|
-
actionview (=
|
104
|
-
activejob (=
|
105
|
-
activemodel (=
|
106
|
-
activerecord (=
|
107
|
-
activestorage (=
|
108
|
-
activesupport (=
|
118
|
+
rails (7.0.3)
|
119
|
+
actioncable (= 7.0.3)
|
120
|
+
actionmailbox (= 7.0.3)
|
121
|
+
actionmailer (= 7.0.3)
|
122
|
+
actionpack (= 7.0.3)
|
123
|
+
actiontext (= 7.0.3)
|
124
|
+
actionview (= 7.0.3)
|
125
|
+
activejob (= 7.0.3)
|
126
|
+
activemodel (= 7.0.3)
|
127
|
+
activerecord (= 7.0.3)
|
128
|
+
activestorage (= 7.0.3)
|
129
|
+
activesupport (= 7.0.3)
|
109
130
|
bundler (>= 1.15.0)
|
110
|
-
railties (=
|
111
|
-
sprockets-rails (>= 2.0.0)
|
131
|
+
railties (= 7.0.3)
|
112
132
|
rails-dom-testing (2.0.3)
|
113
133
|
activesupport (>= 4.2.0)
|
114
134
|
nokogiri (>= 1.6)
|
115
|
-
rails-html-sanitizer (1.4.
|
135
|
+
rails-html-sanitizer (1.4.3)
|
116
136
|
loofah (~> 2.3)
|
117
|
-
railties (
|
118
|
-
actionpack (=
|
119
|
-
activesupport (=
|
137
|
+
railties (7.0.3)
|
138
|
+
actionpack (= 7.0.3)
|
139
|
+
activesupport (= 7.0.3)
|
120
140
|
method_source
|
121
|
-
rake (>=
|
141
|
+
rake (>= 12.2)
|
122
142
|
thor (~> 1.0)
|
143
|
+
zeitwerk (~> 2.5)
|
123
144
|
rake (13.0.6)
|
124
|
-
rspec (3.
|
125
|
-
rspec-core (~> 3.
|
126
|
-
rspec-expectations (~> 3.
|
127
|
-
rspec-mocks (~> 3.
|
128
|
-
rspec-core (3.
|
129
|
-
rspec-support (~> 3.
|
130
|
-
rspec-expectations (3.
|
145
|
+
rspec (3.11.0)
|
146
|
+
rspec-core (~> 3.11.0)
|
147
|
+
rspec-expectations (~> 3.11.0)
|
148
|
+
rspec-mocks (~> 3.11.0)
|
149
|
+
rspec-core (3.11.0)
|
150
|
+
rspec-support (~> 3.11.0)
|
151
|
+
rspec-expectations (3.11.0)
|
131
152
|
diff-lcs (>= 1.2.0, < 2.0)
|
132
|
-
rspec-support (~> 3.
|
133
|
-
rspec-mocks (3.
|
153
|
+
rspec-support (~> 3.11.0)
|
154
|
+
rspec-mocks (3.11.1)
|
134
155
|
diff-lcs (>= 1.2.0, < 2.0)
|
135
|
-
rspec-support (~> 3.
|
136
|
-
rspec-support (3.
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
sprockets-rails (3.2.2)
|
141
|
-
actionpack (>= 4.0)
|
142
|
-
activesupport (>= 4.0)
|
143
|
-
sprockets (>= 3.0.0)
|
144
|
-
thor (1.1.0)
|
156
|
+
rspec-support (~> 3.11.0)
|
157
|
+
rspec-support (3.11.0)
|
158
|
+
strscan (3.0.3)
|
159
|
+
thor (1.2.1)
|
160
|
+
timeout (0.3.0)
|
145
161
|
tzinfo (2.0.4)
|
146
162
|
concurrent-ruby (~> 1.0)
|
163
|
+
webrick (1.7.0)
|
147
164
|
websocket-driver (0.7.5)
|
148
165
|
websocket-extensions (>= 0.1.0)
|
149
166
|
websocket-extensions (0.1.5)
|
150
|
-
yard (0.9.
|
151
|
-
|
167
|
+
yard (0.9.28)
|
168
|
+
webrick (~> 1.7.0)
|
169
|
+
zeitwerk (2.5.4)
|
152
170
|
|
153
171
|
PLATFORMS
|
154
|
-
|
172
|
+
arm64-darwin-21
|
155
173
|
|
156
174
|
DEPENDENCIES
|
157
175
|
formtastic_tristate_radio!
|
@@ -159,4 +177,4 @@ DEPENDENCIES
|
|
159
177
|
yard (>= 0.9.20, < 1)
|
160
178
|
|
161
179
|
BUNDLED WITH
|
162
|
-
2.
|
180
|
+
2.3.15
|
data/README.md
CHANGED
@@ -62,7 +62,7 @@ ru:
|
|
62
62
|
null: Неизвестно # <- this you must provide youself
|
63
63
|
```
|
64
64
|
|
65
|
-
|
65
|
+
You can override individual translations like so:
|
66
66
|
|
67
67
|
```ruby
|
68
68
|
f.input :attribute, as: :tristate_radio, null: "Your text"
|
@@ -190,8 +190,8 @@ ActiveModel::Type::Boolean.new.cast(:nil) #=> nil
|
|
190
190
|
- [ ] Remove `require_relative "../app/models/active_record/base"` from main file
|
191
191
|
- [x] Make the gem configurable
|
192
192
|
- [x] Pull the key used for “unset” choice value into configuration
|
193
|
+
- [x] Add translations into most popular languages
|
193
194
|
- [ ] Load translations from gem
|
194
|
-
- [ ] Add translations into most popular languages
|
195
195
|
- [ ] Rgister `:tristate_radio` for Boolean columns with `null`
|
196
196
|
- [ ] Decouple `ActiveModel::Type::Boolean` thing from Formtastic things, maybe into a separate gem
|
197
197
|
- [ ] Decouple from Rails
|
@@ -1,11 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "formtastic"
|
4
|
-
|
5
3
|
# It may also be appropriate to put this file in `app/inputs`
|
6
4
|
class TristateRadioInput < Formtastic::Inputs::RadioInput
|
7
5
|
|
8
|
-
#
|
6
|
+
# Now equals `:null`.
|
9
7
|
# Should equal one of `ActiveModel::Type::Boolean::NULL_VALUES`
|
10
8
|
#
|
11
9
|
# Mind ActiveAdmin [status resolving logic](https://github.com/activeadmin/activeadmin/blob/master/lib/active_admin/views/components/status_tag.rb#L51):
|
@@ -14,37 +12,6 @@ class TristateRadioInput < Formtastic::Inputs::RadioInput
|
|
14
12
|
#
|
15
13
|
UNSET_KEY = FormtasticTristateRadio.config.unset_key
|
16
14
|
|
17
|
-
I18N_EXAMPLE_ACTIVEADMIN = <<~YAML.chomp
|
18
|
-
ru:
|
19
|
-
active_admin:
|
20
|
-
status_tag:
|
21
|
-
:yes: Да
|
22
|
-
:no: Нет
|
23
|
-
:#{UNSET_KEY}: Неизвестно
|
24
|
-
YAML
|
25
|
-
|
26
|
-
I18N_EXAMPLE_FORMTASTIC = <<~YAML.chomp
|
27
|
-
ru:
|
28
|
-
formtastic:
|
29
|
-
:yes: Да
|
30
|
-
:no: Нет
|
31
|
-
:#{UNSET_KEY}: Неизвестно
|
32
|
-
YAML
|
33
|
-
|
34
|
-
|
35
|
-
# @note In you have ActiveAdmin installed, it will give you YAML example for ActiveAdmin as well, otherwise only for Formtastic
|
36
|
-
#
|
37
|
-
# @return [String] error message with YAML examples for the “unset” label translation lookup error
|
38
|
-
#
|
39
|
-
def self.missing_i18n_error_msg
|
40
|
-
msg = []
|
41
|
-
msg << "Add translations for the “unset” radio label"
|
42
|
-
msg << ["For radiobutton labels in forms:", I18N_EXAMPLE_FORMTASTIC].join("\n")
|
43
|
-
msg << "Note: “yes”, “no” and some other reserved words are converted into Boolean values in YAML, so you need to quote or symbolize them."
|
44
|
-
msg << ["For ActiveAdmin status tags in index & view tables:", I18N_EXAMPLE_ACTIVEADMIN].join("\n") if !!defined?(ActiveAdmin)
|
45
|
-
msg.join("\n\n")
|
46
|
-
end
|
47
|
-
|
48
15
|
|
49
16
|
# @see https://github.com/formtastic/formtastic/blob/35dc806964403cb2bb0a6074b951ceef906c8581/lib/formtastic/inputs/base/choices.rb#L59 Original Formtastic method
|
50
17
|
#
|
@@ -85,12 +52,10 @@ class TristateRadioInput < Formtastic::Inputs::RadioInput
|
|
85
52
|
#
|
86
53
|
# @return [String] Label of the radio that stands for the unknown choice
|
87
54
|
#
|
88
|
-
# @raise [
|
89
|
-
# @see missing_i18n_error_msg
|
55
|
+
# @raise [FormtasticTristateRadio::I18n::Error] if the translation could not be found
|
90
56
|
#
|
91
57
|
def label_text_for_unset
|
92
|
-
options.fetch(:null, Formtastic::I18n.t(UNSET_KEY)).presence or
|
93
|
-
fail FormtasticTristateRadio::MissingTranslationError.new(self.class.missing_i18n_error_msg)
|
58
|
+
options.fetch(:null, Formtastic::I18n.t(UNSET_KEY)).presence or fail FormtasticTristateRadio::I18n::Error.new(I18n.locale, UNSET_KEY)
|
94
59
|
end
|
95
60
|
|
96
61
|
|
@@ -16,21 +16,11 @@ Gem::Specification.new do |spec|
|
|
16
16
|
|
17
17
|
spec.summary = "Have 3-state radiobuttons instead of a 2-state checkbox for your Boolean columns which can store NULL"
|
18
18
|
spec.description = <<~HEREDOC
|
19
|
-
#{spec.summary}.
|
20
|
-
|
21
|
-
What the gem does?
|
22
|
-
|
19
|
+
#{spec.summary}. This gem:
|
23
20
|
1. Provides a custom Formtastic input type `:tristate_radio` which renders 3 radios (“Yes”, “No”, “Unset”) instead of a checkbox (only where you put it).
|
24
|
-
|
25
|
-
|
26
|
-
|
21
|
+
2. Teaches Rails recognize `"null"` and `"nil"` param values as `nil`
|
22
|
+
3. Encourages you to add translations for ActiveAdmin “status tag” so that `nil` be correctly translated as “Unset” instead of “False”.
|
27
23
|
Does not change controls, you need to turn it on via `as: :tristate_radio` option.
|
28
|
-
|
29
|
-
By defenition Boolean values have 2 states: True & False.
|
30
|
-
|
31
|
-
However, if you store a Boolean value in a database column with no `NOT NULL` restriction, it aquires a 3<sup>d</sup> possible state: `null`.
|
32
|
-
|
33
|
-
Some may consider this practice questionable — I don’t think so. In real life you always have a case when the answer to your question may be only “yes” or “no”, but you don’t know the answer yet. Using a string type column, storing there `"yes"`, `"no"` and `"unset"` + using a state machine + validations — feels overkill to me.
|
34
24
|
HEREDOC
|
35
25
|
|
36
26
|
spec.homepage = "https://github.com/sergeypedan/formtastic-tristate-radio"
|
@@ -53,7 +43,7 @@ Gem::Specification.new do |spec|
|
|
53
43
|
spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
|
54
44
|
|
55
45
|
spec.add_dependency "formtastic", ">= 3", "< 5"
|
56
|
-
spec.add_dependency "rails", ">= 4", "<
|
46
|
+
spec.add_dependency "rails", ">= 4", "< 8"
|
57
47
|
|
58
48
|
spec.add_development_dependency "rspec", "~> 3"
|
59
49
|
spec.add_development_dependency "yard", ">= 0.9.20", "< 1"
|
@@ -14,12 +14,30 @@ module FormtasticTristateRadio
|
|
14
14
|
yield(config)
|
15
15
|
end
|
16
16
|
|
17
|
+
# Configuration block pattern
|
18
|
+
#
|
19
|
+
# @see https://thoughtbot.com/blog/mygem-configure-block
|
20
|
+
# @see https://brandonhilkert.com/blog/ruby-gem-configuration-patterns/
|
21
|
+
#
|
17
22
|
class Configuration
|
18
|
-
attr_accessor :unset_key
|
19
23
|
|
20
24
|
def initialize
|
21
25
|
@unset_key = :null
|
22
26
|
end
|
27
|
+
|
28
|
+
# @!attribute [r] unset_key
|
29
|
+
# @return [Symbol, String] the value of <var>@unset_key</var>
|
30
|
+
#
|
31
|
+
attr_reader :unset_key
|
32
|
+
|
33
|
+
# @return [Symbol, String, Integer] value that was passed into the method
|
34
|
+
#
|
35
|
+
# @raise [TypeError] because no other types seem to make sence here
|
36
|
+
#
|
37
|
+
def unset_key=(value)
|
38
|
+
fail TypeError, "`unset_key` must be a Symbol, String or Integer" unless [Symbol, String, Integer].include? value.class
|
39
|
+
@unset_key = value
|
40
|
+
end
|
23
41
|
end
|
24
42
|
|
25
43
|
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module FormtasticTristateRadio
|
4
4
|
|
5
5
|
# This is standard Rails way to autoload gem’s contents dynamically as an “engine”
|
6
|
-
# https://guides.rubyonrails.org/engines.html
|
6
|
+
# @see https://guides.rubyonrails.org/engines.html Rails guide on engines
|
7
7
|
#
|
8
8
|
class Engine < ::Rails::Engine
|
9
9
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module FormtasticTristateRadio
|
4
|
+
module I18n
|
5
|
+
|
6
|
+
EXAMPLE_ACTIVEADMIN = <<~YAML.chomp
|
7
|
+
ru:
|
8
|
+
active_admin:
|
9
|
+
status_tag:
|
10
|
+
:yes: Да
|
11
|
+
:no: Нет
|
12
|
+
:#{FormtasticTristateRadio.config.unset_key}: Неизвестно
|
13
|
+
YAML
|
14
|
+
|
15
|
+
EXAMPLE_FORMTASTIC = <<~YAML.chomp
|
16
|
+
ru:
|
17
|
+
formtastic:
|
18
|
+
:yes: Да
|
19
|
+
:no: Нет
|
20
|
+
:#{FormtasticTristateRadio.config.unset_key}: Неизвестно
|
21
|
+
YAML
|
22
|
+
|
23
|
+
class Error < ::I18n::MissingTranslationData
|
24
|
+
module Base
|
25
|
+
|
26
|
+
# @note In you have ActiveAdmin installed, it will give you YAML example for ActiveAdmin as well, otherwise only for Formtastic
|
27
|
+
#
|
28
|
+
# @return [String] error message with YAML examples for the “unset” label translation lookup error
|
29
|
+
#
|
30
|
+
# @see https://github.com/ruby-i18n/i18n/blob/master/lib/i18n/exceptions.rb#L63 Original I18n method
|
31
|
+
#
|
32
|
+
def message
|
33
|
+
msg = []
|
34
|
+
msg << "Add translations for the “unset” radio label"
|
35
|
+
msg << ["For radiobutton labels in forms:", EXAMPLE_FORMTASTIC].join("\n")
|
36
|
+
msg << "Note: “yes”, “no” and some other reserved words are converted into Boolean values in YAML, so you need to quote or symbolize them."
|
37
|
+
msg << ["For ActiveAdmin status tags in index & view tables:", EXAMPLE_ACTIVEADMIN].join("\n") if !!defined?(ActiveAdmin)
|
38
|
+
[super, msg.join("\n\n")].join("\n\n")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
include Base
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
@@ -1,9 +1,7 @@
|
|
1
1
|
require_relative "formtastic_tristate_radio/version"
|
2
|
-
require_relative "formtastic_tristate_radio/missing_translation_error"
|
3
2
|
require_relative "formtastic_tristate_radio/configuration"
|
3
|
+
require_relative "formtastic_tristate_radio/i18n/error"
|
4
4
|
require_relative "formtastic_tristate_radio/engine"
|
5
|
-
|
6
5
|
require_relative "../app/models/active_record/base"
|
7
6
|
|
8
|
-
module FormtasticTristateRadio
|
9
|
-
end
|
7
|
+
module FormtasticTristateRadio; end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: formtastic_tristate_radio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergey Pedan
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-06-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: formtastic
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
version: '4'
|
40
40
|
- - "<"
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version: '
|
42
|
+
version: '8'
|
43
43
|
type: :runtime
|
44
44
|
prerelease: false
|
45
45
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -49,7 +49,7 @@ dependencies:
|
|
49
49
|
version: '4'
|
50
50
|
- - "<"
|
51
51
|
- !ruby/object:Gem::Version
|
52
|
-
version: '
|
52
|
+
version: '8'
|
53
53
|
- !ruby/object:Gem::Dependency
|
54
54
|
name: rspec
|
55
55
|
requirement: !ruby/object:Gem::Requirement
|
@@ -85,21 +85,11 @@ dependencies:
|
|
85
85
|
- !ruby/object:Gem::Version
|
86
86
|
version: '1'
|
87
87
|
description: |
|
88
|
-
Have 3-state radiobuttons instead of a 2-state checkbox for your Boolean columns which can store NULL.
|
89
|
-
|
90
|
-
What the gem does?
|
91
|
-
|
88
|
+
Have 3-state radiobuttons instead of a 2-state checkbox for your Boolean columns which can store NULL. This gem:
|
92
89
|
1. Provides a custom Formtastic input type `:tristate_radio` which renders 3 radios (“Yes”, “No”, “Unset”) instead of a checkbox (only where you put it).
|
93
|
-
|
94
|
-
|
95
|
-
|
90
|
+
2. Teaches Rails recognize `"null"` and `"nil"` param values as `nil`
|
91
|
+
3. Encourages you to add translations for ActiveAdmin “status tag” so that `nil` be correctly translated as “Unset” instead of “False”.
|
96
92
|
Does not change controls, you need to turn it on via `as: :tristate_radio` option.
|
97
|
-
|
98
|
-
By defenition Boolean values have 2 states: True & False.
|
99
|
-
|
100
|
-
However, if you store a Boolean value in a database column with no `NOT NULL` restriction, it aquires a 3<sup>d</sup> possible state: `null`.
|
101
|
-
|
102
|
-
Some may consider this practice questionable — I don’t think so. In real life you always have a case when the answer to your question may be only “yes” or “no”, but you don’t know the answer yet. Using a string type column, storing there `"yes"`, `"no"` and `"unset"` + using a state machine + validations — feels overkill to me.
|
103
93
|
email:
|
104
94
|
- sergey.pedan@gmail.com
|
105
95
|
executables: []
|
@@ -124,7 +114,7 @@ files:
|
|
124
114
|
- lib/formtastic_tristate_radio.rb
|
125
115
|
- lib/formtastic_tristate_radio/configuration.rb
|
126
116
|
- lib/formtastic_tristate_radio/engine.rb
|
127
|
-
- lib/formtastic_tristate_radio/
|
117
|
+
- lib/formtastic_tristate_radio/i18n/error.rb
|
128
118
|
- lib/formtastic_tristate_radio/version.rb
|
129
119
|
homepage: https://github.com/sergeypedan/formtastic-tristate-radio
|
130
120
|
licenses:
|
@@ -154,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
154
144
|
- !ruby/object:Gem::Version
|
155
145
|
version: '0'
|
156
146
|
requirements: []
|
157
|
-
rubygems_version: 3.
|
147
|
+
rubygems_version: 3.3.7
|
158
148
|
signing_key:
|
159
149
|
specification_version: 4
|
160
150
|
summary: Have 3-state radiobuttons instead of a 2-state checkbox for your Boolean
|