formtastic_tristate_radio 0.2.1 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +162 -0
- data/MIT-LICENSE +20 -0
- data/README.md +25 -15
- data/app/inputs/tristate_radio_input.rb +5 -39
- data/config/locales/active_admin.yml +60 -0
- data/config/locales/formtastic.yml +48 -0
- data/formtastic_tristate_radio-0.2.4.gem +0 -0
- data/formtastic_tristate_radio.gemspec +50 -0
- data/lib/formtastic_tristate_radio/configuration.rb +43 -0
- 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 +3 -5
- metadata +34 -13
- data/config/locales/active_admin.en.yml +0 -5
- data/config/locales/active_admin.ru.yml +0 -7
- data/config/locales/formtastic.en.yml +0 -4
- data/config/locales/formtastic.ru.yml +0 -6
- data/lib/tasks/formtastic_tristate_radio_tasks.rake +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b26a9dab6e7233cd6a694dc88f59d08f6d47263c900abfc07416679a87f7c974
|
4
|
+
data.tar.gz: 0a399b71d713ce0f4488f1f7461694d824d43c8f0f42db848daf4c0ad2caa0db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0339d723213d63e7355ca4c50f120f6b08b22d406ba042ad47a89414708d4e07a1748dfa6d530190d2ca45ffd5dff0402779d53a225d9af80449c86b90d85a88'
|
7
|
+
data.tar.gz: b36093c5c3207e2375adb7c80769f890ac3b433c178128add4fa0d24ebd68aff11c5421b783213ff4d3e25d0f3603bf3b49ab8f794475f958e6aa909c879a088
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,20 @@
|
|
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
|
+
|
13
|
+
## [0.2.2] - 2021-11-05
|
14
|
+
|
15
|
+
- Make the gem configurable
|
16
|
+
- Pull the key used for “unset” choice value into configuration
|
17
|
+
|
3
18
|
## [0.2.1] - 2021-11-04
|
4
19
|
|
5
20
|
- Updates docs URL in gemspec
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,162 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
formtastic_tristate_radio (0.2.3)
|
5
|
+
formtastic (>= 3, < 5)
|
6
|
+
rails (>= 4, < 7)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
actioncable (6.1.4.1)
|
12
|
+
actionpack (= 6.1.4.1)
|
13
|
+
activesupport (= 6.1.4.1)
|
14
|
+
nio4r (~> 2.0)
|
15
|
+
websocket-driver (>= 0.6.1)
|
16
|
+
actionmailbox (6.1.4.1)
|
17
|
+
actionpack (= 6.1.4.1)
|
18
|
+
activejob (= 6.1.4.1)
|
19
|
+
activerecord (= 6.1.4.1)
|
20
|
+
activestorage (= 6.1.4.1)
|
21
|
+
activesupport (= 6.1.4.1)
|
22
|
+
mail (>= 2.7.1)
|
23
|
+
actionmailer (6.1.4.1)
|
24
|
+
actionpack (= 6.1.4.1)
|
25
|
+
actionview (= 6.1.4.1)
|
26
|
+
activejob (= 6.1.4.1)
|
27
|
+
activesupport (= 6.1.4.1)
|
28
|
+
mail (~> 2.5, >= 2.5.4)
|
29
|
+
rails-dom-testing (~> 2.0)
|
30
|
+
actionpack (6.1.4.1)
|
31
|
+
actionview (= 6.1.4.1)
|
32
|
+
activesupport (= 6.1.4.1)
|
33
|
+
rack (~> 2.0, >= 2.0.9)
|
34
|
+
rack-test (>= 0.6.3)
|
35
|
+
rails-dom-testing (~> 2.0)
|
36
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
37
|
+
actiontext (6.1.4.1)
|
38
|
+
actionpack (= 6.1.4.1)
|
39
|
+
activerecord (= 6.1.4.1)
|
40
|
+
activestorage (= 6.1.4.1)
|
41
|
+
activesupport (= 6.1.4.1)
|
42
|
+
nokogiri (>= 1.8.5)
|
43
|
+
actionview (6.1.4.1)
|
44
|
+
activesupport (= 6.1.4.1)
|
45
|
+
builder (~> 3.1)
|
46
|
+
erubi (~> 1.4)
|
47
|
+
rails-dom-testing (~> 2.0)
|
48
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
49
|
+
activejob (6.1.4.1)
|
50
|
+
activesupport (= 6.1.4.1)
|
51
|
+
globalid (>= 0.3.6)
|
52
|
+
activemodel (6.1.4.1)
|
53
|
+
activesupport (= 6.1.4.1)
|
54
|
+
activerecord (6.1.4.1)
|
55
|
+
activemodel (= 6.1.4.1)
|
56
|
+
activesupport (= 6.1.4.1)
|
57
|
+
activestorage (6.1.4.1)
|
58
|
+
actionpack (= 6.1.4.1)
|
59
|
+
activejob (= 6.1.4.1)
|
60
|
+
activerecord (= 6.1.4.1)
|
61
|
+
activesupport (= 6.1.4.1)
|
62
|
+
marcel (~> 1.0.0)
|
63
|
+
mini_mime (>= 1.1.0)
|
64
|
+
activesupport (6.1.4.1)
|
65
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
66
|
+
i18n (>= 1.6, < 2)
|
67
|
+
minitest (>= 5.1)
|
68
|
+
tzinfo (~> 2.0)
|
69
|
+
zeitwerk (~> 2.3)
|
70
|
+
builder (3.2.4)
|
71
|
+
concurrent-ruby (1.1.9)
|
72
|
+
crass (1.0.6)
|
73
|
+
diff-lcs (1.4.4)
|
74
|
+
erubi (1.10.0)
|
75
|
+
formtastic (4.0.0)
|
76
|
+
actionpack (>= 5.2.0)
|
77
|
+
globalid (0.5.2)
|
78
|
+
activesupport (>= 5.0)
|
79
|
+
i18n (1.8.11)
|
80
|
+
concurrent-ruby (~> 1.0)
|
81
|
+
loofah (2.12.0)
|
82
|
+
crass (~> 1.0.2)
|
83
|
+
nokogiri (>= 1.5.9)
|
84
|
+
mail (2.7.1)
|
85
|
+
mini_mime (>= 0.1.1)
|
86
|
+
marcel (1.0.2)
|
87
|
+
method_source (1.0.0)
|
88
|
+
mini_mime (1.1.2)
|
89
|
+
minitest (5.14.4)
|
90
|
+
nio4r (2.5.8)
|
91
|
+
nokogiri (1.12.5-x86_64-darwin)
|
92
|
+
racc (~> 1.4)
|
93
|
+
racc (1.6.0)
|
94
|
+
rack (2.2.3)
|
95
|
+
rack-test (1.1.0)
|
96
|
+
rack (>= 1.0, < 3)
|
97
|
+
rails (6.1.4.1)
|
98
|
+
actioncable (= 6.1.4.1)
|
99
|
+
actionmailbox (= 6.1.4.1)
|
100
|
+
actionmailer (= 6.1.4.1)
|
101
|
+
actionpack (= 6.1.4.1)
|
102
|
+
actiontext (= 6.1.4.1)
|
103
|
+
actionview (= 6.1.4.1)
|
104
|
+
activejob (= 6.1.4.1)
|
105
|
+
activemodel (= 6.1.4.1)
|
106
|
+
activerecord (= 6.1.4.1)
|
107
|
+
activestorage (= 6.1.4.1)
|
108
|
+
activesupport (= 6.1.4.1)
|
109
|
+
bundler (>= 1.15.0)
|
110
|
+
railties (= 6.1.4.1)
|
111
|
+
sprockets-rails (>= 2.0.0)
|
112
|
+
rails-dom-testing (2.0.3)
|
113
|
+
activesupport (>= 4.2.0)
|
114
|
+
nokogiri (>= 1.6)
|
115
|
+
rails-html-sanitizer (1.4.2)
|
116
|
+
loofah (~> 2.3)
|
117
|
+
railties (6.1.4.1)
|
118
|
+
actionpack (= 6.1.4.1)
|
119
|
+
activesupport (= 6.1.4.1)
|
120
|
+
method_source
|
121
|
+
rake (>= 0.13)
|
122
|
+
thor (~> 1.0)
|
123
|
+
rake (13.0.6)
|
124
|
+
rspec (3.10.0)
|
125
|
+
rspec-core (~> 3.10.0)
|
126
|
+
rspec-expectations (~> 3.10.0)
|
127
|
+
rspec-mocks (~> 3.10.0)
|
128
|
+
rspec-core (3.10.1)
|
129
|
+
rspec-support (~> 3.10.0)
|
130
|
+
rspec-expectations (3.10.1)
|
131
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
132
|
+
rspec-support (~> 3.10.0)
|
133
|
+
rspec-mocks (3.10.2)
|
134
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
135
|
+
rspec-support (~> 3.10.0)
|
136
|
+
rspec-support (3.10.3)
|
137
|
+
sprockets (4.0.2)
|
138
|
+
concurrent-ruby (~> 1.0)
|
139
|
+
rack (> 1, < 3)
|
140
|
+
sprockets-rails (3.2.2)
|
141
|
+
actionpack (>= 4.0)
|
142
|
+
activesupport (>= 4.0)
|
143
|
+
sprockets (>= 3.0.0)
|
144
|
+
thor (1.1.0)
|
145
|
+
tzinfo (2.0.4)
|
146
|
+
concurrent-ruby (~> 1.0)
|
147
|
+
websocket-driver (0.7.5)
|
148
|
+
websocket-extensions (>= 0.1.0)
|
149
|
+
websocket-extensions (0.1.5)
|
150
|
+
yard (0.9.26)
|
151
|
+
zeitwerk (2.5.1)
|
152
|
+
|
153
|
+
PLATFORMS
|
154
|
+
x86_64-darwin-17
|
155
|
+
|
156
|
+
DEPENDENCIES
|
157
|
+
formtastic_tristate_radio!
|
158
|
+
rspec (~> 3)
|
159
|
+
yard (>= 0.9.20, < 1)
|
160
|
+
|
161
|
+
BUNDLED WITH
|
162
|
+
2.2.27
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2021 Sergey Pedan
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -27,8 +27,7 @@ Some may consider this practice questionable — I don’t think so. In real
|
|
27
27
|
For a Boolean column with 3 possible states:
|
28
28
|
|
29
29
|
```ruby
|
30
|
-
f.input :am_i_awake,
|
31
|
-
f.input :is_this_a_dream, as: :tristate_radio, null: "Reality is a persistent hallucination"
|
30
|
+
f.input :am_i_awake, as: :tristate_radio
|
32
31
|
```
|
33
32
|
|
34
33
|
You get (HTML is simplified, actually there are more classes etc.):
|
@@ -40,13 +39,6 @@ You get (HTML is simplified, actually there are more classes etc.):
|
|
40
39
|
<input name="am_i_awake" type="radio" value="false"> <label>No</label>
|
41
40
|
<input name="am_i_awake" type="radio" value="null"> <label>Unset</label>
|
42
41
|
</fieldset>
|
43
|
-
|
44
|
-
<fieldset>
|
45
|
-
<legend>Is this a dream?</legend>
|
46
|
-
<input name="is_this_a_dream" type="radio" value="true"> <label>Yes</label>
|
47
|
-
<input name="is_this_a_dream" type="radio" value="false"> <label>No</label>
|
48
|
-
<input name="is_this_a_dream" type="radio" value="null"> <label>Reality is a persistent hallucination</label>
|
49
|
-
</fieldset>
|
50
42
|
```
|
51
43
|
|
52
44
|
|
@@ -94,12 +86,29 @@ Notice that the key ActiveAdmin uses is “unset”, not “null”.
|
|
94
86
|
|
95
87
|
## Configuration
|
96
88
|
|
97
|
-
|
89
|
+
It’s difficult to come up with a reasonable use case for that, but you can configure what will be used as inputs value:
|
90
|
+
|
91
|
+
```ruby
|
92
|
+
# config/initializers/formtastic.rb
|
93
|
+
FormtasticTristateRadio.configure do |config|
|
94
|
+
config.unset_key = "__unset" # default is :null
|
95
|
+
end
|
96
|
+
```
|
97
|
+
|
98
|
+
which will result in:
|
99
|
+
|
100
|
+
```html
|
101
|
+
<input type="radio" name="am_i_awake" value="true">
|
102
|
+
<input type="radio" name="am_i_awake" value="false">
|
103
|
+
<input type="radio" name="am_i_awake" value="__unset">
|
104
|
+
```
|
105
|
+
|
106
|
+
Mind that for your custom value to work, you also need to configure `ActiveModel` to recognize that value as `nil`. Currently that is done [like so](https://github.com/sergeypedan/formtastic-tristate-radio/blob/master/config/initializers/activemodel_type_boolean.rb#L9).
|
98
107
|
|
99
108
|
|
100
109
|
## Documentation
|
101
110
|
|
102
|
-
Low-level methods are properly documented in RubyDoc [here](https://www.rubydoc.info/gems/formtastic_tristate_radio/).
|
111
|
+
Low-level methods are properly documented in RubyDoc [here](https://www.rubydoc.info/gems/formtastic_tristate_radio/TristateRadioInput).
|
103
112
|
|
104
113
|
|
105
114
|
## Dependencies
|
@@ -121,7 +130,7 @@ In Ruby any String is cast to `true`:
|
|
121
130
|
|
122
131
|
Web form params are passed as plain text and are interpreted as String by Rack.
|
123
132
|
|
124
|
-
So how Boolean values
|
133
|
+
So how are Boolean values transfered as strings if a `"no"` or `"0"` and even `""` is truthy in Ruby?
|
125
134
|
|
126
135
|
Frameworks just have a list of string values to be recognized and mapped to Boolean values:
|
127
136
|
|
@@ -178,10 +187,11 @@ ActiveModel::Type::Boolean.new.cast(:nil) #=> nil
|
|
178
187
|
|
179
188
|
## Roadmap
|
180
189
|
|
190
|
+
- [ ] Remove `require_relative "../app/models/active_record/base"` from main file
|
191
|
+
- [x] Make the gem configurable
|
192
|
+
- [x] Pull the key used for “unset” choice value into configuration
|
193
|
+
- [x] Add translations into most popular languages
|
181
194
|
- [ ] Load translations from gem
|
182
|
-
- [ ] Add translations into most popular languages
|
183
|
-
- [ ] Make the gem configurable
|
184
|
-
- [ ] Pull the key used for “unset” choice value into configuration
|
185
195
|
- [ ] Rgister `:tristate_radio` for Boolean columns with `null`
|
186
196
|
- [ ] Decouple `ActiveModel::Type::Boolean` thing from Formtastic things, maybe into a separate gem
|
187
197
|
- [ ] Decouple from Rails
|
@@ -1,48 +1,16 @@
|
|
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`.
|
7
|
+
# Should equal one of `ActiveModel::Type::Boolean::NULL_VALUES`
|
9
8
|
#
|
10
9
|
# Mind ActiveAdmin [status resolving logic](https://github.com/activeadmin/activeadmin/blob/master/lib/active_admin/views/components/status_tag.rb#L51):
|
11
10
|
# in status tag builder the value is lowercased before casting into Boolean, and the keyword for nil is `"unset"`.
|
12
11
|
# So if we have lowercase `"unset"`, translations from `ru.formtastic.unset` will be overriden by `ru.active_admin.status_tag.unset`.
|
13
12
|
#
|
14
|
-
UNSET_KEY =
|
15
|
-
|
16
|
-
I18N_EXAMPLE_ACTIVEADMIN = <<~YAML.chomp
|
17
|
-
ru:
|
18
|
-
active_admin:
|
19
|
-
status_tag:
|
20
|
-
:yes: Да
|
21
|
-
:no: Нет
|
22
|
-
:#{UNSET_KEY}: Неизвестно
|
23
|
-
YAML
|
24
|
-
|
25
|
-
I18N_EXAMPLE_FORMTASTIC = <<~YAML.chomp
|
26
|
-
ru:
|
27
|
-
formtastic:
|
28
|
-
:yes: Да
|
29
|
-
:no: Нет
|
30
|
-
:#{UNSET_KEY}: Неизвестно
|
31
|
-
YAML
|
32
|
-
|
33
|
-
|
34
|
-
# @note In you have ActiveAdmin installed, it will give you YAML example for ActiveAdmin as well, otherwise only for Formtastic
|
35
|
-
#
|
36
|
-
# @return [String] error message with YAML examples for the “unset” label translation lookup error
|
37
|
-
#
|
38
|
-
def self.missing_i18n_error_msg
|
39
|
-
msg = []
|
40
|
-
msg << "Add translations for the “unset” radio label"
|
41
|
-
msg << ["For radiobutton labels in forms:", I18N_EXAMPLE_FORMTASTIC].join("\n")
|
42
|
-
msg << "Note: “yes”, “no” and some other reserved words are converted into Boolean values in YAML, so you need to quote or symbolize them."
|
43
|
-
msg << ["For ActiveAdmin status tags in index & view tables:", I18N_EXAMPLE_ACTIVEADMIN].join("\n") if !!defined?(ActiveAdmin)
|
44
|
-
msg.join("\n\n")
|
45
|
-
end
|
13
|
+
UNSET_KEY = FormtasticTristateRadio.config.unset_key
|
46
14
|
|
47
15
|
|
48
16
|
# @see https://github.com/formtastic/formtastic/blob/35dc806964403cb2bb0a6074b951ceef906c8581/lib/formtastic/inputs/base/choices.rb#L59 Original Formtastic method
|
@@ -84,12 +52,10 @@ class TristateRadioInput < Formtastic::Inputs::RadioInput
|
|
84
52
|
#
|
85
53
|
# @return [String] Label of the radio that stands for the unknown choice
|
86
54
|
#
|
87
|
-
# @raise [
|
88
|
-
# @see missing_i18n_error_msg
|
55
|
+
# @raise [FormtasticTristateRadio::I18n::Error] if the translation could not be found
|
89
56
|
#
|
90
57
|
def label_text_for_unset
|
91
|
-
options.fetch(:null, Formtastic::I18n.t(UNSET_KEY)).presence or
|
92
|
-
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)
|
93
59
|
end
|
94
60
|
|
95
61
|
|
@@ -0,0 +1,60 @@
|
|
1
|
+
---
|
2
|
+
ca:
|
3
|
+
active_admin:
|
4
|
+
status_tag:
|
5
|
+
:null: No establert
|
6
|
+
---
|
7
|
+
de:
|
8
|
+
active_admin:
|
9
|
+
status_tag:
|
10
|
+
:null: Nicht eingestellt
|
11
|
+
---
|
12
|
+
fr:
|
13
|
+
active_admin:
|
14
|
+
status_tag:
|
15
|
+
:null: Pas défini
|
16
|
+
---
|
17
|
+
it:
|
18
|
+
active_admin:
|
19
|
+
status_tag:
|
20
|
+
:null: Sconosciuto
|
21
|
+
---
|
22
|
+
ja:
|
23
|
+
active_admin:
|
24
|
+
status_tag:
|
25
|
+
:null: 不明
|
26
|
+
---
|
27
|
+
en:
|
28
|
+
active_admin:
|
29
|
+
status_tag:
|
30
|
+
:null: Unset
|
31
|
+
---
|
32
|
+
es:
|
33
|
+
active_admin:
|
34
|
+
status_tag:
|
35
|
+
:null: No establecido
|
36
|
+
---
|
37
|
+
pl:
|
38
|
+
active_admin:
|
39
|
+
status_tag:
|
40
|
+
:null: Nie ustawiony
|
41
|
+
---
|
42
|
+
pt-BR:
|
43
|
+
active_admin:
|
44
|
+
status_tag:
|
45
|
+
:null: Não configurado
|
46
|
+
---
|
47
|
+
pt:
|
48
|
+
active_admin:
|
49
|
+
status_tag:
|
50
|
+
:null: Não configurado
|
51
|
+
---
|
52
|
+
ru:
|
53
|
+
active_admin:
|
54
|
+
status_tag:
|
55
|
+
:null: Неизвестно
|
56
|
+
---
|
57
|
+
tr:
|
58
|
+
active_admin:
|
59
|
+
status_tag:
|
60
|
+
:null: Ayarlanmadı
|
@@ -0,0 +1,48 @@
|
|
1
|
+
---
|
2
|
+
ca:
|
3
|
+
formtastic:
|
4
|
+
:null: No establert
|
5
|
+
---
|
6
|
+
de:
|
7
|
+
formtastic:
|
8
|
+
:null: Nicht eingestellt
|
9
|
+
---
|
10
|
+
fr:
|
11
|
+
formtastic:
|
12
|
+
:null: Pas défini
|
13
|
+
---
|
14
|
+
it:
|
15
|
+
formtastic:
|
16
|
+
:null: Sconosciuto
|
17
|
+
---
|
18
|
+
ja:
|
19
|
+
formtastic:
|
20
|
+
:null: 不明
|
21
|
+
---
|
22
|
+
en:
|
23
|
+
formtastic:
|
24
|
+
:null: Unset
|
25
|
+
---
|
26
|
+
es:
|
27
|
+
formtastic:
|
28
|
+
:null: No establecido
|
29
|
+
---
|
30
|
+
pl:
|
31
|
+
formtastic:
|
32
|
+
:null: Nie ustawiony
|
33
|
+
---
|
34
|
+
pt-BR:
|
35
|
+
formtastic:
|
36
|
+
:null: Não configurado
|
37
|
+
---
|
38
|
+
pt:
|
39
|
+
formtastic:
|
40
|
+
:null: Não configurado
|
41
|
+
---
|
42
|
+
ru:
|
43
|
+
formtastic:
|
44
|
+
:null: Неизвестно
|
45
|
+
---
|
46
|
+
tr:
|
47
|
+
formtastic:
|
48
|
+
:null: Ayarlanmadı
|
Binary file
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# https://guides.rubygems.org/name-your-gem/
|
4
|
+
# https://bundler.io/guides/creating_gem.html
|
5
|
+
# https://guides.rubyonrails.org/engines.html
|
6
|
+
# https://guides.rubyonrails.org/plugins.html
|
7
|
+
|
8
|
+
require_relative "lib/formtastic_tristate_radio/version"
|
9
|
+
|
10
|
+
Gem::Specification.new do |spec|
|
11
|
+
spec.name = "formtastic_tristate_radio"
|
12
|
+
spec.version = FormtasticTristateRadio::VERSION
|
13
|
+
spec.authors = ["Sergey Pedan"]
|
14
|
+
spec.email = ["sergey.pedan@gmail.com"]
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.summary = "Have 3-state radiobuttons instead of a 2-state checkbox for your Boolean columns which can store NULL"
|
18
|
+
spec.description = <<~HEREDOC
|
19
|
+
#{spec.summary}. This gem:
|
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).
|
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”.
|
23
|
+
Does not change controls, you need to turn it on via `as: :tristate_radio` option.
|
24
|
+
HEREDOC
|
25
|
+
|
26
|
+
spec.homepage = "https://github.com/sergeypedan/formtastic-tristate-radio"
|
27
|
+
spec.extra_rdoc_files = ["README.md", "CHANGELOG.md"]
|
28
|
+
spec.rdoc_options = ["--charset=UTF-8"]
|
29
|
+
spec.metadata = { "changelog_uri" => "#{spec.homepage}/blob/master/CHANGELOG.md",
|
30
|
+
"documentation_uri" => "https://www.rubydoc.info/gems/#{spec.name}",
|
31
|
+
"homepage_uri" => spec.homepage,
|
32
|
+
"source_code_uri" => spec.homepage }
|
33
|
+
|
34
|
+
spec.require_paths = ["app/inputs", "app/models/active_record", "config/initializers", "config/locales", "lib"]
|
35
|
+
spec.bindir = "exe"
|
36
|
+
spec.executables = []
|
37
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
38
|
+
`git ls-files`.split("\n")
|
39
|
+
.reject { |f| %w[bin spec test].any? { |dir| f.start_with? dir } }
|
40
|
+
.reject { |f| f.start_with? "." }
|
41
|
+
end
|
42
|
+
|
43
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
|
44
|
+
|
45
|
+
spec.add_dependency "formtastic", ">= 3", "< 5"
|
46
|
+
spec.add_dependency "rails", ">= 4", "< 7"
|
47
|
+
|
48
|
+
spec.add_development_dependency "rspec", "~> 3"
|
49
|
+
spec.add_development_dependency "yard", ">= 0.9.20", "< 1"
|
50
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module FormtasticTristateRadio
|
4
|
+
|
5
|
+
class << self
|
6
|
+
attr_writer :config
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.config
|
10
|
+
@config ||= Configuration.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.configure
|
14
|
+
yield(config)
|
15
|
+
end
|
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
|
+
#
|
22
|
+
class Configuration
|
23
|
+
|
24
|
+
def initialize
|
25
|
+
@unset_key = :null
|
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
|
41
|
+
end
|
42
|
+
|
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/configuration"
|
3
|
+
require_relative "formtastic_tristate_radio/i18n/error"
|
2
4
|
require_relative "formtastic_tristate_radio/engine"
|
3
5
|
require_relative "../app/models/active_record/base"
|
4
6
|
|
5
|
-
module FormtasticTristateRadio
|
6
|
-
|
7
|
-
class MissingTranslationError < StandardError; end
|
8
|
-
|
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.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergey Pedan
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-11-
|
11
|
+
date: 2021-11-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: formtastic
|
@@ -50,13 +50,27 @@ dependencies:
|
|
50
50
|
- - "<"
|
51
51
|
- !ruby/object:Gem::Version
|
52
52
|
version: '7'
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: rspec
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - "~>"
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '3'
|
60
|
+
type: :development
|
61
|
+
prerelease: false
|
62
|
+
version_requirements: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - "~>"
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '3'
|
53
67
|
- !ruby/object:Gem::Dependency
|
54
68
|
name: yard
|
55
69
|
requirement: !ruby/object:Gem::Requirement
|
56
70
|
requirements:
|
57
71
|
- - ">="
|
58
72
|
- !ruby/object:Gem::Version
|
59
|
-
version:
|
73
|
+
version: 0.9.20
|
60
74
|
- - "<"
|
61
75
|
- !ruby/object:Gem::Version
|
62
76
|
version: '1'
|
@@ -66,13 +80,16 @@ dependencies:
|
|
66
80
|
requirements:
|
67
81
|
- - ">="
|
68
82
|
- !ruby/object:Gem::Version
|
69
|
-
version:
|
83
|
+
version: 0.9.20
|
70
84
|
- - "<"
|
71
85
|
- !ruby/object:Gem::Version
|
72
86
|
version: '1'
|
73
|
-
description:
|
74
|
-
|
75
|
-
|
87
|
+
description: |
|
88
|
+
Have 3-state radiobuttons instead of a 2-state checkbox for your Boolean columns which can store NULL. This gem:
|
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).
|
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”.
|
92
|
+
Does not change controls, you need to turn it on via `as: :tristate_radio` option.
|
76
93
|
email:
|
77
94
|
- sergey.pedan@gmail.com
|
78
95
|
executables: []
|
@@ -82,20 +99,24 @@ extra_rdoc_files:
|
|
82
99
|
- CHANGELOG.md
|
83
100
|
files:
|
84
101
|
- CHANGELOG.md
|
102
|
+
- Gemfile
|
103
|
+
- Gemfile.lock
|
104
|
+
- MIT-LICENSE
|
85
105
|
- README.md
|
86
106
|
- Rakefile
|
87
107
|
- app/inputs/tristate_radio_input.rb
|
88
108
|
- app/models/active_record/base.rb
|
89
109
|
- config/initializers/activemodel_type_boolean.rb
|
90
|
-
- config/locales/active_admin.
|
91
|
-
- config/locales/
|
92
|
-
- config/locales/formtastic.en.yml
|
93
|
-
- config/locales/formtastic.ru.yml
|
110
|
+
- config/locales/active_admin.yml
|
111
|
+
- config/locales/formtastic.yml
|
94
112
|
- config/routes.rb
|
113
|
+
- formtastic_tristate_radio-0.2.4.gem
|
114
|
+
- formtastic_tristate_radio.gemspec
|
95
115
|
- lib/formtastic_tristate_radio.rb
|
116
|
+
- lib/formtastic_tristate_radio/configuration.rb
|
96
117
|
- lib/formtastic_tristate_radio/engine.rb
|
118
|
+
- lib/formtastic_tristate_radio/i18n/error.rb
|
97
119
|
- lib/formtastic_tristate_radio/version.rb
|
98
|
-
- lib/tasks/formtastic_tristate_radio_tasks.rake
|
99
120
|
homepage: https://github.com/sergeypedan/formtastic-tristate-radio
|
100
121
|
licenses:
|
101
122
|
- MIT
|
@@ -108,11 +129,11 @@ post_install_message:
|
|
108
129
|
rdoc_options:
|
109
130
|
- "--charset=UTF-8"
|
110
131
|
require_paths:
|
111
|
-
- lib
|
112
132
|
- app/inputs
|
113
133
|
- app/models/active_record
|
114
134
|
- config/initializers
|
115
135
|
- config/locales
|
136
|
+
- lib
|
116
137
|
required_ruby_version: !ruby/object:Gem::Requirement
|
117
138
|
requirements:
|
118
139
|
- - ">="
|