phlexible 0.6.2 → 1.0.0.beta.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 +0 -1
- data/Gemfile.lock +50 -136
- data/README.md +65 -13
- data/fixtures/dummy/app/views/articles/show.rb +7 -0
- data/fixtures/rails_helper.rb +1 -0
- data/lib/phlexible/rails/action_controller/implicit_render.rb +2 -14
- data/lib/phlexible/rails/action_controller/meta_tags.rb +27 -0
- data/lib/phlexible/rails/button_to.rb +17 -11
- data/lib/phlexible/rails/controller_variables.rb +101 -0
- data/lib/phlexible/rails/meta_tags_component.rb +13 -0
- data/lib/phlexible/rails.rb +3 -1
- data/lib/phlexible/version.rb +1 -1
- metadata +11 -8
- data/lib/phlexible/rails/controller_attributes.rb +0 -61
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 64179e5e683be255a3bbd07a5da7fcec2c9e077fc52bffa854b9f9c2b3d4786d
|
|
4
|
+
data.tar.gz: 87c196d1421e5845f961ad3b79a63d0aa7d9d8966b79778400eb0bc0ea39daf6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e180904344267c2fd9911dbaa8c7c9a1a7c66ba26cb459fec7e7b3df7bbc419b16352b6c008c42cbdd6f456fd67a3bab27a2412c112746c1ca0329834c0f439a
|
|
7
|
+
data.tar.gz: 842c6c4db2390a5a9abd9f5ceb01bb0b4a45c97d1ef7a02dac7cd77a2b4824a6c6f0b6dd268de7e933f9dadd252051f2b3eb2dd94034e441e93e96f9740bb842
|
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,77 +1,30 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
phlexible (0.
|
|
5
|
-
phlex (
|
|
6
|
-
phlex-rails (
|
|
4
|
+
phlexible (1.0.0.beta.1)
|
|
5
|
+
phlex (>= 1.8.1)
|
|
6
|
+
phlex-rails (>= 1.0.0)
|
|
7
7
|
|
|
8
8
|
GEM
|
|
9
9
|
remote: https://rubygems.org/
|
|
10
10
|
specs:
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
activesupport (= 7.1.
|
|
14
|
-
nio4r (~> 2.0)
|
|
15
|
-
websocket-driver (>= 0.6.1)
|
|
16
|
-
zeitwerk (~> 2.6)
|
|
17
|
-
actionmailbox (7.1.1)
|
|
18
|
-
actionpack (= 7.1.1)
|
|
19
|
-
activejob (= 7.1.1)
|
|
20
|
-
activerecord (= 7.1.1)
|
|
21
|
-
activestorage (= 7.1.1)
|
|
22
|
-
activesupport (= 7.1.1)
|
|
23
|
-
mail (>= 2.7.1)
|
|
24
|
-
net-imap
|
|
25
|
-
net-pop
|
|
26
|
-
net-smtp
|
|
27
|
-
actionmailer (7.1.1)
|
|
28
|
-
actionpack (= 7.1.1)
|
|
29
|
-
actionview (= 7.1.1)
|
|
30
|
-
activejob (= 7.1.1)
|
|
31
|
-
activesupport (= 7.1.1)
|
|
32
|
-
mail (~> 2.5, >= 2.5.4)
|
|
33
|
-
net-imap
|
|
34
|
-
net-pop
|
|
35
|
-
net-smtp
|
|
36
|
-
rails-dom-testing (~> 2.2)
|
|
37
|
-
actionpack (7.1.1)
|
|
38
|
-
actionview (= 7.1.1)
|
|
39
|
-
activesupport (= 7.1.1)
|
|
11
|
+
actionpack (7.1.3)
|
|
12
|
+
actionview (= 7.1.3)
|
|
13
|
+
activesupport (= 7.1.3)
|
|
40
14
|
nokogiri (>= 1.8.5)
|
|
15
|
+
racc
|
|
41
16
|
rack (>= 2.2.4)
|
|
42
17
|
rack-session (>= 1.0.1)
|
|
43
18
|
rack-test (>= 0.6.3)
|
|
44
19
|
rails-dom-testing (~> 2.2)
|
|
45
20
|
rails-html-sanitizer (~> 1.6)
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
activerecord (= 7.1.1)
|
|
49
|
-
activestorage (= 7.1.1)
|
|
50
|
-
activesupport (= 7.1.1)
|
|
51
|
-
globalid (>= 0.6.0)
|
|
52
|
-
nokogiri (>= 1.8.5)
|
|
53
|
-
actionview (7.1.1)
|
|
54
|
-
activesupport (= 7.1.1)
|
|
21
|
+
actionview (7.1.3)
|
|
22
|
+
activesupport (= 7.1.3)
|
|
55
23
|
builder (~> 3.1)
|
|
56
24
|
erubi (~> 1.11)
|
|
57
25
|
rails-dom-testing (~> 2.2)
|
|
58
26
|
rails-html-sanitizer (~> 1.6)
|
|
59
|
-
|
|
60
|
-
activesupport (= 7.1.1)
|
|
61
|
-
globalid (>= 0.3.6)
|
|
62
|
-
activemodel (7.1.1)
|
|
63
|
-
activesupport (= 7.1.1)
|
|
64
|
-
activerecord (7.1.1)
|
|
65
|
-
activemodel (= 7.1.1)
|
|
66
|
-
activesupport (= 7.1.1)
|
|
67
|
-
timeout (>= 0.4.0)
|
|
68
|
-
activestorage (7.1.1)
|
|
69
|
-
actionpack (= 7.1.1)
|
|
70
|
-
activejob (= 7.1.1)
|
|
71
|
-
activerecord (= 7.1.1)
|
|
72
|
-
activesupport (= 7.1.1)
|
|
73
|
-
marcel (~> 1.0)
|
|
74
|
-
activesupport (7.1.1)
|
|
27
|
+
activesupport (7.1.3)
|
|
75
28
|
base64
|
|
76
29
|
bigdecimal
|
|
77
30
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
@@ -82,80 +35,60 @@ GEM
|
|
|
82
35
|
mutex_m
|
|
83
36
|
tzinfo (~> 2.0)
|
|
84
37
|
ast (2.4.2)
|
|
85
|
-
base64 (0.
|
|
86
|
-
bigdecimal (3.1.
|
|
38
|
+
base64 (0.2.0)
|
|
39
|
+
bigdecimal (3.1.6)
|
|
87
40
|
builder (3.2.4)
|
|
88
|
-
cgi (0.
|
|
89
|
-
combustion (1.
|
|
41
|
+
cgi (0.4.1)
|
|
42
|
+
combustion (1.4.0)
|
|
90
43
|
activesupport (>= 3.0.0)
|
|
91
44
|
railties (>= 3.0.0)
|
|
92
45
|
thor (>= 0.14.6)
|
|
93
|
-
concurrent-ruby (1.2.
|
|
46
|
+
concurrent-ruby (1.2.3)
|
|
94
47
|
connection_pool (2.4.1)
|
|
95
48
|
crass (1.0.6)
|
|
96
|
-
|
|
97
|
-
drb (2.1.1)
|
|
49
|
+
drb (2.2.0)
|
|
98
50
|
ruby2_keywords
|
|
99
|
-
erb (4.0.
|
|
51
|
+
erb (4.0.4)
|
|
100
52
|
cgi (>= 0.3.3)
|
|
101
53
|
erubi (1.12.0)
|
|
102
|
-
globalid (1.2.1)
|
|
103
|
-
activesupport (>= 6.1)
|
|
104
54
|
i18n (1.14.1)
|
|
105
55
|
concurrent-ruby (~> 1.0)
|
|
106
|
-
io-console (0.
|
|
107
|
-
irb (1.
|
|
56
|
+
io-console (0.7.2)
|
|
57
|
+
irb (1.11.1)
|
|
108
58
|
rdoc
|
|
109
|
-
reline (>= 0.
|
|
110
|
-
json (2.
|
|
59
|
+
reline (>= 0.4.2)
|
|
60
|
+
json (2.7.1)
|
|
111
61
|
language_server-protocol (3.17.0.3)
|
|
112
|
-
loofah (2.
|
|
62
|
+
loofah (2.22.0)
|
|
113
63
|
crass (~> 1.0.2)
|
|
114
64
|
nokogiri (>= 1.12.0)
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
net-pop
|
|
119
|
-
net-smtp
|
|
120
|
-
marcel (1.0.2)
|
|
121
|
-
mini_mime (1.1.5)
|
|
122
|
-
minitest (5.20.0)
|
|
123
|
-
mutex_m (0.1.2)
|
|
124
|
-
net-imap (0.4.1)
|
|
125
|
-
date
|
|
126
|
-
net-protocol
|
|
127
|
-
net-pop (0.1.2)
|
|
128
|
-
net-protocol
|
|
129
|
-
net-protocol (0.2.1)
|
|
130
|
-
timeout
|
|
131
|
-
net-smtp (0.4.0)
|
|
132
|
-
net-protocol
|
|
133
|
-
nio4r (2.5.9)
|
|
134
|
-
nokogiri (1.15.4-arm64-darwin)
|
|
65
|
+
minitest (5.21.2)
|
|
66
|
+
mutex_m (0.2.0)
|
|
67
|
+
nokogiri (1.16.0-arm64-darwin)
|
|
135
68
|
racc (~> 1.4)
|
|
136
|
-
nokogiri (1.
|
|
69
|
+
nokogiri (1.16.0-x86_64-darwin)
|
|
137
70
|
racc (~> 1.4)
|
|
138
|
-
nokogiri (1.
|
|
71
|
+
nokogiri (1.16.0-x86_64-linux)
|
|
139
72
|
racc (~> 1.4)
|
|
140
|
-
parallel (1.
|
|
141
|
-
parser (3.
|
|
73
|
+
parallel (1.24.0)
|
|
74
|
+
parser (3.3.0.5)
|
|
142
75
|
ast (~> 2.4.1)
|
|
143
76
|
racc
|
|
144
|
-
phlex (1.
|
|
77
|
+
phlex (1.9.0)
|
|
145
78
|
concurrent-ruby (~> 1.2)
|
|
146
79
|
erb (>= 4)
|
|
147
80
|
zeitwerk (~> 2.6)
|
|
148
|
-
phlex-rails (1.
|
|
149
|
-
phlex (~> 1.
|
|
150
|
-
|
|
81
|
+
phlex-rails (1.1.1)
|
|
82
|
+
phlex (~> 1.9)
|
|
83
|
+
railties (>= 6.1, < 8)
|
|
151
84
|
zeitwerk (~> 2.6)
|
|
152
85
|
phlex-testing-nokogiri (0.1.0)
|
|
153
86
|
nokogiri (~> 1.13)
|
|
154
87
|
phlex (>= 0.5)
|
|
155
|
-
psych (5.1.
|
|
88
|
+
psych (5.1.2)
|
|
156
89
|
stringio
|
|
157
|
-
racc (1.7.
|
|
158
|
-
rack (3.0.
|
|
90
|
+
racc (1.7.3)
|
|
91
|
+
rack (3.0.9)
|
|
159
92
|
rack-session (2.0.0)
|
|
160
93
|
rack (>= 3.0.0)
|
|
161
94
|
rack-test (2.1.0)
|
|
@@ -163,20 +96,6 @@ GEM
|
|
|
163
96
|
rackup (2.1.0)
|
|
164
97
|
rack (>= 3)
|
|
165
98
|
webrick (~> 1.8)
|
|
166
|
-
rails (7.1.1)
|
|
167
|
-
actioncable (= 7.1.1)
|
|
168
|
-
actionmailbox (= 7.1.1)
|
|
169
|
-
actionmailer (= 7.1.1)
|
|
170
|
-
actionpack (= 7.1.1)
|
|
171
|
-
actiontext (= 7.1.1)
|
|
172
|
-
actionview (= 7.1.1)
|
|
173
|
-
activejob (= 7.1.1)
|
|
174
|
-
activemodel (= 7.1.1)
|
|
175
|
-
activerecord (= 7.1.1)
|
|
176
|
-
activestorage (= 7.1.1)
|
|
177
|
-
activesupport (= 7.1.1)
|
|
178
|
-
bundler (>= 1.15.0)
|
|
179
|
-
railties (= 7.1.1)
|
|
180
99
|
rails-dom-testing (2.2.0)
|
|
181
100
|
activesupport (>= 5.0.0)
|
|
182
101
|
minitest
|
|
@@ -184,49 +103,44 @@ GEM
|
|
|
184
103
|
rails-html-sanitizer (1.6.0)
|
|
185
104
|
loofah (~> 2.21)
|
|
186
105
|
nokogiri (~> 1.14)
|
|
187
|
-
railties (7.1.
|
|
188
|
-
actionpack (= 7.1.
|
|
189
|
-
activesupport (= 7.1.
|
|
106
|
+
railties (7.1.3)
|
|
107
|
+
actionpack (= 7.1.3)
|
|
108
|
+
activesupport (= 7.1.3)
|
|
190
109
|
irb
|
|
191
110
|
rackup (>= 1.0.0)
|
|
192
111
|
rake (>= 12.2)
|
|
193
112
|
thor (~> 1.0, >= 1.2.2)
|
|
194
113
|
zeitwerk (~> 2.6)
|
|
195
114
|
rainbow (3.1.1)
|
|
196
|
-
rake (13.0
|
|
197
|
-
rdoc (6.
|
|
115
|
+
rake (13.1.0)
|
|
116
|
+
rdoc (6.6.2)
|
|
198
117
|
psych (>= 4.0.0)
|
|
199
|
-
regexp_parser (2.
|
|
200
|
-
reline (0.
|
|
118
|
+
regexp_parser (2.9.0)
|
|
119
|
+
reline (0.4.2)
|
|
201
120
|
io-console (~> 0.5)
|
|
202
121
|
rexml (3.2.6)
|
|
203
|
-
rubocop (1.
|
|
204
|
-
base64 (~> 0.1.1)
|
|
122
|
+
rubocop (1.60.2)
|
|
205
123
|
json (~> 2.3)
|
|
206
124
|
language_server-protocol (>= 3.17.0)
|
|
207
125
|
parallel (~> 1.10)
|
|
208
|
-
parser (>= 3.
|
|
126
|
+
parser (>= 3.3.0.2)
|
|
209
127
|
rainbow (>= 2.2.2, < 4.0)
|
|
210
128
|
regexp_parser (>= 1.8, < 3.0)
|
|
211
129
|
rexml (>= 3.2.5, < 4.0)
|
|
212
|
-
rubocop-ast (>= 1.
|
|
130
|
+
rubocop-ast (>= 1.30.0, < 2.0)
|
|
213
131
|
ruby-progressbar (~> 1.7)
|
|
214
132
|
unicode-display_width (>= 2.4.0, < 3.0)
|
|
215
|
-
rubocop-ast (1.
|
|
133
|
+
rubocop-ast (1.30.0)
|
|
216
134
|
parser (>= 3.2.1.0)
|
|
217
135
|
ruby-progressbar (1.13.0)
|
|
218
136
|
ruby2_keywords (0.0.5)
|
|
219
|
-
stringio (3.0
|
|
220
|
-
sus (0.
|
|
221
|
-
thor (1.
|
|
222
|
-
timeout (0.4.0)
|
|
137
|
+
stringio (3.1.0)
|
|
138
|
+
sus (0.24.5)
|
|
139
|
+
thor (1.3.0)
|
|
223
140
|
tzinfo (2.0.6)
|
|
224
141
|
concurrent-ruby (~> 1.0)
|
|
225
142
|
unicode-display_width (2.5.0)
|
|
226
143
|
webrick (1.8.1)
|
|
227
|
-
websocket-driver (0.7.6)
|
|
228
|
-
websocket-extensions (>= 0.1.0)
|
|
229
|
-
websocket-extensions (0.1.5)
|
|
230
144
|
zeitwerk (2.6.12)
|
|
231
145
|
|
|
232
146
|
PLATFORMS
|
data/README.md
CHANGED
|
@@ -36,15 +36,19 @@ class UsersController
|
|
|
36
36
|
end
|
|
37
37
|
```
|
|
38
38
|
|
|
39
|
-
#### `
|
|
39
|
+
#### `ControllerVariables`
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
> Available in **>= 1.0.0**
|
|
42
|
+
|
|
43
|
+
> **NOTE:** Prior to **1.0.0**, this module was called `ControllerAttributes` with a very different API. This is no longer available since **1.0.0**.
|
|
44
|
+
|
|
45
|
+
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 within the view.
|
|
42
46
|
|
|
43
47
|
```ruby
|
|
44
48
|
class Views::Users::Index < Views::Base
|
|
45
|
-
include Phlexible::Rails::
|
|
49
|
+
include Phlexible::Rails::ControllerVariables
|
|
46
50
|
|
|
47
|
-
|
|
51
|
+
controller_variable :first_name, :last_name
|
|
48
52
|
|
|
49
53
|
def template
|
|
50
54
|
h1 { "#{@first_name} #{@last_name}" }
|
|
@@ -54,13 +58,29 @@ end
|
|
|
54
58
|
|
|
55
59
|
##### Options
|
|
56
60
|
|
|
57
|
-
|
|
58
|
-
|
|
61
|
+
`controller_variable` accepts one or many symbols, or a hash of symbols to options.
|
|
62
|
+
|
|
63
|
+
- `as:` - If set, the given attribute will be renamed to the given value. Helpful to avoid naming conflicts.
|
|
64
|
+
- `allow_undefined:` - By default, if the instance variable is not defined in the controller, an
|
|
65
|
+
exception will be raised. If this option is to `true`, an error will not be raised.
|
|
66
|
+
|
|
67
|
+
You can also pass a hash of attributes to `controller_variable`, where the key is the controller
|
|
68
|
+
attribute, and the value is the renamed value, or options hash.
|
|
59
69
|
|
|
60
70
|
```ruby
|
|
61
|
-
|
|
71
|
+
class Views::Users::Index < Views::Base
|
|
72
|
+
include Phlexible::Rails::ControllerVariables
|
|
73
|
+
|
|
74
|
+
controller_variable last_name: :surname, first_name: { as: :given_name, allow_undefined: true }
|
|
75
|
+
|
|
76
|
+
def template
|
|
77
|
+
h1 { "#{@given_name} #{@surname}" }
|
|
78
|
+
end
|
|
79
|
+
end
|
|
62
80
|
```
|
|
63
81
|
|
|
82
|
+
Please note that defining a variable with the same name as an existing variable in the view will be overwritten.
|
|
83
|
+
|
|
64
84
|
#### `Responder`
|
|
65
85
|
|
|
66
86
|
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.
|
|
@@ -90,7 +110,7 @@ end
|
|
|
90
110
|
|
|
91
111
|
This responder requires the use of `ActionController::ImplicitRender`, so don't forget to include that in your `ApplicationController`.
|
|
92
112
|
|
|
93
|
-
If you use `
|
|
113
|
+
If you use `ControllerVariables` in your view, and define a `resource` attribute, the responder will pass that to your view.
|
|
94
114
|
|
|
95
115
|
#### `AElement`
|
|
96
116
|
|
|
@@ -134,11 +154,43 @@ Phlexible::Rails::ButtonTo.new(:root, method: :patch) { 'My Button' }
|
|
|
134
154
|
|
|
135
155
|
##### Options
|
|
136
156
|
|
|
137
|
-
- `:class`
|
|
138
|
-
- `:
|
|
139
|
-
- `:data`
|
|
140
|
-
- `:params`
|
|
141
|
-
- `:method`
|
|
157
|
+
- `:class` - Specify the HTML class name of the button (not the form).
|
|
158
|
+
- `:form_attributes` - Hash of HTML attributes for the form tag.
|
|
159
|
+
- `:data` - This option can be used to add custom data attributes.
|
|
160
|
+
- `:params` - Hash of parameters to be rendered as hidden fields within the form.
|
|
161
|
+
- `:method` - Symbol of the HTTP verb. Supported verbs are :post (default), :get, :delete, :patch,
|
|
162
|
+
and :put.
|
|
163
|
+
|
|
164
|
+
#### `MetaTags`
|
|
165
|
+
|
|
166
|
+
> Available in **>= 1.0.0**
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
A super simple way to define and render meta tags in your Phlex views. Just render the
|
|
170
|
+
`Phlexible::Rails::MetaTagsComponent` component in the head element of your page, and define the
|
|
171
|
+
meta tags using the `meta_tag` method in your controllers.
|
|
172
|
+
|
|
173
|
+
```ruby
|
|
174
|
+
class MyController < ApplicationController
|
|
175
|
+
meta_tag :description, 'My description'
|
|
176
|
+
meta_tag :keywords, 'My keywords'
|
|
177
|
+
end
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
```ruby
|
|
181
|
+
class MyView < Phlex::HTML
|
|
182
|
+
def template
|
|
183
|
+
html do
|
|
184
|
+
head do
|
|
185
|
+
render Phlexible::Rails::MetaTagsComponent
|
|
186
|
+
end
|
|
187
|
+
body do
|
|
188
|
+
# ...
|
|
189
|
+
end
|
|
190
|
+
end
|
|
191
|
+
end
|
|
192
|
+
end
|
|
193
|
+
```
|
|
142
194
|
|
|
143
195
|
### `AliasView`
|
|
144
196
|
|
data/fixtures/rails_helper.rb
CHANGED
|
@@ -26,24 +26,12 @@ module Phlexible
|
|
|
26
26
|
render_plex_view({ action: action_name }) || super
|
|
27
27
|
end
|
|
28
28
|
|
|
29
|
-
def assign_phlex_accessors(pview)
|
|
30
|
-
pview.tap do |view|
|
|
31
|
-
if view.respond_to?(:__controller_attributes__)
|
|
32
|
-
view.__controller_attributes__.each do |attr|
|
|
33
|
-
raise ControllerAttributes::UndefinedVariable, attr unless view_assigns.key?(attr.to_s)
|
|
34
|
-
|
|
35
|
-
view.instance_variable_set :"@#{attr}", view_assigns[attr.to_s]
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
|
|
41
29
|
def method_for_action(action_name)
|
|
42
30
|
super || ('default_phlex_render' if phlex_view(action_name))
|
|
43
31
|
end
|
|
44
32
|
|
|
45
33
|
def default_phlex_render
|
|
46
|
-
render
|
|
34
|
+
render phlex_view(action_name).new
|
|
47
35
|
end
|
|
48
36
|
|
|
49
37
|
# @param options [Hash] At a minimum this may contain an `:action` key, which will be used
|
|
@@ -54,7 +42,7 @@ module Phlexible
|
|
|
54
42
|
|
|
55
43
|
return unless (view = phlex_view(options[:action]))
|
|
56
44
|
|
|
57
|
-
render
|
|
45
|
+
render view.new, options
|
|
58
46
|
end
|
|
59
47
|
|
|
60
48
|
private
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Phlexible
|
|
4
|
+
module Rails
|
|
5
|
+
module ActionController
|
|
6
|
+
module MetaTags
|
|
7
|
+
extend ActiveSupport::Concern
|
|
8
|
+
|
|
9
|
+
def meta_tags
|
|
10
|
+
@meta_tags ||= {}
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def meta_tag(name, content)
|
|
14
|
+
meta_tags[name] = content
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
module ClassMethods
|
|
18
|
+
def meta_tag(name, content, **kwargs)
|
|
19
|
+
before_action(**kwargs) do |ctrl|
|
|
20
|
+
ctrl.meta_tag name, content.is_a?(Proc) ? ctrl.instance_exec(&content) : content
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -7,11 +7,12 @@
|
|
|
7
7
|
# option.
|
|
8
8
|
#
|
|
9
9
|
# Additional arguments are passed through to the button element, with a few exceptions:
|
|
10
|
-
#
|
|
11
|
-
#
|
|
12
|
-
#
|
|
13
|
-
#
|
|
14
|
-
#
|
|
10
|
+
# - :method - Symbol of HTTP verb. Supported verbs are :post, :get, :delete, :patch, and :put.
|
|
11
|
+
# Default is :post.
|
|
12
|
+
# - :form_attributes - Hash of HTML attributes to be rendered on the form tag.
|
|
13
|
+
# - :form_class - This controls the class of the form within which the submit button will be placed.
|
|
14
|
+
# Default is 'button_to'. @deprecated: use :form_attributes instead if you want to override this.
|
|
15
|
+
# - :params - Hash of parameters to be rendered as hidden fields within the form.
|
|
15
16
|
module Phlexible
|
|
16
17
|
module Rails
|
|
17
18
|
module ButtonToConcerns
|
|
@@ -23,15 +24,14 @@ module Phlexible
|
|
|
23
24
|
@options = options
|
|
24
25
|
end
|
|
25
26
|
|
|
26
|
-
# rubocop:disable Metrics/AbcSize
|
|
27
|
-
def template(&block)
|
|
27
|
+
def template(&block) # rubocop:disable Metrics/AbcSize
|
|
28
28
|
action = helpers.url_for(@url)
|
|
29
29
|
@options = DEFAULT_OPTIONS.merge((@options || {}).symbolize_keys)
|
|
30
30
|
|
|
31
31
|
method = (@options.delete(:method).presence || method_for_options(@options)).to_s
|
|
32
32
|
form_method = method == 'get' ? 'get' : 'post'
|
|
33
33
|
|
|
34
|
-
form action: action,
|
|
34
|
+
form action: action, method: form_method, **form_attributes do
|
|
35
35
|
method_tag method
|
|
36
36
|
form_method == 'post' && token_input(action, method.empty? ? 'post' : method)
|
|
37
37
|
param_inputs
|
|
@@ -39,10 +39,16 @@ module Phlexible
|
|
|
39
39
|
block_given? ? button(**button_attrs, &block) : button(**button_attrs) { @name }
|
|
40
40
|
end
|
|
41
41
|
end
|
|
42
|
-
# rubocop:enable Metrics/AbcSize
|
|
43
42
|
|
|
44
43
|
private
|
|
45
44
|
|
|
45
|
+
def form_attributes
|
|
46
|
+
{
|
|
47
|
+
class: @options.delete(:form_class), # @deprecated
|
|
48
|
+
**(@options.delete(:form_attributes) || {})
|
|
49
|
+
}
|
|
50
|
+
end
|
|
51
|
+
|
|
46
52
|
def button_attrs
|
|
47
53
|
{
|
|
48
54
|
type: 'submit',
|
|
@@ -83,8 +89,8 @@ module Phlexible
|
|
|
83
89
|
end
|
|
84
90
|
end
|
|
85
91
|
|
|
86
|
-
# Returns an array of hashes each containing :name and :value keys
|
|
87
|
-
#
|
|
92
|
+
# Returns an array of hashes each containing :name and :value keys suitable for use as the
|
|
93
|
+
# names and values of form input fields:
|
|
88
94
|
#
|
|
89
95
|
# to_form_params(name: 'David', nationality: 'Danish')
|
|
90
96
|
# # => [{name: 'name', value: 'David'}, {name: 'nationality', value: 'Danish'}]
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Include this module in your Phlex views to get access to the controller's instance variables. It
|
|
4
|
+
# provides an explicit interface for accessing controller instance variables from the view. Simply
|
|
5
|
+
# call `controller_variable` with the name of any controller instance variable you want to access
|
|
6
|
+
# in your view.
|
|
7
|
+
#
|
|
8
|
+
# @example
|
|
9
|
+
# class Views::Users::Index < Views::Base
|
|
10
|
+
# controller_variable :user_name
|
|
11
|
+
#
|
|
12
|
+
# def template
|
|
13
|
+
# h1 { @user_name }
|
|
14
|
+
# end
|
|
15
|
+
# end
|
|
16
|
+
#
|
|
17
|
+
# Options
|
|
18
|
+
# - `as:` - If set, the given attribute will be renamed to the given value. Helpful to avoid
|
|
19
|
+
# naming conflicts.
|
|
20
|
+
# - `allow_undefined:` - If set to `true`, the view will not raise an error if the controller
|
|
21
|
+
# instance variable is not defined.
|
|
22
|
+
#
|
|
23
|
+
module Phlexible
|
|
24
|
+
module Rails
|
|
25
|
+
module ControllerVariables
|
|
26
|
+
def self.included(klass)
|
|
27
|
+
klass.class_attribute :__controller_variables__, instance_predicate: false, default: Set.new
|
|
28
|
+
klass.extend ClassMethods
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
class UndefinedVariable < NameError
|
|
32
|
+
def initialize(name)
|
|
33
|
+
@variable_name = name
|
|
34
|
+
super "Attempted to expose controller variable `#{@variable_name}`, but instance " \
|
|
35
|
+
'variable is not defined in the controller.'
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def before_template
|
|
40
|
+
if respond_to?(:__controller_variables__)
|
|
41
|
+
view_assigns = helpers.controller.view_assigns
|
|
42
|
+
|
|
43
|
+
__controller_variables__.each do |k, v|
|
|
44
|
+
allow_undefined = true
|
|
45
|
+
if k.ends_with?('!')
|
|
46
|
+
allow_undefined = false
|
|
47
|
+
k = k.chop
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
raise ControllerVariables::UndefinedVariable, k if !allow_undefined && !view_assigns.key?(k)
|
|
51
|
+
|
|
52
|
+
instance_variable_set(:"@#{v}", view_assigns[k])
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
super
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
module ClassMethods
|
|
60
|
+
def controller_variable(*names, **kwargs) # rubocop:disable Metrics/*
|
|
61
|
+
if names.empty? && kwargs.empty?
|
|
62
|
+
raise ArgumentError, 'You must provide at least one variable name and/or a hash of ' \
|
|
63
|
+
'variable names and options.'
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
allow_undefined = kwargs.delete(:allow_undefined)
|
|
67
|
+
as = kwargs.delete(:as)
|
|
68
|
+
|
|
69
|
+
if names.count > 1 && as
|
|
70
|
+
raise ArgumentError, 'You cannot provide the `as:` option when passing multiple ' \
|
|
71
|
+
'variable names.'
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
names.each do |name|
|
|
75
|
+
name_as = as || name
|
|
76
|
+
name = "#{name}!" unless allow_undefined
|
|
77
|
+
|
|
78
|
+
self.__controller_variables__ += { name.to_s => name_as.to_s }
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
kwargs.each do |k, v|
|
|
82
|
+
if v.is_a?(Hash)
|
|
83
|
+
name = v.key?(:as) ? v[:as].to_s : k.to_s
|
|
84
|
+
|
|
85
|
+
if v.key?(:allow_undefined)
|
|
86
|
+
k = "#{k}!" unless v[:allow_undefined]
|
|
87
|
+
elsif !allow_undefined
|
|
88
|
+
k = "#{k}!"
|
|
89
|
+
end
|
|
90
|
+
else
|
|
91
|
+
name = v.to_s
|
|
92
|
+
k = "#{k}!" unless allow_undefined
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
self.__controller_variables__ += { k.to_s => name }
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Phlexible
|
|
4
|
+
module Rails
|
|
5
|
+
class MetaTagsComponent < Phlex::HTML
|
|
6
|
+
def template
|
|
7
|
+
helpers.controller.view_assigns['meta_tags']&.each do |name, content|
|
|
8
|
+
meta name: name, content: content.is_a?(String) ? content : content.to_json
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
data/lib/phlexible/rails.rb
CHANGED
|
@@ -4,15 +4,17 @@ require 'phlex-rails'
|
|
|
4
4
|
|
|
5
5
|
module Phlexible
|
|
6
6
|
module Rails
|
|
7
|
-
autoload :
|
|
7
|
+
autoload :ControllerVariables, 'phlexible/rails/controller_variables'
|
|
8
8
|
autoload :Responder, 'phlexible/rails/responder'
|
|
9
9
|
autoload :AElement, 'phlexible/rails/a_element'
|
|
10
10
|
|
|
11
|
+
autoload :MetaTagsComponent, 'phlexible/rails/meta_tags_component'
|
|
11
12
|
autoload :ButtonTo, 'phlexible/rails/button_to'
|
|
12
13
|
autoload :ButtonToConcerns, 'phlexible/rails/button_to'
|
|
13
14
|
|
|
14
15
|
module ActionController
|
|
15
16
|
autoload :ImplicitRender, 'phlexible/rails/action_controller/implicit_render'
|
|
17
|
+
autoload :MetaTags, 'phlexible/rails/action_controller/meta_tags'
|
|
16
18
|
end
|
|
17
19
|
end
|
|
18
20
|
end
|
data/lib/phlexible/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: phlexible
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 1.0.0.beta.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Joel Moss
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2024-02-02 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: phlex
|
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
|
16
16
|
requirements:
|
|
17
|
-
- - "
|
|
17
|
+
- - ">="
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
19
|
version: 1.8.1
|
|
20
20
|
type: :runtime
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
|
-
- - "
|
|
24
|
+
- - ">="
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
26
|
version: 1.8.1
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
28
|
name: phlex-rails
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
30
30
|
requirements:
|
|
31
|
-
- - "
|
|
31
|
+
- - ">="
|
|
32
32
|
- !ruby/object:Gem::Version
|
|
33
33
|
version: 1.0.0
|
|
34
34
|
type: :runtime
|
|
35
35
|
prerelease: false
|
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
37
|
requirements:
|
|
38
|
-
- - "
|
|
38
|
+
- - ">="
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
40
|
version: 1.0.0
|
|
41
41
|
description: A bunch of helpers and goodies intended to make life with Phlex even
|
|
@@ -58,6 +58,7 @@ files:
|
|
|
58
58
|
- fixtures/dummy/app/controllers/articles_controller.rb
|
|
59
59
|
- fixtures/dummy/app/views/articles/index.html.erb
|
|
60
60
|
- fixtures/dummy/app/views/articles/link.rb
|
|
61
|
+
- fixtures/dummy/app/views/articles/show.rb
|
|
61
62
|
- fixtures/dummy/config/database.yml
|
|
62
63
|
- fixtures/dummy/config/routes.rb
|
|
63
64
|
- fixtures/dummy/config/storage.yml
|
|
@@ -71,8 +72,10 @@ files:
|
|
|
71
72
|
- lib/phlexible/rails.rb
|
|
72
73
|
- lib/phlexible/rails/a_element.rb
|
|
73
74
|
- lib/phlexible/rails/action_controller/implicit_render.rb
|
|
75
|
+
- lib/phlexible/rails/action_controller/meta_tags.rb
|
|
74
76
|
- lib/phlexible/rails/button_to.rb
|
|
75
|
-
- lib/phlexible/rails/
|
|
77
|
+
- lib/phlexible/rails/controller_variables.rb
|
|
78
|
+
- lib/phlexible/rails/meta_tags_component.rb
|
|
76
79
|
- lib/phlexible/rails/responder.rb
|
|
77
80
|
- lib/phlexible/version.rb
|
|
78
81
|
homepage: https://github.com/joelmoss/phlexible
|
|
@@ -98,7 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
98
101
|
- !ruby/object:Gem::Version
|
|
99
102
|
version: '0'
|
|
100
103
|
requirements: []
|
|
101
|
-
rubygems_version: 3.
|
|
104
|
+
rubygems_version: 3.5.5
|
|
102
105
|
signing_key:
|
|
103
106
|
specification_version: 4
|
|
104
107
|
summary: A bunch of helpers and goodies intended to make life with Phlex even easier!
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# Include this module in your Phlex views to get access to the controller's instance variables. It
|
|
4
|
-
# provides an explicit interface for accessing controller instance variables from the view. Simply
|
|
5
|
-
# call `controller_attribute` with the name of any controller instance variable you want to access
|
|
6
|
-
# in your view.
|
|
7
|
-
#
|
|
8
|
-
# @example
|
|
9
|
-
# class Views::Users::Index < Views::Base
|
|
10
|
-
# controller_attribute :user_name
|
|
11
|
-
#
|
|
12
|
-
# def template
|
|
13
|
-
# h1 { @user_name }
|
|
14
|
-
# end
|
|
15
|
-
# end
|
|
16
|
-
#
|
|
17
|
-
# Options
|
|
18
|
-
# - `attr_reader:` - If set to `true`, an `attr_reader` will be defined for the given attributes.
|
|
19
|
-
# - `alias:` - If set, the given attribute will be aliased to the given alias value.
|
|
20
|
-
#
|
|
21
|
-
# NOTE: Phlexible::Rails::ActionController::ImplicitRender is required for this to work.
|
|
22
|
-
#
|
|
23
|
-
module Phlexible
|
|
24
|
-
module Rails
|
|
25
|
-
module ControllerAttributes
|
|
26
|
-
extend ActiveSupport::Concern
|
|
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
|
-
|
|
36
|
-
included do
|
|
37
|
-
class_attribute :__controller_attributes__, instance_predicate: false, default: Set.new
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
class_methods do
|
|
41
|
-
def controller_attribute(*names, **kwargs)
|
|
42
|
-
self.__controller_attributes__ += names
|
|
43
|
-
|
|
44
|
-
return if kwargs.empty?
|
|
45
|
-
|
|
46
|
-
names.each do |name|
|
|
47
|
-
attr_reader name if kwargs[:attr_reader]
|
|
48
|
-
|
|
49
|
-
if kwargs[:alias]
|
|
50
|
-
if kwargs[:attr_reader]
|
|
51
|
-
alias_method kwargs[:alias], name
|
|
52
|
-
else
|
|
53
|
-
define_method(kwargs[:alias]) { instance_variable_get :"@#{name}" }
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
end
|