formtastic_tristate_radio 0.2.0 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +12 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +162 -0
- data/MIT-LICENSE +20 -0
- data/README.md +31 -11
- data/app/inputs/tristate_radio_input.rb +4 -37
- data/config/locales/active_admin.yml +60 -0
- data/config/locales/formtastic.yml +48 -0
- data/formtastic_tristate_radio.gemspec +50 -0
- data/lib/formtastic_tristate_radio/configuration.rb +25 -0
- 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 +36 -51
- 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
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6cb90abb9a912c583ace9c1ce3c7fabdf27e3b0b
|
4
|
+
data.tar.gz: fd220427f9e5d0f573c3533d186c85c47dffd581
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 47c7eb5acfd279ce25b9b61216951004aa76c472260d01053ffc91925c2ea078c2428287593e746e62239b984a90b3f3f6f2a299ae2f928024b5702c4e19202f
|
7
|
+
data.tar.gz: 0f76c972c65fd6d2e1e78b69e7d5b1868345d0a04a3755a7b39719fc9fffc16e7b0fa5776861202d2638ecfa267a5ee1431493576b5d6467fbba2096d95fb0a1
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## [0.2.2] - 2021-11-05
|
4
|
+
|
5
|
+
- Make the gem configurable
|
6
|
+
- Pull the key used for “unset” choice value into configuration
|
7
|
+
|
8
|
+
## [0.2.1] - 2021-11-04
|
9
|
+
|
10
|
+
- Updates docs URL in gemspec
|
11
|
+
- Updates change-log URL in gemspec
|
12
|
+
- Removes development gems
|
13
|
+
- Adds roadmap items
|
14
|
+
|
3
15
|
## [0.2.0] - 2021-11-04
|
4
16
|
|
5
17
|
- Custom translation override from form via options
|
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
@@ -1,6 +1,8 @@
|
|
1
1
|
# Formtastic tri-state radio
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/formtastic_tristate_radio.svg)](https://badge.fury.io/rb/formtastic_tristate_radio)
|
4
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/c2508d7f23238fb2b87f/maintainability)](https://codeclimate.com/github/sergeypedan/formtastic-tristate-radio/maintainability)
|
5
|
+
[![Test Coverage](https://api.codeclimate.com/v1/badges/c2508d7f23238fb2b87f/test_coverage)](https://codeclimate.com/github/sergeypedan/formtastic-tristate-radio/test_coverage)
|
4
6
|
|
5
7
|
## What is “tri-state”?
|
6
8
|
|
@@ -25,8 +27,7 @@ Some may consider this practice questionable — I don’t think so. In real
|
|
25
27
|
For a Boolean column with 3 possible states:
|
26
28
|
|
27
29
|
```ruby
|
28
|
-
f.input :am_i_awake,
|
29
|
-
f.input :is_this_a_dream, as: :tristate_radio, null: "Reality is a persistent hallucination"
|
30
|
+
f.input :am_i_awake, as: :tristate_radio
|
30
31
|
```
|
31
32
|
|
32
33
|
You get (HTML is simplified, actually there are more classes etc.):
|
@@ -38,13 +39,6 @@ You get (HTML is simplified, actually there are more classes etc.):
|
|
38
39
|
<input name="am_i_awake" type="radio" value="false"> <label>No</label>
|
39
40
|
<input name="am_i_awake" type="radio" value="null"> <label>Unset</label>
|
40
41
|
</fieldset>
|
41
|
-
|
42
|
-
<fieldset>
|
43
|
-
<legend>Is this a dream?</legend>
|
44
|
-
<input name="is_this_a_dream" type="radio" value="true"> <label>Yes</label>
|
45
|
-
<input name="is_this_a_dream" type="radio" value="false"> <label>No</label>
|
46
|
-
<input name="is_this_a_dream" type="radio" value="null"> <label>Reality is a persistent hallucination</label>
|
47
|
-
</fieldset>
|
48
42
|
```
|
49
43
|
|
50
44
|
|
@@ -92,7 +86,29 @@ Notice that the key ActiveAdmin uses is “unset”, not “null”.
|
|
92
86
|
|
93
87
|
## Configuration
|
94
88
|
|
95
|
-
|
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).
|
107
|
+
|
108
|
+
|
109
|
+
## Documentation
|
110
|
+
|
111
|
+
Low-level methods are properly documented in RubyDoc [here](https://www.rubydoc.info/gems/formtastic_tristate_radio/TristateRadioInput).
|
96
112
|
|
97
113
|
|
98
114
|
## Dependencies
|
@@ -114,7 +130,7 @@ In Ruby any String is cast to `true`:
|
|
114
130
|
|
115
131
|
Web form params are passed as plain text and are interpreted as String by Rack.
|
116
132
|
|
117
|
-
So how Boolean values
|
133
|
+
So how are Boolean values transfered as strings if a `"no"` or `"0"` and even `""` is truthy in Ruby?
|
118
134
|
|
119
135
|
Frameworks just have a list of string values to be recognized and mapped to Boolean values:
|
120
136
|
|
@@ -171,9 +187,13 @@ ActiveModel::Type::Boolean.new.cast(:nil) #=> nil
|
|
171
187
|
|
172
188
|
## Roadmap
|
173
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
|
174
193
|
- [ ] Load translations from gem
|
175
194
|
- [ ] Add translations into most popular languages
|
176
195
|
- [ ] Rgister `:tristate_radio` for Boolean columns with `null`
|
196
|
+
- [ ] Decouple `ActiveModel::Type::Boolean` thing from Formtastic things, maybe into a separate gem
|
177
197
|
- [ ] Decouple from Rails
|
178
198
|
|
179
199
|
|
@@ -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
|
@@ -88,8 +56,7 @@ class TristateRadioInput < Formtastic::Inputs::RadioInput
|
|
88
56
|
# @see missing_i18n_error_msg
|
89
57
|
#
|
90
58
|
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)
|
59
|
+
options.fetch(:null, Formtastic::I18n.t(UNSET_KEY)).presence or fail FormtasticTristateRadio::I18n::Error.new(locale, UNSET_KEY)
|
93
60
|
end
|
94
61
|
|
95
62
|
|
@@ -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ı
|
@@ -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`. See “[How it works](#how-it-works)” ☟ section for technical details on this.
|
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,25 @@
|
|
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
|
+
class Configuration
|
18
|
+
attr_accessor :unset_key
|
19
|
+
|
20
|
+
def initialize
|
21
|
+
@unset_key = :null
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
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 URL 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.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergey Pedan
|
8
|
-
autorequire:
|
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
|
@@ -51,64 +51,45 @@ dependencies:
|
|
51
51
|
- !ruby/object:Gem::Version
|
52
52
|
version: '7'
|
53
53
|
- !ruby/object:Gem::Dependency
|
54
|
-
name:
|
54
|
+
name: rspec
|
55
55
|
requirement: !ruby/object:Gem::Requirement
|
56
56
|
requirements:
|
57
57
|
- - "~>"
|
58
58
|
- !ruby/object:Gem::Version
|
59
|
-
version: '
|
59
|
+
version: '3'
|
60
60
|
type: :development
|
61
61
|
prerelease: false
|
62
62
|
version_requirements: !ruby/object:Gem::Requirement
|
63
63
|
requirements:
|
64
64
|
- - "~>"
|
65
65
|
- !ruby/object:Gem::Version
|
66
|
-
version: '
|
66
|
+
version: '3'
|
67
67
|
- !ruby/object:Gem::Dependency
|
68
|
-
name:
|
68
|
+
name: yard
|
69
69
|
requirement: !ruby/object:Gem::Requirement
|
70
70
|
requirements:
|
71
|
-
- - "
|
72
|
-
- !ruby/object:Gem::Version
|
73
|
-
version: '0.14'
|
74
|
-
type: :development
|
75
|
-
prerelease: false
|
76
|
-
version_requirements: !ruby/object:Gem::Requirement
|
77
|
-
requirements:
|
78
|
-
- - "~>"
|
71
|
+
- - ">="
|
79
72
|
- !ruby/object:Gem::Version
|
80
|
-
version:
|
81
|
-
-
|
82
|
-
name: rake
|
83
|
-
requirement: !ruby/object:Gem::Requirement
|
84
|
-
requirements:
|
85
|
-
- - "~>"
|
73
|
+
version: 0.9.20
|
74
|
+
- - "<"
|
86
75
|
- !ruby/object:Gem::Version
|
87
|
-
version: '
|
76
|
+
version: '1'
|
88
77
|
type: :development
|
89
78
|
prerelease: false
|
90
79
|
version_requirements: !ruby/object:Gem::Requirement
|
91
80
|
requirements:
|
92
|
-
- - "
|
93
|
-
- !ruby/object:Gem::Version
|
94
|
-
version: '13'
|
95
|
-
- !ruby/object:Gem::Dependency
|
96
|
-
name: yard
|
97
|
-
requirement: !ruby/object:Gem::Requirement
|
98
|
-
requirements:
|
99
|
-
- - "~>"
|
81
|
+
- - ">="
|
100
82
|
- !ruby/object:Gem::Version
|
101
|
-
version:
|
102
|
-
|
103
|
-
prerelease: false
|
104
|
-
version_requirements: !ruby/object:Gem::Requirement
|
105
|
-
requirements:
|
106
|
-
- - "~>"
|
83
|
+
version: 0.9.20
|
84
|
+
- - "<"
|
107
85
|
- !ruby/object:Gem::Version
|
108
|
-
version: '
|
109
|
-
description:
|
110
|
-
|
111
|
-
|
86
|
+
version: '1'
|
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`. See “[How it works](#how-it-works)” ☟ section for technical details on this.
|
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.
|
112
93
|
email:
|
113
94
|
- sergey.pedan@gmail.com
|
114
95
|
executables: []
|
@@ -118,37 +99,40 @@ extra_rdoc_files:
|
|
118
99
|
- CHANGELOG.md
|
119
100
|
files:
|
120
101
|
- CHANGELOG.md
|
102
|
+
- Gemfile
|
103
|
+
- Gemfile.lock
|
104
|
+
- MIT-LICENSE
|
121
105
|
- README.md
|
122
106
|
- Rakefile
|
123
107
|
- app/inputs/tristate_radio_input.rb
|
124
108
|
- app/models/active_record/base.rb
|
125
109
|
- config/initializers/activemodel_type_boolean.rb
|
126
|
-
- config/locales/active_admin.
|
127
|
-
- config/locales/
|
128
|
-
- config/locales/formtastic.en.yml
|
129
|
-
- config/locales/formtastic.ru.yml
|
110
|
+
- config/locales/active_admin.yml
|
111
|
+
- config/locales/formtastic.yml
|
130
112
|
- config/routes.rb
|
113
|
+
- formtastic_tristate_radio.gemspec
|
131
114
|
- lib/formtastic_tristate_radio.rb
|
115
|
+
- lib/formtastic_tristate_radio/configuration.rb
|
132
116
|
- lib/formtastic_tristate_radio/engine.rb
|
117
|
+
- lib/formtastic_tristate_radio/i18n/error.rb
|
133
118
|
- lib/formtastic_tristate_radio/version.rb
|
134
|
-
- lib/tasks/formtastic_tristate_radio_tasks.rake
|
135
119
|
homepage: https://github.com/sergeypedan/formtastic-tristate-radio
|
136
120
|
licenses:
|
137
121
|
- MIT
|
138
122
|
metadata:
|
139
|
-
changelog_uri: https://github.com/sergeypedan/formtastic-tristate-radio/blob/master/
|
140
|
-
documentation_uri: https://www.rubydoc.info/gems/
|
123
|
+
changelog_uri: https://github.com/sergeypedan/formtastic-tristate-radio/blob/master/CHANGELOG.md
|
124
|
+
documentation_uri: https://www.rubydoc.info/gems/formtastic_tristate_radio
|
141
125
|
homepage_uri: https://github.com/sergeypedan/formtastic-tristate-radio
|
142
126
|
source_code_uri: https://github.com/sergeypedan/formtastic-tristate-radio
|
143
|
-
post_install_message:
|
127
|
+
post_install_message:
|
144
128
|
rdoc_options:
|
145
129
|
- "--charset=UTF-8"
|
146
130
|
require_paths:
|
147
|
-
- lib
|
148
131
|
- app/inputs
|
149
132
|
- app/models/active_record
|
150
133
|
- config/initializers
|
151
134
|
- config/locales
|
135
|
+
- lib
|
152
136
|
required_ruby_version: !ruby/object:Gem::Requirement
|
153
137
|
requirements:
|
154
138
|
- - ">="
|
@@ -160,8 +144,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
160
144
|
- !ruby/object:Gem::Version
|
161
145
|
version: '0'
|
162
146
|
requirements: []
|
163
|
-
|
164
|
-
|
147
|
+
rubyforge_project:
|
148
|
+
rubygems_version: 2.5.2.3
|
149
|
+
signing_key:
|
165
150
|
specification_version: 4
|
166
151
|
summary: Have 3-state radiobuttons instead of a 2-state checkbox for your Boolean
|
167
152
|
columns which can store NULL
|