phlexible 0.4.2 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +10 -6
- data/Gemfile +2 -2
- data/Gemfile.lock +94 -87
- data/README.md +14 -26
- data/config/sus.rb +1 -1
- data/lib/phlexible/rails/action_controller/implicit_render.rb +10 -2
- data/lib/phlexible/rails/button_to.rb +55 -1
- data/lib/phlexible/rails/controller_attributes.rb +10 -0
- data/lib/phlexible/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8493676006ae7ebce0167e43ea8c323955d82a7b3ced60d37faa5c8a7af207cc
|
4
|
+
data.tar.gz: ef35f7c71e856ce3e7dbee030b5f942f1d1fb23eaddbab94fdc1e410b0f4e98a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fcc9e726abf97bc12cd5de24964c9d0acc9d1372e5d75e661b6a64239e21d36ac4fb7eadaa5f55e00a25e34db8bc4348d226c13d2beecee84427d99ecea02840
|
7
|
+
data.tar.gz: 1cfd851a4238c73d91219bfc4152e5855b52683a3fa67e2d7cfec88e38b92a99a577b391da3cd225c0182fb3c8f5c78c6e307a0ff73954e00d25c54ba39e4031
|
data/.rubocop.yml
CHANGED
@@ -3,16 +3,20 @@ AllCops:
|
|
3
3
|
SuggestExtensions: false
|
4
4
|
NewCops: enable
|
5
5
|
|
6
|
-
Style/Documentation:
|
7
|
-
Enabled: false
|
8
|
-
Metrics/BlockLength:
|
9
|
-
Exclude:
|
10
|
-
- test/**/*
|
11
6
|
Lint/ConstantDefinitionInBlock:
|
12
7
|
Exclude:
|
13
8
|
- test/**/*
|
9
|
+
|
10
|
+
Style/Documentation:
|
11
|
+
Enabled: false
|
14
12
|
Style/ClassAndModuleChildren:
|
15
13
|
Exclude:
|
16
14
|
- fixtures/**/*
|
15
|
+
|
16
|
+
Metrics/BlockLength:
|
17
|
+
Exclude:
|
18
|
+
- test/**/*
|
17
19
|
Metrics/MethodLength:
|
18
|
-
Max:
|
20
|
+
Max: 20
|
21
|
+
Metrics/CyclomaticComplexity:
|
22
|
+
Max: 8
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,79 +1,80 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
phlexible (0.
|
4
|
+
phlexible (0.6.0)
|
5
5
|
phlex (~> 1.8.1)
|
6
6
|
phlex-rails (~> 1.0.0)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
actioncable (7.0.
|
12
|
-
actionpack (= 7.0.
|
13
|
-
activesupport (= 7.0.
|
11
|
+
actioncable (7.0.8)
|
12
|
+
actionpack (= 7.0.8)
|
13
|
+
activesupport (= 7.0.8)
|
14
14
|
nio4r (~> 2.0)
|
15
15
|
websocket-driver (>= 0.6.1)
|
16
|
-
actionmailbox (7.0.
|
17
|
-
actionpack (= 7.0.
|
18
|
-
activejob (= 7.0.
|
19
|
-
activerecord (= 7.0.
|
20
|
-
activestorage (= 7.0.
|
21
|
-
activesupport (= 7.0.
|
16
|
+
actionmailbox (7.0.8)
|
17
|
+
actionpack (= 7.0.8)
|
18
|
+
activejob (= 7.0.8)
|
19
|
+
activerecord (= 7.0.8)
|
20
|
+
activestorage (= 7.0.8)
|
21
|
+
activesupport (= 7.0.8)
|
22
22
|
mail (>= 2.7.1)
|
23
23
|
net-imap
|
24
24
|
net-pop
|
25
25
|
net-smtp
|
26
|
-
actionmailer (7.0.
|
27
|
-
actionpack (= 7.0.
|
28
|
-
actionview (= 7.0.
|
29
|
-
activejob (= 7.0.
|
30
|
-
activesupport (= 7.0.
|
26
|
+
actionmailer (7.0.8)
|
27
|
+
actionpack (= 7.0.8)
|
28
|
+
actionview (= 7.0.8)
|
29
|
+
activejob (= 7.0.8)
|
30
|
+
activesupport (= 7.0.8)
|
31
31
|
mail (~> 2.5, >= 2.5.4)
|
32
32
|
net-imap
|
33
33
|
net-pop
|
34
34
|
net-smtp
|
35
35
|
rails-dom-testing (~> 2.0)
|
36
|
-
actionpack (7.0.
|
37
|
-
actionview (= 7.0.
|
38
|
-
activesupport (= 7.0.
|
39
|
-
rack (~> 2.0, >= 2.2.
|
36
|
+
actionpack (7.0.8)
|
37
|
+
actionview (= 7.0.8)
|
38
|
+
activesupport (= 7.0.8)
|
39
|
+
rack (~> 2.0, >= 2.2.4)
|
40
40
|
rack-test (>= 0.6.3)
|
41
41
|
rails-dom-testing (~> 2.0)
|
42
42
|
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
43
|
-
actiontext (7.0.
|
44
|
-
actionpack (= 7.0.
|
45
|
-
activerecord (= 7.0.
|
46
|
-
activestorage (= 7.0.
|
47
|
-
activesupport (= 7.0.
|
43
|
+
actiontext (7.0.8)
|
44
|
+
actionpack (= 7.0.8)
|
45
|
+
activerecord (= 7.0.8)
|
46
|
+
activestorage (= 7.0.8)
|
47
|
+
activesupport (= 7.0.8)
|
48
48
|
globalid (>= 0.6.0)
|
49
49
|
nokogiri (>= 1.8.5)
|
50
|
-
actionview (7.0.
|
51
|
-
activesupport (= 7.0.
|
50
|
+
actionview (7.0.8)
|
51
|
+
activesupport (= 7.0.8)
|
52
52
|
builder (~> 3.1)
|
53
53
|
erubi (~> 1.4)
|
54
54
|
rails-dom-testing (~> 2.0)
|
55
55
|
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
56
|
-
activejob (7.0.
|
57
|
-
activesupport (= 7.0.
|
56
|
+
activejob (7.0.8)
|
57
|
+
activesupport (= 7.0.8)
|
58
58
|
globalid (>= 0.3.6)
|
59
|
-
activemodel (7.0.
|
60
|
-
activesupport (= 7.0.
|
61
|
-
activerecord (7.0.
|
62
|
-
activemodel (= 7.0.
|
63
|
-
activesupport (= 7.0.
|
64
|
-
activestorage (7.0.
|
65
|
-
actionpack (= 7.0.
|
66
|
-
activejob (= 7.0.
|
67
|
-
activerecord (= 7.0.
|
68
|
-
activesupport (= 7.0.
|
59
|
+
activemodel (7.0.8)
|
60
|
+
activesupport (= 7.0.8)
|
61
|
+
activerecord (7.0.8)
|
62
|
+
activemodel (= 7.0.8)
|
63
|
+
activesupport (= 7.0.8)
|
64
|
+
activestorage (7.0.8)
|
65
|
+
actionpack (= 7.0.8)
|
66
|
+
activejob (= 7.0.8)
|
67
|
+
activerecord (= 7.0.8)
|
68
|
+
activesupport (= 7.0.8)
|
69
69
|
marcel (~> 1.0)
|
70
70
|
mini_mime (>= 1.1.0)
|
71
|
-
activesupport (7.0.
|
71
|
+
activesupport (7.0.8)
|
72
72
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
73
73
|
i18n (>= 1.6, < 2)
|
74
74
|
minitest (>= 5.1)
|
75
75
|
tzinfo (~> 2.0)
|
76
76
|
ast (2.4.2)
|
77
|
+
base64 (0.1.1)
|
77
78
|
builder (3.2.4)
|
78
79
|
cgi (0.3.6)
|
79
80
|
combustion (1.3.7)
|
@@ -83,17 +84,18 @@ GEM
|
|
83
84
|
concurrent-ruby (1.2.2)
|
84
85
|
crass (1.0.6)
|
85
86
|
date (3.3.3)
|
86
|
-
erb (4.0.
|
87
|
+
erb (4.0.3)
|
87
88
|
cgi (>= 0.3.3)
|
88
89
|
erubi (1.12.0)
|
89
|
-
globalid (1.1
|
90
|
-
activesupport (>=
|
91
|
-
i18n (1.
|
90
|
+
globalid (1.2.1)
|
91
|
+
activesupport (>= 6.1)
|
92
|
+
i18n (1.14.1)
|
92
93
|
concurrent-ruby (~> 1.0)
|
93
94
|
json (2.6.3)
|
94
|
-
|
95
|
+
language_server-protocol (3.17.0.3)
|
96
|
+
loofah (2.21.3)
|
95
97
|
crass (~> 1.0.2)
|
96
|
-
nokogiri (>= 1.
|
98
|
+
nokogiri (>= 1.12.0)
|
97
99
|
mail (2.8.1)
|
98
100
|
mini_mime (>= 0.1.1)
|
99
101
|
net-imap
|
@@ -101,9 +103,9 @@ GEM
|
|
101
103
|
net-smtp
|
102
104
|
marcel (1.0.2)
|
103
105
|
method_source (1.0.0)
|
104
|
-
mini_mime (1.1.
|
105
|
-
minitest (5.
|
106
|
-
net-imap (0.3.
|
106
|
+
mini_mime (1.1.5)
|
107
|
+
minitest (5.20.0)
|
108
|
+
net-imap (0.3.7)
|
107
109
|
date
|
108
110
|
net-protocol
|
109
111
|
net-pop (0.1.2)
|
@@ -113,15 +115,16 @@ GEM
|
|
113
115
|
net-smtp (0.3.3)
|
114
116
|
net-protocol
|
115
117
|
nio4r (2.5.9)
|
116
|
-
nokogiri (1.
|
118
|
+
nokogiri (1.15.4-arm64-darwin)
|
117
119
|
racc (~> 1.4)
|
118
|
-
nokogiri (1.
|
120
|
+
nokogiri (1.15.4-x86_64-darwin)
|
119
121
|
racc (~> 1.4)
|
120
|
-
nokogiri (1.
|
122
|
+
nokogiri (1.15.4-x86_64-linux)
|
121
123
|
racc (~> 1.4)
|
122
124
|
parallel (1.23.0)
|
123
|
-
parser (3.2.2.
|
125
|
+
parser (3.2.2.3)
|
124
126
|
ast (~> 2.4.1)
|
127
|
+
racc
|
125
128
|
phlex (1.8.1)
|
126
129
|
concurrent-ruby (~> 1.2)
|
127
130
|
erb (>= 4)
|
@@ -133,63 +136,67 @@ GEM
|
|
133
136
|
phlex-testing-nokogiri (0.1.0)
|
134
137
|
nokogiri (~> 1.13)
|
135
138
|
phlex (>= 0.5)
|
136
|
-
racc (1.
|
137
|
-
rack (2.2.
|
139
|
+
racc (1.7.1)
|
140
|
+
rack (2.2.8)
|
138
141
|
rack-test (2.1.0)
|
139
142
|
rack (>= 1.3)
|
140
|
-
rails (7.0.
|
141
|
-
actioncable (= 7.0.
|
142
|
-
actionmailbox (= 7.0.
|
143
|
-
actionmailer (= 7.0.
|
144
|
-
actionpack (= 7.0.
|
145
|
-
actiontext (= 7.0.
|
146
|
-
actionview (= 7.0.
|
147
|
-
activejob (= 7.0.
|
148
|
-
activemodel (= 7.0.
|
149
|
-
activerecord (= 7.0.
|
150
|
-
activestorage (= 7.0.
|
151
|
-
activesupport (= 7.0.
|
143
|
+
rails (7.0.8)
|
144
|
+
actioncable (= 7.0.8)
|
145
|
+
actionmailbox (= 7.0.8)
|
146
|
+
actionmailer (= 7.0.8)
|
147
|
+
actionpack (= 7.0.8)
|
148
|
+
actiontext (= 7.0.8)
|
149
|
+
actionview (= 7.0.8)
|
150
|
+
activejob (= 7.0.8)
|
151
|
+
activemodel (= 7.0.8)
|
152
|
+
activerecord (= 7.0.8)
|
153
|
+
activestorage (= 7.0.8)
|
154
|
+
activesupport (= 7.0.8)
|
152
155
|
bundler (>= 1.15.0)
|
153
|
-
railties (= 7.0.
|
154
|
-
rails-dom-testing (2.0
|
155
|
-
activesupport (>=
|
156
|
+
railties (= 7.0.8)
|
157
|
+
rails-dom-testing (2.2.0)
|
158
|
+
activesupport (>= 5.0.0)
|
159
|
+
minitest
|
156
160
|
nokogiri (>= 1.6)
|
157
|
-
rails-html-sanitizer (1.
|
158
|
-
loofah (~> 2.
|
159
|
-
|
160
|
-
|
161
|
-
|
161
|
+
rails-html-sanitizer (1.6.0)
|
162
|
+
loofah (~> 2.21)
|
163
|
+
nokogiri (~> 1.14)
|
164
|
+
railties (7.0.8)
|
165
|
+
actionpack (= 7.0.8)
|
166
|
+
activesupport (= 7.0.8)
|
162
167
|
method_source
|
163
168
|
rake (>= 12.2)
|
164
169
|
thor (~> 1.0)
|
165
170
|
zeitwerk (~> 2.5)
|
166
171
|
rainbow (3.1.1)
|
167
172
|
rake (13.0.6)
|
168
|
-
regexp_parser (2.8.
|
169
|
-
rexml (3.2.
|
170
|
-
rubocop (1.
|
173
|
+
regexp_parser (2.8.1)
|
174
|
+
rexml (3.2.6)
|
175
|
+
rubocop (1.56.3)
|
176
|
+
base64 (~> 0.1.1)
|
171
177
|
json (~> 2.3)
|
178
|
+
language_server-protocol (>= 3.17.0)
|
172
179
|
parallel (~> 1.10)
|
173
|
-
parser (>= 3.2.
|
180
|
+
parser (>= 3.2.2.3)
|
174
181
|
rainbow (>= 2.2.2, < 4.0)
|
175
182
|
regexp_parser (>= 1.8, < 3.0)
|
176
183
|
rexml (>= 3.2.5, < 4.0)
|
177
|
-
rubocop-ast (>= 1.28.
|
184
|
+
rubocop-ast (>= 1.28.1, < 2.0)
|
178
185
|
ruby-progressbar (~> 1.7)
|
179
186
|
unicode-display_width (>= 2.4.0, < 3.0)
|
180
|
-
rubocop-ast (1.
|
187
|
+
rubocop-ast (1.29.0)
|
181
188
|
parser (>= 3.2.1.0)
|
182
189
|
ruby-progressbar (1.13.0)
|
183
|
-
sus (0.
|
184
|
-
thor (1.2.
|
185
|
-
timeout (0.
|
190
|
+
sus (0.23.0)
|
191
|
+
thor (1.2.2)
|
192
|
+
timeout (0.4.0)
|
186
193
|
tzinfo (2.0.6)
|
187
194
|
concurrent-ruby (~> 1.0)
|
188
195
|
unicode-display_width (2.4.2)
|
189
|
-
websocket-driver (0.7.
|
196
|
+
websocket-driver (0.7.6)
|
190
197
|
websocket-extensions (>= 0.1.0)
|
191
198
|
websocket-extensions (0.1.5)
|
192
|
-
zeitwerk (2.6.
|
199
|
+
zeitwerk (2.6.11)
|
193
200
|
|
194
201
|
PLATFORMS
|
195
202
|
arm64-darwin-22
|
@@ -201,8 +208,8 @@ DEPENDENCIES
|
|
201
208
|
phlex-testing-nokogiri
|
202
209
|
phlexible!
|
203
210
|
rake (~> 13.0)
|
204
|
-
rubocop (~> 1.
|
205
|
-
sus
|
211
|
+
rubocop (~> 1.55)
|
212
|
+
sus
|
206
213
|
|
207
214
|
BUNDLED WITH
|
208
215
|
2.4.1
|
data/README.md
CHANGED
@@ -38,8 +38,7 @@ end
|
|
38
38
|
|
39
39
|
#### `ControllerAttributes`
|
40
40
|
|
41
|
-
Include this module in your Phlex views to get access to the controller's instance variables. It
|
42
|
-
provides an explicit interface for accessing controller instance variables from the view.
|
41
|
+
Include this module in your Phlex views to get access to the controller's instance variables. It provides an explicit interface for accessing controller instance variables from the view.
|
43
42
|
|
44
43
|
```ruby
|
45
44
|
class Views::Users::Index < Views::Base
|
@@ -64,9 +63,7 @@ controller_attribute :users, attr_reader: true, alias: :my_users
|
|
64
63
|
|
65
64
|
#### `Responder`
|
66
65
|
|
67
|
-
If you use [Responders](https://github.com/heartcombo/responders), Phlexible provides a responder to
|
68
|
-
support implicit rendering similar to `ActionController::ImplicitRender` above. It will render the
|
69
|
-
Phlex view using `respond_with` if one exists, and fall back to default rendering.
|
66
|
+
If you use [Responders](https://github.com/heartcombo/responders), Phlexible provides a responder to support implicit rendering similar to `ActionController::ImplicitRender` above. It will render the Phlex view using `respond_with` if one exists, and fall back to default rendering.
|
70
67
|
|
71
68
|
Just include it in your ApplicationResponder:
|
72
69
|
|
@@ -91,20 +88,15 @@ class UsersController < ApplicationController
|
|
91
88
|
end
|
92
89
|
```
|
93
90
|
|
94
|
-
This responder requires the use of `ActionController::ImplicitRender`, so don't forget to include
|
95
|
-
that in your `ApplicationController`.
|
91
|
+
This responder requires the use of `ActionController::ImplicitRender`, so don't forget to include that in your `ApplicationController`.
|
96
92
|
|
97
|
-
If you use `ControllerAttributes` in your view, and define a `resource` attribute, the responder
|
98
|
-
will pass that to your view.
|
93
|
+
If you use `ControllerAttributes` in your view, and define a `resource` attribute, the responder will pass that to your view.
|
99
94
|
|
100
95
|
#### `AElement`
|
101
96
|
|
102
|
-
No need to call Rails `link_to` helper, when you can simply render an anchor tag directly with
|
103
|
-
Phlex. But unfortunately that means you lose some of the magic that `link_to` provides. Especially
|
104
|
-
the automatic resolution of URL's and Rails routes.
|
97
|
+
No need to call Rails `link_to` helper, when you can simply render an anchor tag directly with Phlex. But unfortunately that means you lose some of the magic that `link_to` provides. Especially the automatic resolution of URL's and Rails routes.
|
105
98
|
|
106
|
-
The `Phlexible::Rails::AElement` module passes through the `href` attribute to Rails `url_for`
|
107
|
-
helper. So you can do this:
|
99
|
+
The `Phlexible::Rails::AElement` module passes through the `href` attribute to Rails `url_for` helper. So you can do this:
|
108
100
|
|
109
101
|
```ruby
|
110
102
|
Rails.application.routes.draw do
|
@@ -126,8 +118,7 @@ end
|
|
126
118
|
|
127
119
|
Generates a form containing a single button that submits to the URL created by the set of options.
|
128
120
|
|
129
|
-
It is similar to Rails `button_to` helper, which accepts the URL or route helper as the first
|
130
|
-
argument, and the value/content of the button as the block.
|
121
|
+
It is similar to Rails `button_to` helper, which accepts the URL or route helper as the first argument, and the value/content of the button as the block.
|
131
122
|
|
132
123
|
```ruby
|
133
124
|
Phlexible::Rails::ButtonTo.new(:root) { 'My Button' }
|
@@ -135,8 +126,7 @@ Phlexible::Rails::ButtonTo.new(:root) { 'My Button' }
|
|
135
126
|
|
136
127
|
The url argument accepts the same options as Rails `url_for`.
|
137
128
|
|
138
|
-
The form submits a POST request by default. You can specify a different HTTP verb via the :method
|
139
|
-
option.
|
129
|
+
The form submits a POST request by default. You can specify a different HTTP verb via the :method option.
|
140
130
|
|
141
131
|
```ruby
|
142
132
|
Phlexible::Rails::ButtonTo.new(:root, method: :patch) { 'My Button' }
|
@@ -144,11 +134,11 @@ Phlexible::Rails::ButtonTo.new(:root, method: :patch) { 'My Button' }
|
|
144
134
|
|
145
135
|
##### Options
|
146
136
|
|
147
|
-
- `:class`
|
137
|
+
- `:class` - Specify the HTML class name of the button (not the form).
|
148
138
|
- `:form_class` - Specify the HTML class name of the form (default: 'button_to').
|
149
|
-
- `:data`
|
150
|
-
- `:
|
151
|
-
|
139
|
+
- `:data` - This option can be used to add custom data attributes.
|
140
|
+
- `:params` - Hash of parameters to be rendered as hidden fields within the form.
|
141
|
+
- `:method` - Symbol of the HTTP verb. Supported verbs are :post (default), :get, :delete, :patch, and :put.
|
152
142
|
|
153
143
|
### `AliasView`
|
154
144
|
|
@@ -184,9 +174,7 @@ end
|
|
184
174
|
|
185
175
|
### PageTitle
|
186
176
|
|
187
|
-
Helper to assist in defining page titles within Phlex views. Also includes support for nested views,
|
188
|
-
where each desendent view class will have its title prepended to the page title. Simply assign the
|
189
|
-
title to the `page_title` class variable:
|
177
|
+
Helper to assist in defining page titles within Phlex views. Also includes support for nested views, where each desendent view class will have its title prepended to the page title. Simply assign the title to the `page_title` class variable:
|
190
178
|
|
191
179
|
```ruby
|
192
180
|
class MyView
|
@@ -204,7 +192,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
204
192
|
|
205
193
|
## Contributing
|
206
194
|
|
207
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/joelmoss/phlexible
|
195
|
+
Bug reports and pull requests are welcome on GitHub at <https://github.com/joelmoss/phlexible>. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/joelmoss/phlexible/blob/master/CODE_OF_CONDUCT.md).
|
208
196
|
|
209
197
|
## License
|
210
198
|
|
data/config/sus.rb
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
# def index
|
7
7
|
# render Views::Users::Index.new
|
8
8
|
# end
|
9
|
-
|
9
|
+
#
|
10
10
|
# def show
|
11
11
|
# render Views::Users::Show.new(user)
|
12
12
|
# end
|
@@ -30,6 +30,8 @@ module Phlexible
|
|
30
30
|
pview.tap do |view|
|
31
31
|
if view.respond_to?(:__controller_attributes__)
|
32
32
|
view.__controller_attributes__.each do |attr|
|
33
|
+
raise ControllerAttributes::UndefinedVariable, attr unless view_assigns.key?(attr.to_s)
|
34
|
+
|
33
35
|
view.instance_variable_set :"@#{attr}", view_assigns[attr.to_s]
|
34
36
|
end
|
35
37
|
end
|
@@ -55,8 +57,14 @@ module Phlexible
|
|
55
57
|
render assign_phlex_accessors(view.new)
|
56
58
|
end
|
57
59
|
|
60
|
+
private
|
61
|
+
|
58
62
|
def phlex_view(action_name = @_action_name)
|
59
|
-
|
63
|
+
phlex_view_path(action_name).classify.constantize
|
64
|
+
end
|
65
|
+
|
66
|
+
def phlex_view_path(action_name)
|
67
|
+
"#{controller_path}/#{action_name}_view"
|
60
68
|
end
|
61
69
|
end
|
62
70
|
end
|
@@ -5,11 +5,18 @@
|
|
5
5
|
#
|
6
6
|
# The form submits a POST request by default. You can specify a different HTTP verb via the :method
|
7
7
|
# option.
|
8
|
+
#
|
9
|
+
# Additional arguments are passed through to the button element, with a few exceptions:
|
10
|
+
# - :method - Symbol of HTTP verb. Supported verbs are :post, :get, :delete, :patch, and :put. By
|
11
|
+
# default it will be :post.
|
12
|
+
# - :form_class - This controls the class of the form within which the submit button will be
|
13
|
+
# placed. By default it will be 'button_to'.
|
14
|
+
# - :params - Hash of parameters to be rendered as hidden fields within the form.
|
8
15
|
module Phlexible
|
9
16
|
module Rails
|
10
17
|
module ButtonToConcerns
|
11
18
|
BUTTON_TAG_METHOD_VERBS = %w[patch put delete].freeze
|
12
|
-
DEFAULT_OPTIONS = { method: 'post', form_class: 'button_to' }.freeze
|
19
|
+
DEFAULT_OPTIONS = { method: 'post', form_class: 'button_to', params: {} }.freeze
|
13
20
|
|
14
21
|
def initialize(url, options = nil)
|
15
22
|
@url = url
|
@@ -27,6 +34,7 @@ module Phlexible
|
|
27
34
|
form action: action, class: @options.delete(:form_class), method: form_method do
|
28
35
|
method_tag method
|
29
36
|
form_method == 'post' && token_input(action, method.empty? ? 'post' : method)
|
37
|
+
param_inputs
|
30
38
|
|
31
39
|
block_given? ? button(**button_attrs, &block) : button(**button_attrs) { @name }
|
32
40
|
end
|
@@ -66,6 +74,52 @@ module Phlexible
|
|
66
74
|
|
67
75
|
input type: 'hidden', name: '_method', value: method.to_s, autocomplete: 'off'
|
68
76
|
end
|
77
|
+
|
78
|
+
def param_inputs
|
79
|
+
return unless (params = @options.delete(:params))
|
80
|
+
|
81
|
+
to_form_params(params).each do |param|
|
82
|
+
input type: 'hidden', name: param[:name], value: param[:value], autocomplete: 'off'
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
# Returns an array of hashes each containing :name and :value keys
|
87
|
+
# suitable for use as the names and values of form input fields:
|
88
|
+
#
|
89
|
+
# to_form_params(name: 'David', nationality: 'Danish')
|
90
|
+
# # => [{name: 'name', value: 'David'}, {name: 'nationality', value: 'Danish'}]
|
91
|
+
#
|
92
|
+
# to_form_params(country: { name: 'Denmark' })
|
93
|
+
# # => [{name: 'country[name]', value: 'Denmark'}]
|
94
|
+
#
|
95
|
+
# to_form_params(countries: ['Denmark', 'Sweden']})
|
96
|
+
# # => [{name: 'countries[]', value: 'Denmark'}, {name: 'countries[]', value: 'Sweden'}]
|
97
|
+
#
|
98
|
+
# An optional namespace can be passed to enclose key names:
|
99
|
+
#
|
100
|
+
# to_form_params({ name: 'Denmark' }, 'country')
|
101
|
+
# # => [{name: 'country[name]', value: 'Denmark'}]
|
102
|
+
def to_form_params(attribute, namespace = nil)
|
103
|
+
attribute = attribute.to_h if attribute.respond_to?(:permitted?)
|
104
|
+
|
105
|
+
params = []
|
106
|
+
case attribute
|
107
|
+
when Hash
|
108
|
+
attribute.each do |key, value|
|
109
|
+
prefix = namespace ? "#{namespace}[#{key}]" : key
|
110
|
+
params.push(*to_form_params(value, prefix))
|
111
|
+
end
|
112
|
+
when Array
|
113
|
+
array_prefix = "#{namespace}[]"
|
114
|
+
attribute.each do |value|
|
115
|
+
params.push(*to_form_params(value, array_prefix))
|
116
|
+
end
|
117
|
+
else
|
118
|
+
params << { name: namespace.to_s, value: attribute.to_param }
|
119
|
+
end
|
120
|
+
|
121
|
+
params.sort_by { |pair| pair[:name] }
|
122
|
+
end
|
69
123
|
end
|
70
124
|
|
71
125
|
class ButtonTo < Phlex::HTML
|
@@ -18,11 +18,21 @@
|
|
18
18
|
# - `attr_reader:` - If set to `true`, an `attr_reader` will be defined for the given attributes.
|
19
19
|
# - `alias:` - If set, the given attribute will be aliased to the given alias value.
|
20
20
|
#
|
21
|
+
# NOTE: Phlexible::Rails::ActionController::ImplicitRender is required for this to work.
|
22
|
+
#
|
21
23
|
module Phlexible
|
22
24
|
module Rails
|
23
25
|
module ControllerAttributes
|
24
26
|
extend ActiveSupport::Concern
|
25
27
|
|
28
|
+
class UndefinedVariable < NameError
|
29
|
+
def initialize(name)
|
30
|
+
@variable_name = name
|
31
|
+
super "Attempted to expose controller attribute `#{@variable_name}`, but instance " \
|
32
|
+
'variable is not defined in the controller.'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
26
36
|
included do
|
27
37
|
class_attribute :__controller_attributes__, instance_predicate: false, default: Set.new
|
28
38
|
end
|
data/lib/phlexible/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phlexible
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joel Moss
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-10-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: phlex
|
@@ -98,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
98
98
|
- !ruby/object:Gem::Version
|
99
99
|
version: '0'
|
100
100
|
requirements: []
|
101
|
-
rubygems_version: 3.4.
|
101
|
+
rubygems_version: 3.4.20
|
102
102
|
signing_key:
|
103
103
|
specification_version: 4
|
104
104
|
summary: A bunch of helpers and goodies intended to make life with Phlex even easier!
|