protos-protoform 0.0.2 → 0.1.1
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/.rubocop.yml +1 -1
- data/CHANGELOG.md +20 -2
- data/Gemfile.lock +103 -87
- data/lib/protoform/field_collection.rb +2 -2
- data/lib/protoform/namespace.rb +4 -4
- data/lib/protoform/namespace_collection.rb +2 -2
- data/lib/protoform/rails/component.rb +2 -0
- data/lib/protoform/rails/components/button.rb +2 -1
- data/lib/protoform/rails/components/component.rb +6 -0
- data/lib/protoform/rails/components/date.rb +41 -0
- data/lib/protoform/rails/components/datetime.rb +46 -0
- data/lib/protoform/rails/components/input.rb +2 -2
- data/lib/protoform/rails/components/label.rb +10 -2
- data/lib/protoform/rails/components/radio_button.rb +33 -0
- data/lib/protoform/rails/components/select.rb +5 -4
- data/lib/protoform/rails/components/time.rb +46 -0
- data/lib/protoform/rails/form/field.rb +16 -0
- data/lib/protoform/rails/form.rb +18 -5
- data/lib/protoform/rails/option_mapper.rb +2 -0
- data/lib/protoform/version.rb +1 -1
- data/protos-protoform.gemspec +5 -3
- metadata +40 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3bc26745e32d0e8702d9fdb3606083afbe57843fa28ccd02672bf9e03e9d2e03
|
4
|
+
data.tar.gz: 44765738946f4fdd500bbb9e120ba9fa0d744206606bdac925a7abae9fa19ade
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a4268976b1a3658b4f2de87f45570c78d92867931a2712c855bd45022471fda6981e8c2c06ef146bab9b4d740a69984d71cd22c77c3723e59dc0b5f2fefeeb7b
|
7
|
+
data.tar.gz: f39dda31e9dd6527326b09e23111630f407d4c1adb53c2d21e113c668f5684691f78f142a9a43603d40abcd96f18a8b14c319a657aaccc9215de0e27d61b9bd6
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,24 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
-
## [0.
|
3
|
+
## [0.1.1] - 2025-01-26
|
4
|
+
|
5
|
+
- Bumps `protos` to `~> 0.7`
|
6
|
+
- Bumps `activerecord` and `activesupport` requirements to `~> 8.0`
|
7
|
+
- Hides authenticity token and method field when the form has a GET method
|
8
|
+
automatically
|
9
|
+
- Fixes passing symbol values to labels
|
10
|
+
- Fixes passing wrong values to radio button components
|
11
|
+
|
12
|
+
## [0.1.0] - 2024-09-04
|
13
|
+
|
14
|
+
- Adds tests for all Rails components
|
15
|
+
- Adds `Time`, `Datetime`, `Date`, and `RadioButton` components
|
16
|
+
- Fixes a bug in `Button` component calling the wrong method on `attrs`
|
17
|
+
- Bumps supported Ruby version to 3.2
|
18
|
+
- Adds value suffix to labels allowing them to match radio button ids
|
19
|
+
- Bumps `protos` dependency to `v0.6.0`
|
20
|
+
|
21
|
+
## [0.0.2] - 2024-08-14
|
4
22
|
|
5
23
|
- Adds handling client supplied values like files and images
|
6
24
|
- Fixes overriding methods on forms when supplying a Rails model
|
@@ -8,6 +26,6 @@
|
|
8
26
|
- Transfers ownership of repo from `nolantait` to `inhouse-work` organization to
|
9
27
|
match other `protos-` gems
|
10
28
|
|
11
|
-
## [0.1
|
29
|
+
## [0.0.1] - 2023-06-23
|
12
30
|
|
13
31
|
- Initial release
|
data/Gemfile.lock
CHANGED
@@ -1,35 +1,41 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
protos-protoform (0.0
|
4
|
+
protos-protoform (0.1.0)
|
5
|
+
activerecord (~> 8.0)
|
6
|
+
activesupport (~> 8.0)
|
5
7
|
phlex-rails (~> 1.0)
|
6
|
-
protos (~> 0.
|
7
|
-
zeitwerk (~> 2.
|
8
|
+
protos (~> 0.7)
|
9
|
+
zeitwerk (~> 2.7)
|
8
10
|
|
9
11
|
GEM
|
10
12
|
remote: https://rubygems.org/
|
11
13
|
specs:
|
12
|
-
actionpack (
|
13
|
-
actionview (=
|
14
|
-
activesupport (=
|
14
|
+
actionpack (8.0.1)
|
15
|
+
actionview (= 8.0.1)
|
16
|
+
activesupport (= 8.0.1)
|
15
17
|
nokogiri (>= 1.8.5)
|
16
|
-
|
17
|
-
rack (>= 2.2.4, < 3.2)
|
18
|
+
rack (>= 2.2.4)
|
18
19
|
rack-session (>= 1.0.1)
|
19
20
|
rack-test (>= 0.6.3)
|
20
21
|
rails-dom-testing (~> 2.2)
|
21
22
|
rails-html-sanitizer (~> 1.6)
|
22
23
|
useragent (~> 0.16)
|
23
|
-
actionview (
|
24
|
-
activesupport (=
|
24
|
+
actionview (8.0.1)
|
25
|
+
activesupport (= 8.0.1)
|
25
26
|
builder (~> 3.1)
|
26
27
|
erubi (~> 1.11)
|
27
28
|
rails-dom-testing (~> 2.2)
|
28
29
|
rails-html-sanitizer (~> 1.6)
|
29
|
-
activemodel (
|
30
|
-
activesupport (=
|
31
|
-
|
30
|
+
activemodel (8.0.1)
|
31
|
+
activesupport (= 8.0.1)
|
32
|
+
activerecord (8.0.1)
|
33
|
+
activemodel (= 8.0.1)
|
34
|
+
activesupport (= 8.0.1)
|
35
|
+
timeout (>= 0.4.0)
|
36
|
+
activesupport (8.0.1)
|
32
37
|
base64
|
38
|
+
benchmark (>= 0.3)
|
33
39
|
bigdecimal
|
34
40
|
concurrent-ruby (~> 1.0, >= 1.3.1)
|
35
41
|
connection_pool (>= 2.2.5)
|
@@ -39,11 +45,13 @@ GEM
|
|
39
45
|
minitest (>= 5.1)
|
40
46
|
securerandom (>= 0.3)
|
41
47
|
tzinfo (~> 2.0, >= 2.0.5)
|
48
|
+
uri (>= 0.13.1)
|
42
49
|
addressable (2.8.7)
|
43
50
|
public_suffix (>= 2.0.2, < 7.0)
|
44
51
|
ast (2.4.2)
|
45
52
|
base64 (0.2.0)
|
46
|
-
|
53
|
+
benchmark (0.4.0)
|
54
|
+
bigdecimal (3.1.9)
|
47
55
|
builder (3.3.0)
|
48
56
|
capybara (3.40.0)
|
49
57
|
addressable
|
@@ -54,99 +62,107 @@ GEM
|
|
54
62
|
rack-test (>= 0.6.3)
|
55
63
|
regexp_parser (>= 1.5, < 3.0)
|
56
64
|
xpath (~> 3.2)
|
57
|
-
concurrent-ruby (1.3.
|
58
|
-
connection_pool (2.
|
65
|
+
concurrent-ruby (1.3.5)
|
66
|
+
connection_pool (2.5.0)
|
59
67
|
crass (1.0.6)
|
60
|
-
|
68
|
+
date (3.4.1)
|
69
|
+
debug (1.10.0)
|
61
70
|
irb (~> 1.10)
|
62
71
|
reline (>= 0.3.8)
|
63
72
|
diff-lcs (1.5.1)
|
64
73
|
drb (2.2.1)
|
65
|
-
dry-core (1.0
|
74
|
+
dry-core (1.1.0)
|
66
75
|
concurrent-ruby (~> 1.0)
|
76
|
+
logger
|
67
77
|
zeitwerk (~> 2.6)
|
68
|
-
dry-inflector (1.
|
69
|
-
dry-initializer (3.
|
70
|
-
dry-logic (1.
|
78
|
+
dry-inflector (1.2.0)
|
79
|
+
dry-initializer (3.2.0)
|
80
|
+
dry-logic (1.6.0)
|
81
|
+
bigdecimal
|
71
82
|
concurrent-ruby (~> 1.0)
|
72
|
-
dry-core (~> 1.
|
83
|
+
dry-core (~> 1.1)
|
73
84
|
zeitwerk (~> 2.6)
|
74
|
-
dry-types (1.
|
85
|
+
dry-types (1.8.1)
|
75
86
|
bigdecimal (~> 3.0)
|
76
87
|
concurrent-ruby (~> 1.0)
|
77
88
|
dry-core (~> 1.0)
|
78
89
|
dry-inflector (~> 1.0)
|
79
90
|
dry-logic (~> 1.4)
|
80
91
|
zeitwerk (~> 2.6)
|
81
|
-
erubi (1.13.
|
82
|
-
i18n (1.14.
|
92
|
+
erubi (1.13.1)
|
93
|
+
i18n (1.14.7)
|
83
94
|
concurrent-ruby (~> 1.0)
|
84
|
-
io-console (0.
|
85
|
-
irb (1.
|
95
|
+
io-console (0.8.0)
|
96
|
+
irb (1.15.1)
|
97
|
+
pp (>= 0.6.0)
|
86
98
|
rdoc (>= 4.0.0)
|
87
99
|
reline (>= 0.4.2)
|
88
|
-
json (2.
|
100
|
+
json (2.9.1)
|
89
101
|
language_server-protocol (3.17.0.3)
|
90
|
-
logger (1.6.
|
91
|
-
loofah (2.
|
102
|
+
logger (1.6.5)
|
103
|
+
loofah (2.24.0)
|
92
104
|
crass (~> 1.0.2)
|
93
105
|
nokogiri (>= 1.12.0)
|
94
|
-
lru_redux (1.1.0)
|
95
106
|
matrix (0.4.2)
|
96
107
|
mini_mime (1.1.5)
|
97
|
-
|
98
|
-
|
108
|
+
mini_portile2 (2.8.8)
|
109
|
+
minitest (5.25.4)
|
110
|
+
nokogiri (1.18.2)
|
111
|
+
mini_portile2 (~> 2.8.2)
|
99
112
|
racc (~> 1.4)
|
100
|
-
nokogiri (1.
|
113
|
+
nokogiri (1.18.2-aarch64-linux-gnu)
|
101
114
|
racc (~> 1.4)
|
102
|
-
nokogiri (1.
|
115
|
+
nokogiri (1.18.2-arm-linux-gnu)
|
103
116
|
racc (~> 1.4)
|
104
|
-
nokogiri (1.
|
117
|
+
nokogiri (1.18.2-arm64-darwin)
|
105
118
|
racc (~> 1.4)
|
106
|
-
nokogiri (1.
|
119
|
+
nokogiri (1.18.2-x86_64-darwin)
|
107
120
|
racc (~> 1.4)
|
108
|
-
nokogiri (1.
|
121
|
+
nokogiri (1.18.2-x86_64-linux-gnu)
|
109
122
|
racc (~> 1.4)
|
110
|
-
parallel (1.26.
|
111
|
-
parser (3.3.
|
123
|
+
parallel (1.26.3)
|
124
|
+
parser (3.3.7.0)
|
112
125
|
ast (~> 2.4.1)
|
113
126
|
racc
|
114
127
|
phlex (1.11.0)
|
115
|
-
phlex-rails (1.
|
116
|
-
phlex (
|
117
|
-
railties (>= 6.1, <
|
118
|
-
zeitwerk (~> 2.6)
|
128
|
+
phlex-rails (1.2.2)
|
129
|
+
phlex (>= 1.10, < 2)
|
130
|
+
railties (>= 6.1, < 9)
|
119
131
|
phlex-testing-capybara (0.1.0)
|
120
132
|
capybara (~> 3.38)
|
121
133
|
phlex (>= 0.5)
|
122
|
-
|
134
|
+
pp (0.6.2)
|
135
|
+
prettyprint
|
136
|
+
prettyprint (0.2.0)
|
137
|
+
protos (0.7.0)
|
123
138
|
dry-core (~> 1.0)
|
124
139
|
dry-initializer (~> 3.1)
|
125
140
|
dry-types (~> 1.7)
|
126
141
|
phlex (~> 1.10)
|
127
142
|
tailwind_merge (~> 0.10)
|
128
|
-
psych (5.
|
143
|
+
psych (5.2.3)
|
144
|
+
date
|
129
145
|
stringio
|
130
146
|
public_suffix (6.0.1)
|
131
147
|
racc (1.8.1)
|
132
|
-
rack (3.1.
|
133
|
-
rack-session (2.
|
148
|
+
rack (3.1.8)
|
149
|
+
rack-session (2.1.0)
|
150
|
+
base64 (>= 0.1.0)
|
134
151
|
rack (>= 3.0.0)
|
135
|
-
rack-test (2.
|
152
|
+
rack-test (2.2.0)
|
136
153
|
rack (>= 1.3)
|
137
|
-
rackup (2.1
|
154
|
+
rackup (2.2.1)
|
138
155
|
rack (>= 3)
|
139
|
-
webrick (~> 1.8)
|
140
156
|
rails-dom-testing (2.2.0)
|
141
157
|
activesupport (>= 5.0.0)
|
142
158
|
minitest
|
143
159
|
nokogiri (>= 1.6)
|
144
|
-
rails-html-sanitizer (1.6.
|
160
|
+
rails-html-sanitizer (1.6.2)
|
145
161
|
loofah (~> 2.21)
|
146
|
-
nokogiri (
|
147
|
-
railties (
|
148
|
-
actionpack (=
|
149
|
-
activesupport (=
|
162
|
+
nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
|
163
|
+
railties (8.0.1)
|
164
|
+
actionpack (= 8.0.1)
|
165
|
+
activesupport (= 8.0.1)
|
150
166
|
irb (~> 1.13)
|
151
167
|
rackup (>= 1.0.0)
|
152
168
|
rake (>= 12.2)
|
@@ -154,44 +170,41 @@ GEM
|
|
154
170
|
zeitwerk (~> 2.6)
|
155
171
|
rainbow (3.1.1)
|
156
172
|
rake (13.2.1)
|
157
|
-
rdoc (6.
|
173
|
+
rdoc (6.11.0)
|
158
174
|
psych (>= 4.0.0)
|
159
|
-
regexp_parser (2.
|
160
|
-
reline (0.
|
175
|
+
regexp_parser (2.10.0)
|
176
|
+
reline (0.6.0)
|
161
177
|
io-console (~> 0.5)
|
162
|
-
rexml (3.3.5)
|
163
|
-
strscan
|
164
178
|
rspec (3.13.0)
|
165
179
|
rspec-core (~> 3.13.0)
|
166
180
|
rspec-expectations (~> 3.13.0)
|
167
181
|
rspec-mocks (~> 3.13.0)
|
168
|
-
rspec-core (3.13.
|
182
|
+
rspec-core (3.13.2)
|
169
183
|
rspec-support (~> 3.13.0)
|
170
|
-
rspec-expectations (3.13.
|
184
|
+
rspec-expectations (3.13.3)
|
171
185
|
diff-lcs (>= 1.2.0, < 2.0)
|
172
186
|
rspec-support (~> 3.13.0)
|
173
|
-
rspec-mocks (3.13.
|
187
|
+
rspec-mocks (3.13.2)
|
174
188
|
diff-lcs (>= 1.2.0, < 2.0)
|
175
189
|
rspec-support (~> 3.13.0)
|
176
|
-
rspec-support (3.13.
|
177
|
-
rubocop (1.
|
190
|
+
rspec-support (3.13.2)
|
191
|
+
rubocop (1.71.0)
|
178
192
|
json (~> 2.3)
|
179
193
|
language_server-protocol (>= 3.17.0)
|
180
194
|
parallel (~> 1.10)
|
181
195
|
parser (>= 3.3.0.2)
|
182
196
|
rainbow (>= 2.2.2, < 4.0)
|
183
|
-
regexp_parser (>= 2.
|
184
|
-
|
185
|
-
rubocop-ast (>= 1.31.1, < 2.0)
|
197
|
+
regexp_parser (>= 2.9.3, < 3.0)
|
198
|
+
rubocop-ast (>= 1.36.2, < 2.0)
|
186
199
|
ruby-progressbar (~> 1.7)
|
187
|
-
unicode-display_width (>= 2.4.0, <
|
188
|
-
rubocop-ast (1.
|
200
|
+
unicode-display_width (>= 2.4.0, < 4.0)
|
201
|
+
rubocop-ast (1.37.0)
|
189
202
|
parser (>= 3.3.1.0)
|
190
203
|
rubocop-capybara (2.21.0)
|
191
204
|
rubocop (~> 1.41)
|
192
205
|
rubocop-factory_bot (2.26.1)
|
193
206
|
rubocop (~> 1.61)
|
194
|
-
rubocop-inhouse (0.
|
207
|
+
rubocop-inhouse (0.2.2)
|
195
208
|
rubocop (>= 1.5)
|
196
209
|
rubocop-capybara (>= 2.1)
|
197
210
|
rubocop-factory_bot (>= 2.2)
|
@@ -200,36 +213,39 @@ GEM
|
|
200
213
|
rubocop-rake (>= 0.6)
|
201
214
|
rubocop-rspec (>= 2.2)
|
202
215
|
rubocop-rspec_rails (>= 2.2)
|
203
|
-
rubocop-performance (1.
|
216
|
+
rubocop-performance (1.23.1)
|
204
217
|
rubocop (>= 1.48.1, < 2.0)
|
205
218
|
rubocop-ast (>= 1.31.1, < 2.0)
|
206
|
-
rubocop-rails (2.
|
219
|
+
rubocop-rails (2.29.1)
|
207
220
|
activesupport (>= 4.2.0)
|
208
221
|
rack (>= 1.1)
|
209
|
-
rubocop (>= 1.
|
222
|
+
rubocop (>= 1.52.0, < 2.0)
|
210
223
|
rubocop-ast (>= 1.31.1, < 2.0)
|
211
224
|
rubocop-rake (0.6.0)
|
212
225
|
rubocop (~> 1.0)
|
213
|
-
rubocop-rspec (3.0
|
226
|
+
rubocop-rspec (3.4.0)
|
214
227
|
rubocop (~> 1.61)
|
215
228
|
rubocop-rspec_rails (2.30.0)
|
216
229
|
rubocop (~> 1.61)
|
217
230
|
rubocop-rspec (~> 3, >= 3.0.1)
|
218
231
|
ruby-progressbar (1.13.0)
|
219
|
-
securerandom (0.
|
220
|
-
|
221
|
-
|
222
|
-
tailwind_merge (0.
|
223
|
-
|
224
|
-
thor (1.3.
|
232
|
+
securerandom (0.4.1)
|
233
|
+
sin_lru_redux (2.5.0)
|
234
|
+
stringio (3.1.2)
|
235
|
+
tailwind_merge (0.16.0)
|
236
|
+
sin_lru_redux (~> 2.5)
|
237
|
+
thor (1.3.2)
|
238
|
+
timeout (0.4.3)
|
225
239
|
tzinfo (2.0.6)
|
226
240
|
concurrent-ruby (~> 1.0)
|
227
|
-
unicode-display_width (
|
228
|
-
|
229
|
-
|
241
|
+
unicode-display_width (3.1.4)
|
242
|
+
unicode-emoji (~> 4.0, >= 4.0.4)
|
243
|
+
unicode-emoji (4.0.4)
|
244
|
+
uri (1.0.2)
|
245
|
+
useragent (0.16.11)
|
230
246
|
xpath (3.2.0)
|
231
247
|
nokogiri (~> 1.8)
|
232
|
-
zeitwerk (2.
|
248
|
+
zeitwerk (2.7.1)
|
233
249
|
|
234
250
|
PLATFORMS
|
235
251
|
aarch64-linux
|
@@ -249,4 +265,4 @@ DEPENDENCIES
|
|
249
265
|
rubocop-inhouse
|
250
266
|
|
251
267
|
BUNDLED WITH
|
252
|
-
2.
|
268
|
+
2.6.2
|
data/lib/protoform/namespace.rb
CHANGED
@@ -120,8 +120,8 @@ module Protoform
|
|
120
120
|
end
|
121
121
|
|
122
122
|
# Creates a root Namespace, which is essentially a form.
|
123
|
-
def self.root(
|
124
|
-
new(
|
123
|
+
def self.root(*, **, &block)
|
124
|
+
new(*, parent: nil, **, &block)
|
125
125
|
end
|
126
126
|
|
127
127
|
protected
|
@@ -141,7 +141,7 @@ module Protoform
|
|
141
141
|
|
142
142
|
# Checks if the child exists. If it does then it returns that. If it
|
143
143
|
# doesn't, it will build the child.
|
144
|
-
def create_child(key:, child_class:,
|
144
|
+
def create_child(key:, child_class:, **, &block)
|
145
145
|
if (child = @children.fetch(key, nil))
|
146
146
|
# ensure that found children are also yielded
|
147
147
|
child.tap { yield child if block }
|
@@ -150,7 +150,7 @@ module Protoform
|
|
150
150
|
@children[key] = child_class.new(
|
151
151
|
key,
|
152
152
|
parent: self,
|
153
|
-
|
153
|
+
**,
|
154
154
|
&block
|
155
155
|
)
|
156
156
|
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "active_support/core_ext/string/inflections"
|
4
|
+
|
3
5
|
module Protoform
|
4
6
|
module Rails
|
5
7
|
module Components
|
@@ -9,6 +11,10 @@ module Protoform
|
|
9
11
|
def dom
|
10
12
|
field.dom
|
11
13
|
end
|
14
|
+
|
15
|
+
def title
|
16
|
+
field.key.to_s.titleize
|
17
|
+
end
|
12
18
|
end
|
13
19
|
end
|
14
20
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Protoform
|
4
|
+
module Rails
|
5
|
+
module Components
|
6
|
+
class Date < Input
|
7
|
+
option :value, default: -> { field.value }
|
8
|
+
option :min, default: -> { }
|
9
|
+
option :max, default: -> { }
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def default_attrs
|
14
|
+
super.merge(
|
15
|
+
{
|
16
|
+
type: "date",
|
17
|
+
value: date_value(value)
|
18
|
+
}
|
19
|
+
).tap do |attrs|
|
20
|
+
attrs[:min] = date_value(min) if min
|
21
|
+
attrs[:max] = date_value(max) if max
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def date_value(value)
|
26
|
+
return unless value
|
27
|
+
|
28
|
+
if value.is_a?(String)
|
29
|
+
value = begin
|
30
|
+
Datetime.parse(value)
|
31
|
+
rescue Date::Error
|
32
|
+
nil
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
value.strftime("%Y-%m-%d")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Protoform
|
4
|
+
module Rails
|
5
|
+
module Components
|
6
|
+
class Datetime < Input
|
7
|
+
option :value, default: -> { field.value }
|
8
|
+
option :include_seconds, default: -> { true }, reader: false
|
9
|
+
option :min, default: -> { }
|
10
|
+
option :max, default: -> { }
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def default_attrs
|
15
|
+
super.merge(
|
16
|
+
{
|
17
|
+
type: "datetime-local",
|
18
|
+
value: datetime_value(value)
|
19
|
+
}
|
20
|
+
).tap do |attrs|
|
21
|
+
attrs[:min] = datetime_value(min) if min
|
22
|
+
attrs[:max] = datetime_value(max) if max
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def datetime_value(value)
|
27
|
+
return unless value
|
28
|
+
|
29
|
+
if value.is_a?(String)
|
30
|
+
value = begin
|
31
|
+
Datetime.parse(value)
|
32
|
+
rescue Date::Error
|
33
|
+
nil
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
if @include_seconds
|
38
|
+
value.strftime("%Y-%m-%dT%T")
|
39
|
+
else
|
40
|
+
value.strftime("%Y-%m-%dT%H:%M")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -4,16 +4,24 @@ module Protoform
|
|
4
4
|
module Rails
|
5
5
|
module Components
|
6
6
|
class Label < Component
|
7
|
+
option :value, default: -> { }
|
8
|
+
|
7
9
|
def view_template(&content)
|
8
|
-
content ||= proc {
|
10
|
+
content ||= proc { title }
|
9
11
|
label(**attrs, &content)
|
10
12
|
end
|
11
13
|
|
12
14
|
private
|
13
15
|
|
16
|
+
def label_id
|
17
|
+
return dom.id unless value
|
18
|
+
|
19
|
+
[dom.id, value.to_s.parameterize.underscore].join("_")
|
20
|
+
end
|
21
|
+
|
14
22
|
def default_attrs
|
15
23
|
{
|
16
|
-
for:
|
24
|
+
for: label_id
|
17
25
|
}
|
18
26
|
end
|
19
27
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Protoform
|
4
|
+
module Rails
|
5
|
+
module Components
|
6
|
+
class RadioButton < Input
|
7
|
+
# This makes value manditory in this class instead of being absorbed by
|
8
|
+
# the html_options hash from Protos.
|
9
|
+
option :value
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def radio_id
|
14
|
+
[dom.id, value.to_s.parameterize.underscore].join("_")
|
15
|
+
end
|
16
|
+
|
17
|
+
def checked?
|
18
|
+
dom.value == field.value
|
19
|
+
end
|
20
|
+
|
21
|
+
def default_attrs
|
22
|
+
{
|
23
|
+
id: radio_id,
|
24
|
+
name: dom.name,
|
25
|
+
value:,
|
26
|
+
type: "radio",
|
27
|
+
checked: checked? ? "checked" : false
|
28
|
+
}
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -31,10 +31,7 @@ module Protoform
|
|
31
31
|
|
32
32
|
def options(*collection)
|
33
33
|
map_options(collection).each do |key, value|
|
34
|
-
option(
|
35
|
-
selected: selected_value_for(key) ? "selected" : false,
|
36
|
-
value: key
|
37
|
-
) { value }
|
34
|
+
option(selected: selected_value_for(key), value: key) { value }
|
38
35
|
end
|
39
36
|
end
|
40
37
|
|
@@ -53,6 +50,10 @@ module Protoform
|
|
53
50
|
protected
|
54
51
|
|
55
52
|
def selected_value_for(key)
|
53
|
+
selected?(key) ? "selected" : false
|
54
|
+
end
|
55
|
+
|
56
|
+
def selected?(key)
|
56
57
|
case field.value
|
57
58
|
when String, Symbol
|
58
59
|
field.value.to_s == key.to_s
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Protoform
|
4
|
+
module Rails
|
5
|
+
module Components
|
6
|
+
class Time < Input
|
7
|
+
option :value, default: -> { field.value }
|
8
|
+
option :include_seconds, default: -> { true }, reader: false
|
9
|
+
option :min, default: -> { }
|
10
|
+
option :max, default: -> { }
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def default_attrs
|
15
|
+
super.merge(
|
16
|
+
{
|
17
|
+
type: "time",
|
18
|
+
value: time_value(value)
|
19
|
+
}
|
20
|
+
).tap do |attrs|
|
21
|
+
attrs[:min] = time_value(min) if min
|
22
|
+
attrs[:max] = time_value(max) if max
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def time_value(value)
|
27
|
+
return unless value
|
28
|
+
|
29
|
+
if value.is_a?(String)
|
30
|
+
value = begin
|
31
|
+
Datetime.parse(value)
|
32
|
+
rescue Date::Error
|
33
|
+
nil
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
if @include_seconds
|
38
|
+
value.strftime("%T.%L")
|
39
|
+
else
|
40
|
+
value.strftime("%H:%M")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -36,6 +36,22 @@ module Protoform
|
|
36
36
|
Components::Checkbox.new(self, ...)
|
37
37
|
end
|
38
38
|
|
39
|
+
def date(...)
|
40
|
+
Components::Date.new(self, ...)
|
41
|
+
end
|
42
|
+
|
43
|
+
def time(...)
|
44
|
+
Components::Time.new(self, ...)
|
45
|
+
end
|
46
|
+
|
47
|
+
def datetime(...)
|
48
|
+
Components::Datetime.new(self, ...)
|
49
|
+
end
|
50
|
+
|
51
|
+
def radio_button(value, **)
|
52
|
+
Components::RadioButton.new(self, value:, **)
|
53
|
+
end
|
54
|
+
|
39
55
|
def label(...)
|
40
56
|
Components::Label.new(self, ...)
|
41
57
|
end
|
data/lib/protoform/rails/form.rb
CHANGED
@@ -16,11 +16,11 @@ module Protoform
|
|
16
16
|
class Form < Component
|
17
17
|
param :model, reader: false
|
18
18
|
option :authenticity_token, reader: false, default: -> { true }
|
19
|
-
option :helpers, reader: false, default: -> {}
|
20
|
-
option :action, reader: false, default: -> {}
|
19
|
+
option :helpers, reader: false, default: -> { }
|
20
|
+
option :action, reader: false, default: -> { }
|
21
21
|
option :method,
|
22
22
|
reader: false,
|
23
|
-
default: -> {}
|
23
|
+
default: -> { }
|
24
24
|
option :namespace, reader: false, default: -> do
|
25
25
|
Namespace.root(key, object: @model, field_class: self.class::Field)
|
26
26
|
end
|
@@ -47,9 +47,9 @@ module Protoform
|
|
47
47
|
|
48
48
|
def around_template(&block)
|
49
49
|
form_tag do
|
50
|
-
authenticity_token_field if
|
50
|
+
authenticity_token_field if authenticity_token?
|
51
|
+
_method_field if method_field?
|
51
52
|
|
52
|
-
_method_field
|
53
53
|
super
|
54
54
|
end
|
55
55
|
end
|
@@ -83,6 +83,19 @@ module Protoform
|
|
83
83
|
|
84
84
|
protected
|
85
85
|
|
86
|
+
def authenticity_token?
|
87
|
+
return false if _method_field_value == :get
|
88
|
+
|
89
|
+
@authenticity_token
|
90
|
+
end
|
91
|
+
|
92
|
+
def method_field?
|
93
|
+
return false if _method_field_value == :post
|
94
|
+
return false if _method_field_value == :get
|
95
|
+
|
96
|
+
true
|
97
|
+
end
|
98
|
+
|
86
99
|
def authenticity_token_field
|
87
100
|
input(
|
88
101
|
name: "authenticity_token",
|
data/lib/protoform/version.rb
CHANGED
data/protos-protoform.gemspec
CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
|
|
12
12
|
spec.description = "Build phlex based forms using Rails conventions"
|
13
13
|
spec.homepage = "https://github.com/inhouse-work/protos-protoform"
|
14
14
|
spec.license = "MIT"
|
15
|
-
spec.required_ruby_version = ">= 3.
|
15
|
+
spec.required_ruby_version = ">= 3.2.0"
|
16
16
|
|
17
17
|
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
18
18
|
|
@@ -42,8 +42,10 @@ Gem::Specification.new do |spec|
|
|
42
42
|
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
43
43
|
spec.require_paths = ["lib"]
|
44
44
|
|
45
|
+
spec.add_dependency "activerecord", "~> 8.0"
|
46
|
+
spec.add_dependency "activesupport", "~> 8.0"
|
45
47
|
spec.add_dependency "phlex-rails", "~> 1.0"
|
46
|
-
spec.add_dependency "protos", "~> 0.
|
47
|
-
spec.add_dependency "zeitwerk", "~> 2.
|
48
|
+
spec.add_dependency "protos", "~> 0.7"
|
49
|
+
spec.add_dependency "zeitwerk", "~> 2.7"
|
48
50
|
spec.metadata["rubygems_mfa_required"] = "true"
|
49
51
|
end
|
metadata
CHANGED
@@ -1,15 +1,42 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: protos-protoform
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nolan Tait
|
8
|
-
autorequire:
|
9
8
|
bindir: exe
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-01-27 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
12
|
+
- !ruby/object:Gem::Dependency
|
13
|
+
name: activerecord
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - "~>"
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: '8.0'
|
19
|
+
type: :runtime
|
20
|
+
prerelease: false
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
requirements:
|
23
|
+
- - "~>"
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: '8.0'
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: activesupport
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - "~>"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '8.0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '8.0'
|
13
40
|
- !ruby/object:Gem::Dependency
|
14
41
|
name: phlex-rails
|
15
42
|
requirement: !ruby/object:Gem::Requirement
|
@@ -30,28 +57,28 @@ dependencies:
|
|
30
57
|
requirements:
|
31
58
|
- - "~>"
|
32
59
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0.
|
60
|
+
version: '0.7'
|
34
61
|
type: :runtime
|
35
62
|
prerelease: false
|
36
63
|
version_requirements: !ruby/object:Gem::Requirement
|
37
64
|
requirements:
|
38
65
|
- - "~>"
|
39
66
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0.
|
67
|
+
version: '0.7'
|
41
68
|
- !ruby/object:Gem::Dependency
|
42
69
|
name: zeitwerk
|
43
70
|
requirement: !ruby/object:Gem::Requirement
|
44
71
|
requirements:
|
45
72
|
- - "~>"
|
46
73
|
- !ruby/object:Gem::Version
|
47
|
-
version: '2.
|
74
|
+
version: '2.7'
|
48
75
|
type: :runtime
|
49
76
|
prerelease: false
|
50
77
|
version_requirements: !ruby/object:Gem::Requirement
|
51
78
|
requirements:
|
52
79
|
- - "~>"
|
53
80
|
- !ruby/object:Gem::Version
|
54
|
-
version: '2.
|
81
|
+
version: '2.7'
|
55
82
|
description: Build phlex based forms using Rails conventions
|
56
83
|
email:
|
57
84
|
- nolanjtait@gmail.com
|
@@ -81,11 +108,15 @@ files:
|
|
81
108
|
- lib/protoform/rails/components/button.rb
|
82
109
|
- lib/protoform/rails/components/checkbox.rb
|
83
110
|
- lib/protoform/rails/components/component.rb
|
111
|
+
- lib/protoform/rails/components/date.rb
|
112
|
+
- lib/protoform/rails/components/datetime.rb
|
84
113
|
- lib/protoform/rails/components/field_component.rb
|
85
114
|
- lib/protoform/rails/components/input.rb
|
86
115
|
- lib/protoform/rails/components/label.rb
|
116
|
+
- lib/protoform/rails/components/radio_button.rb
|
87
117
|
- lib/protoform/rails/components/select.rb
|
88
118
|
- lib/protoform/rails/components/textarea.rb
|
119
|
+
- lib/protoform/rails/components/time.rb
|
89
120
|
- lib/protoform/rails/form.rb
|
90
121
|
- lib/protoform/rails/form/field.rb
|
91
122
|
- lib/protoform/rails/option_mapper.rb
|
@@ -101,7 +132,6 @@ metadata:
|
|
101
132
|
source_code_uri: https://github.com/inhouse-work/protos-protoform
|
102
133
|
changelog_uri: https://github.com/inhouse-work/protos-protoform
|
103
134
|
rubygems_mfa_required: 'true'
|
104
|
-
post_install_message:
|
105
135
|
rdoc_options: []
|
106
136
|
require_paths:
|
107
137
|
- lib
|
@@ -109,15 +139,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
109
139
|
requirements:
|
110
140
|
- - ">="
|
111
141
|
- !ruby/object:Gem::Version
|
112
|
-
version: 3.
|
142
|
+
version: 3.2.0
|
113
143
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
144
|
requirements:
|
115
145
|
- - ">="
|
116
146
|
- !ruby/object:Gem::Version
|
117
147
|
version: '0'
|
118
148
|
requirements: []
|
119
|
-
rubygems_version: 3.
|
120
|
-
signing_key:
|
149
|
+
rubygems_version: 3.6.2
|
121
150
|
specification_version: 4
|
122
151
|
summary: Phlex based form builder for Rails
|
123
152
|
test_files: []
|