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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fc22975fd2a29b54b0e5f1f5a92ef569fc78a3ab35f3a5672b8705703357c8e1
4
- data.tar.gz: d249529bf058a94369abb9aebd56b4d5b0a68faab4c00831c57a6aa9373fc9c5
3
+ metadata.gz: 3bc26745e32d0e8702d9fdb3606083afbe57843fa28ccd02672bf9e03e9d2e03
4
+ data.tar.gz: 44765738946f4fdd500bbb9e120ba9fa0d744206606bdac925a7abae9fa19ade
5
5
  SHA512:
6
- metadata.gz: d45f5a2705117c6b87a225ec72c8f72605b8573907f9cd71e232a968ec5b2f0f4014d0250ae19ab1b78a83a82cddbdd9608e6d258028159d8e40eaed955eb17e
7
- data.tar.gz: 2dffae4a6e8875b96075542e0d5a5218f0639933f8cc2d10f4b9a502c5a7ec6066d0153e39bbef9ddc08b54e13c9e356a7c84aafa58752422b35bc31488b6806
6
+ metadata.gz: a4268976b1a3658b4f2de87f45570c78d92867931a2712c855bd45022471fda6981e8c2c06ef146bab9b4d740a69984d71cd22c77c3723e59dc0b5f2fefeeb7b
7
+ data.tar.gz: f39dda31e9dd6527326b09e23111630f407d4c1adb53c2d21e113c668f5684691f78f142a9a43603d40abcd96f18a8b14c319a657aaccc9215de0e27d61b9bd6
data/.rubocop.yml CHANGED
@@ -6,4 +6,4 @@ inherit_gem:
6
6
  - config/default.yml
7
7
 
8
8
  AllCops:
9
- TargetRubyVersion: 3.1
9
+ TargetRubyVersion: 3.2
data/CHANGELOG.md CHANGED
@@ -1,6 +1,24 @@
1
1
  ## [Unreleased]
2
2
 
3
- ## [0.2.0] - 2024-08-14
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.0] - 2023-06-23
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.1)
4
+ protos-protoform (0.1.0)
5
+ activerecord (~> 8.0)
6
+ activesupport (~> 8.0)
5
7
  phlex-rails (~> 1.0)
6
- protos (~> 0.4)
7
- zeitwerk (~> 2.6)
8
+ protos (~> 0.7)
9
+ zeitwerk (~> 2.7)
8
10
 
9
11
  GEM
10
12
  remote: https://rubygems.org/
11
13
  specs:
12
- actionpack (7.2.0)
13
- actionview (= 7.2.0)
14
- activesupport (= 7.2.0)
14
+ actionpack (8.0.1)
15
+ actionview (= 8.0.1)
16
+ activesupport (= 8.0.1)
15
17
  nokogiri (>= 1.8.5)
16
- racc
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 (7.2.0)
24
- activesupport (= 7.2.0)
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 (7.2.0)
30
- activesupport (= 7.2.0)
31
- activesupport (7.2.0)
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
- bigdecimal (3.1.8)
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.4)
58
- connection_pool (2.4.1)
65
+ concurrent-ruby (1.3.5)
66
+ connection_pool (2.5.0)
59
67
  crass (1.0.6)
60
- debug (1.9.2)
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.1)
74
+ dry-core (1.1.0)
66
75
  concurrent-ruby (~> 1.0)
76
+ logger
67
77
  zeitwerk (~> 2.6)
68
- dry-inflector (1.1.0)
69
- dry-initializer (3.1.1)
70
- dry-logic (1.5.0)
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.0, < 2)
83
+ dry-core (~> 1.1)
73
84
  zeitwerk (~> 2.6)
74
- dry-types (1.7.2)
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.0)
82
- i18n (1.14.5)
92
+ erubi (1.13.1)
93
+ i18n (1.14.7)
83
94
  concurrent-ruby (~> 1.0)
84
- io-console (0.7.2)
85
- irb (1.14.0)
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.7.2)
100
+ json (2.9.1)
89
101
  language_server-protocol (3.17.0.3)
90
- logger (1.6.0)
91
- loofah (2.22.0)
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
- minitest (5.25.0)
98
- nokogiri (1.16.7-aarch64-linux)
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.16.7-arm-linux)
113
+ nokogiri (1.18.2-aarch64-linux-gnu)
101
114
  racc (~> 1.4)
102
- nokogiri (1.16.7-arm64-darwin)
115
+ nokogiri (1.18.2-arm-linux-gnu)
103
116
  racc (~> 1.4)
104
- nokogiri (1.16.7-x86-linux)
117
+ nokogiri (1.18.2-arm64-darwin)
105
118
  racc (~> 1.4)
106
- nokogiri (1.16.7-x86_64-darwin)
119
+ nokogiri (1.18.2-x86_64-darwin)
107
120
  racc (~> 1.4)
108
- nokogiri (1.16.7-x86_64-linux)
121
+ nokogiri (1.18.2-x86_64-linux-gnu)
109
122
  racc (~> 1.4)
110
- parallel (1.26.2)
111
- parser (3.3.4.2)
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.1.1)
116
- phlex (~> 1.9)
117
- railties (>= 6.1, < 8)
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
- protos (0.4.3)
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.1.2)
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.7)
133
- rack-session (2.0.0)
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.1.0)
152
+ rack-test (2.2.0)
136
153
  rack (>= 1.3)
137
- rackup (2.1.0)
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.0)
160
+ rails-html-sanitizer (1.6.2)
145
161
  loofah (~> 2.21)
146
- nokogiri (~> 1.14)
147
- railties (7.2.0)
148
- actionpack (= 7.2.0)
149
- activesupport (= 7.2.0)
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.7.0)
173
+ rdoc (6.11.0)
158
174
  psych (>= 4.0.0)
159
- regexp_parser (2.9.2)
160
- reline (0.5.9)
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.0)
182
+ rspec-core (3.13.2)
169
183
  rspec-support (~> 3.13.0)
170
- rspec-expectations (3.13.1)
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.1)
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.1)
177
- rubocop (1.65.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.4, < 3.0)
184
- rexml (>= 3.2.5, < 4.0)
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, < 3.0)
188
- rubocop-ast (1.32.0)
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.1.9)
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.21.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.25.1)
219
+ rubocop-rails (2.29.1)
207
220
  activesupport (>= 4.2.0)
208
221
  rack (>= 1.1)
209
- rubocop (>= 1.33.0, < 2.0)
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.4)
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.3.1)
220
- stringio (3.1.1)
221
- strscan (3.1.0)
222
- tailwind_merge (0.12.0)
223
- lru_redux (~> 1.1)
224
- thor (1.3.1)
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 (2.5.0)
228
- useragent (0.16.10)
229
- webrick (1.8.1)
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.6.17)
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.5.6
268
+ 2.6.2
@@ -28,8 +28,8 @@ module Protoform
28
28
 
29
29
  private
30
30
 
31
- def build_field(**kwargs)
32
- @field.class.new(current_index, parent: @field, **kwargs)
31
+ def build_field(**)
32
+ @field.class.new(current_index, parent: @field, **)
33
33
  end
34
34
 
35
35
  def current_index
@@ -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(*args, **kwargs, &block)
124
- new(*args, parent: nil, **kwargs, &block)
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:, **kwargs, &block)
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
- **kwargs,
153
+ **,
154
154
  &block
155
155
  )
156
156
  end
@@ -37,12 +37,12 @@ module Protoform
37
37
  end
38
38
  end
39
39
 
40
- def build_namespace(index, **kwargs)
40
+ def build_namespace(index, **)
41
41
  parent.class.new(
42
42
  index,
43
43
  parent: self,
44
44
  field_class: @field_class,
45
- **kwargs,
45
+ **,
46
46
  &@template
47
47
  )
48
48
  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
  Component = ::ApplicationComponent
@@ -12,7 +12,8 @@ module Protoform
12
12
  private
13
13
 
14
14
  def button_text
15
- attrs.fetch(:value, dom.value).titleize
15
+ text = attrs[:value] || dom.value
16
+ text.titleize
16
17
  end
17
18
 
18
19
  def default_attrs
@@ -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
@@ -38,9 +38,9 @@ module Protoform
38
38
  "url"
39
39
  when Integer
40
40
  "number"
41
- when Date, DateTime
41
+ when ::Date, ::DateTime
42
42
  "date"
43
- when Time
43
+ when ::Time
44
44
  "time"
45
45
  else
46
46
  "text"
@@ -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 { field.key.to_s.titleize }
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: dom.id
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
@@ -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 @authenticity_token
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",
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "active_record"
4
+
3
5
  module Protoform
4
6
  module Rails
5
7
  # Accept a collection of objects and map them to options suitable for form
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Protoform
4
- VERSION = "0.0.2"
4
+ VERSION = "0.1.1"
5
5
  end
@@ -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.1.0"
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.4"
47
- spec.add_dependency "zeitwerk", "~> 2.6"
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.0.2
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: 2024-08-15 00:00:00.000000000 Z
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.4'
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.4'
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.6'
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.6'
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.1.0
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.5.17
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: []