phlexible 0.2.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/Gemfile.lock +92 -85
- data/README.md +39 -11
- data/lib/phlexible/page_title.rb +2 -1
- data/lib/phlexible/rails/action_controller/implicit_render.rb +22 -19
- data/lib/phlexible/rails/button_to.rb +3 -10
- data/lib/phlexible/rails/controller_attributes.rb +44 -0
- data/lib/phlexible/rails/responder.rb +9 -5
- data/lib/phlexible/rails.rb +1 -0
- data/lib/phlexible/version.rb +1 -1
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 27b319da9b017a6659e7a8372c67da3fe5f2d41c60d853a0ff095d97770f9269
|
4
|
+
data.tar.gz: 2d4ecd695d5b0265f4884eddb7ab90c942687953314b831c292971542377ebcf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f20789eac80d0b8c65db6552f8528ff63dcd0952f3e2039bfc5ec4c200c700e8795979c9249d3e8f15a1103a2b8a3b79212dbd234632c3b94a7d305eb1442a7
|
7
|
+
data.tar.gz: df64f02ad32290c863b305db652043119098bc8034744dae36c45901fb23195994260f482ae2c6a9c2a161616f4a6913055abfec0659b5f7db6452ffbf11993e
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,97 +1,100 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
phlexible (0.
|
5
|
-
phlex (~> 1.
|
6
|
-
phlex-rails (~> 0.
|
4
|
+
phlexible (0.3.0)
|
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
|
-
actioncable (7.0.4)
|
12
|
-
actionpack (= 7.0.4)
|
13
|
-
activesupport (= 7.0.4)
|
11
|
+
actioncable (7.0.4.3)
|
12
|
+
actionpack (= 7.0.4.3)
|
13
|
+
activesupport (= 7.0.4.3)
|
14
14
|
nio4r (~> 2.0)
|
15
15
|
websocket-driver (>= 0.6.1)
|
16
|
-
actionmailbox (7.0.4)
|
17
|
-
actionpack (= 7.0.4)
|
18
|
-
activejob (= 7.0.4)
|
19
|
-
activerecord (= 7.0.4)
|
20
|
-
activestorage (= 7.0.4)
|
21
|
-
activesupport (= 7.0.4)
|
16
|
+
actionmailbox (7.0.4.3)
|
17
|
+
actionpack (= 7.0.4.3)
|
18
|
+
activejob (= 7.0.4.3)
|
19
|
+
activerecord (= 7.0.4.3)
|
20
|
+
activestorage (= 7.0.4.3)
|
21
|
+
activesupport (= 7.0.4.3)
|
22
22
|
mail (>= 2.7.1)
|
23
23
|
net-imap
|
24
24
|
net-pop
|
25
25
|
net-smtp
|
26
|
-
actionmailer (7.0.4)
|
27
|
-
actionpack (= 7.0.4)
|
28
|
-
actionview (= 7.0.4)
|
29
|
-
activejob (= 7.0.4)
|
30
|
-
activesupport (= 7.0.4)
|
26
|
+
actionmailer (7.0.4.3)
|
27
|
+
actionpack (= 7.0.4.3)
|
28
|
+
actionview (= 7.0.4.3)
|
29
|
+
activejob (= 7.0.4.3)
|
30
|
+
activesupport (= 7.0.4.3)
|
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.4)
|
37
|
-
actionview (= 7.0.4)
|
38
|
-
activesupport (= 7.0.4)
|
36
|
+
actionpack (7.0.4.3)
|
37
|
+
actionview (= 7.0.4.3)
|
38
|
+
activesupport (= 7.0.4.3)
|
39
39
|
rack (~> 2.0, >= 2.2.0)
|
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.4)
|
44
|
-
actionpack (= 7.0.4)
|
45
|
-
activerecord (= 7.0.4)
|
46
|
-
activestorage (= 7.0.4)
|
47
|
-
activesupport (= 7.0.4)
|
43
|
+
actiontext (7.0.4.3)
|
44
|
+
actionpack (= 7.0.4.3)
|
45
|
+
activerecord (= 7.0.4.3)
|
46
|
+
activestorage (= 7.0.4.3)
|
47
|
+
activesupport (= 7.0.4.3)
|
48
48
|
globalid (>= 0.6.0)
|
49
49
|
nokogiri (>= 1.8.5)
|
50
|
-
actionview (7.0.4)
|
51
|
-
activesupport (= 7.0.4)
|
50
|
+
actionview (7.0.4.3)
|
51
|
+
activesupport (= 7.0.4.3)
|
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.4)
|
57
|
-
activesupport (= 7.0.4)
|
56
|
+
activejob (7.0.4.3)
|
57
|
+
activesupport (= 7.0.4.3)
|
58
58
|
globalid (>= 0.3.6)
|
59
|
-
activemodel (7.0.4)
|
60
|
-
activesupport (= 7.0.4)
|
61
|
-
activerecord (7.0.4)
|
62
|
-
activemodel (= 7.0.4)
|
63
|
-
activesupport (= 7.0.4)
|
64
|
-
activestorage (7.0.4)
|
65
|
-
actionpack (= 7.0.4)
|
66
|
-
activejob (= 7.0.4)
|
67
|
-
activerecord (= 7.0.4)
|
68
|
-
activesupport (= 7.0.4)
|
59
|
+
activemodel (7.0.4.3)
|
60
|
+
activesupport (= 7.0.4.3)
|
61
|
+
activerecord (7.0.4.3)
|
62
|
+
activemodel (= 7.0.4.3)
|
63
|
+
activesupport (= 7.0.4.3)
|
64
|
+
activestorage (7.0.4.3)
|
65
|
+
actionpack (= 7.0.4.3)
|
66
|
+
activejob (= 7.0.4.3)
|
67
|
+
activerecord (= 7.0.4.3)
|
68
|
+
activesupport (= 7.0.4.3)
|
69
69
|
marcel (~> 1.0)
|
70
70
|
mini_mime (>= 1.1.0)
|
71
|
-
activesupport (7.0.4)
|
71
|
+
activesupport (7.0.4.3)
|
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
77
|
builder (3.2.4)
|
78
|
+
cgi (0.3.6)
|
78
79
|
combustion (1.3.7)
|
79
80
|
activesupport (>= 3.0.0)
|
80
81
|
railties (>= 3.0.0)
|
81
82
|
thor (>= 0.14.6)
|
82
|
-
concurrent-ruby (1.
|
83
|
+
concurrent-ruby (1.2.2)
|
83
84
|
crass (1.0.6)
|
84
85
|
date (3.3.3)
|
86
|
+
erb (4.0.2)
|
87
|
+
cgi (>= 0.3.3)
|
85
88
|
erubi (1.12.0)
|
86
|
-
globalid (1.
|
89
|
+
globalid (1.1.0)
|
87
90
|
activesupport (>= 5.0)
|
88
91
|
i18n (1.12.0)
|
89
92
|
concurrent-ruby (~> 1.0)
|
90
93
|
json (2.6.3)
|
91
|
-
loofah (2.
|
94
|
+
loofah (2.20.0)
|
92
95
|
crass (~> 1.0.2)
|
93
96
|
nokogiri (>= 1.5.9)
|
94
|
-
mail (2.8.
|
97
|
+
mail (2.8.1)
|
95
98
|
mini_mime (>= 0.1.1)
|
96
99
|
net-imap
|
97
100
|
net-pop
|
@@ -99,8 +102,7 @@ GEM
|
|
99
102
|
marcel (1.0.2)
|
100
103
|
method_source (1.0.0)
|
101
104
|
mini_mime (1.1.2)
|
102
|
-
|
103
|
-
minitest (5.17.0)
|
105
|
+
minitest (5.18.0)
|
104
106
|
net-imap (0.3.4)
|
105
107
|
date
|
106
108
|
net-protocol
|
@@ -110,79 +112,84 @@ GEM
|
|
110
112
|
timeout
|
111
113
|
net-smtp (0.3.3)
|
112
114
|
net-protocol
|
113
|
-
nio4r (2.5.
|
114
|
-
nokogiri (1.
|
115
|
-
mini_portile2 (~> 2.8.0)
|
115
|
+
nio4r (2.5.9)
|
116
|
+
nokogiri (1.14.3-arm64-darwin)
|
116
117
|
racc (~> 1.4)
|
117
|
-
|
118
|
-
|
118
|
+
nokogiri (1.14.3-x86_64-darwin)
|
119
|
+
racc (~> 1.4)
|
120
|
+
nokogiri (1.14.3-x86_64-linux)
|
121
|
+
racc (~> 1.4)
|
122
|
+
parallel (1.23.0)
|
123
|
+
parser (3.2.2.1)
|
119
124
|
ast (~> 2.4.1)
|
120
|
-
phlex (1.1
|
125
|
+
phlex (1.8.1)
|
126
|
+
concurrent-ruby (~> 1.2)
|
127
|
+
erb (>= 4)
|
121
128
|
zeitwerk (~> 2.6)
|
122
|
-
phlex-rails (0.
|
123
|
-
phlex (
|
129
|
+
phlex-rails (1.0.0)
|
130
|
+
phlex (~> 1.7)
|
124
131
|
rails (>= 6.1, < 8)
|
125
|
-
zeitwerk (~> 2)
|
132
|
+
zeitwerk (~> 2.6)
|
126
133
|
phlex-testing-nokogiri (0.1.0)
|
127
134
|
nokogiri (~> 1.13)
|
128
135
|
phlex (>= 0.5)
|
129
136
|
racc (1.6.2)
|
130
|
-
rack (2.2.
|
131
|
-
rack-test (2.0
|
137
|
+
rack (2.2.6.4)
|
138
|
+
rack-test (2.1.0)
|
132
139
|
rack (>= 1.3)
|
133
|
-
rails (7.0.4)
|
134
|
-
actioncable (= 7.0.4)
|
135
|
-
actionmailbox (= 7.0.4)
|
136
|
-
actionmailer (= 7.0.4)
|
137
|
-
actionpack (= 7.0.4)
|
138
|
-
actiontext (= 7.0.4)
|
139
|
-
actionview (= 7.0.4)
|
140
|
-
activejob (= 7.0.4)
|
141
|
-
activemodel (= 7.0.4)
|
142
|
-
activerecord (= 7.0.4)
|
143
|
-
activestorage (= 7.0.4)
|
144
|
-
activesupport (= 7.0.4)
|
140
|
+
rails (7.0.4.3)
|
141
|
+
actioncable (= 7.0.4.3)
|
142
|
+
actionmailbox (= 7.0.4.3)
|
143
|
+
actionmailer (= 7.0.4.3)
|
144
|
+
actionpack (= 7.0.4.3)
|
145
|
+
actiontext (= 7.0.4.3)
|
146
|
+
actionview (= 7.0.4.3)
|
147
|
+
activejob (= 7.0.4.3)
|
148
|
+
activemodel (= 7.0.4.3)
|
149
|
+
activerecord (= 7.0.4.3)
|
150
|
+
activestorage (= 7.0.4.3)
|
151
|
+
activesupport (= 7.0.4.3)
|
145
152
|
bundler (>= 1.15.0)
|
146
|
-
railties (= 7.0.4)
|
153
|
+
railties (= 7.0.4.3)
|
147
154
|
rails-dom-testing (2.0.3)
|
148
155
|
activesupport (>= 4.2.0)
|
149
156
|
nokogiri (>= 1.6)
|
150
|
-
rails-html-sanitizer (1.
|
157
|
+
rails-html-sanitizer (1.5.0)
|
151
158
|
loofah (~> 2.19, >= 2.19.1)
|
152
|
-
railties (7.0.4)
|
153
|
-
actionpack (= 7.0.4)
|
154
|
-
activesupport (= 7.0.4)
|
159
|
+
railties (7.0.4.3)
|
160
|
+
actionpack (= 7.0.4.3)
|
161
|
+
activesupport (= 7.0.4.3)
|
155
162
|
method_source
|
156
163
|
rake (>= 12.2)
|
157
164
|
thor (~> 1.0)
|
158
165
|
zeitwerk (~> 2.5)
|
159
166
|
rainbow (3.1.1)
|
160
167
|
rake (13.0.6)
|
161
|
-
regexp_parser (2.
|
168
|
+
regexp_parser (2.8.0)
|
162
169
|
rexml (3.2.5)
|
163
|
-
rubocop (1.
|
170
|
+
rubocop (1.50.2)
|
164
171
|
json (~> 2.3)
|
165
172
|
parallel (~> 1.10)
|
166
173
|
parser (>= 3.2.0.0)
|
167
174
|
rainbow (>= 2.2.2, < 4.0)
|
168
175
|
regexp_parser (>= 1.8, < 3.0)
|
169
176
|
rexml (>= 3.2.5, < 4.0)
|
170
|
-
rubocop-ast (>= 1.
|
177
|
+
rubocop-ast (>= 1.28.0, < 2.0)
|
171
178
|
ruby-progressbar (~> 1.7)
|
172
179
|
unicode-display_width (>= 2.4.0, < 3.0)
|
173
|
-
rubocop-ast (1.
|
174
|
-
parser (>= 3.
|
175
|
-
ruby-progressbar (1.
|
176
|
-
sus (0.
|
180
|
+
rubocop-ast (1.28.0)
|
181
|
+
parser (>= 3.2.1.0)
|
182
|
+
ruby-progressbar (1.13.0)
|
183
|
+
sus (0.20.3)
|
177
184
|
thor (1.2.1)
|
178
|
-
timeout (0.3.
|
179
|
-
tzinfo (2.0.
|
185
|
+
timeout (0.3.2)
|
186
|
+
tzinfo (2.0.6)
|
180
187
|
concurrent-ruby (~> 1.0)
|
181
188
|
unicode-display_width (2.4.2)
|
182
189
|
websocket-driver (0.7.5)
|
183
190
|
websocket-extensions (>= 0.1.0)
|
184
191
|
websocket-extensions (0.1.5)
|
185
|
-
zeitwerk (2.6.
|
192
|
+
zeitwerk (2.6.7)
|
186
193
|
|
187
194
|
PLATFORMS
|
188
195
|
arm64-darwin-22
|
@@ -195,7 +202,7 @@ DEPENDENCIES
|
|
195
202
|
phlexible!
|
196
203
|
rake (~> 13.0)
|
197
204
|
rubocop (~> 1.21)
|
198
|
-
sus (~> 0.
|
205
|
+
sus (~> 0.20.0)
|
199
206
|
|
200
207
|
BUNDLED WITH
|
201
208
|
2.4.1
|
data/README.md
CHANGED
@@ -36,6 +36,32 @@ class UsersController
|
|
36
36
|
end
|
37
37
|
```
|
38
38
|
|
39
|
+
#### `ControllerAttributes`
|
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.
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
class Views::Users::Index < Views::Base
|
46
|
+
include Phlexible::Rails::ControllerAttributes
|
47
|
+
|
48
|
+
controller_attribute :first_name, :last_name
|
49
|
+
|
50
|
+
def template
|
51
|
+
h1 { "#{@first_name} #{@last_name}" }
|
52
|
+
end
|
53
|
+
end
|
54
|
+
```
|
55
|
+
|
56
|
+
##### Options
|
57
|
+
|
58
|
+
- `attr_reader:` - If set to `true`, an `attr_reader` will be defined for the given attributes.
|
59
|
+
- `alias:` - If set, the given attribute will be aliased to the given alias value.
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
controller_attribute :users, attr_reader: true, alias: :my_users
|
63
|
+
```
|
64
|
+
|
39
65
|
#### `Responder`
|
40
66
|
|
41
67
|
If you use [Responders](https://github.com/heartcombo/responders), Phlexible provides a responder to
|
@@ -46,6 +72,7 @@ Just include it in your ApplicationResponder:
|
|
46
72
|
|
47
73
|
```ruby
|
48
74
|
class ApplicationResponder < ActionController::Responder
|
75
|
+
include Phlexible::Rails::ActionController::ImplicitRender
|
49
76
|
include Phlexible::Rails::Responder
|
50
77
|
end
|
51
78
|
```
|
@@ -57,12 +84,19 @@ class UsersController < ApplicationController
|
|
57
84
|
def new
|
58
85
|
respond_with User.new
|
59
86
|
end
|
87
|
+
|
88
|
+
def index
|
89
|
+
respond_with User.all
|
90
|
+
end
|
60
91
|
end
|
61
92
|
```
|
62
93
|
|
63
|
-
This responder requires the use of `ActionController::ImplicitRender`, so
|
94
|
+
This responder requires the use of `ActionController::ImplicitRender`, so don't forget to include
|
64
95
|
that in your `ApplicationController`.
|
65
96
|
|
97
|
+
If you use `ControllerAttributes` in your view, and define a `resource` attribute, the responder
|
98
|
+
will pass that to your view.
|
99
|
+
|
66
100
|
#### `AElement`
|
67
101
|
|
68
102
|
No need to call Rails `link_to` helper, when you can simply render an anchor tag directly with
|
@@ -92,17 +126,11 @@ end
|
|
92
126
|
|
93
127
|
Generates a form containing a single button that submits to the URL created by the set of options.
|
94
128
|
|
95
|
-
It is similar to Rails `button_to` helper, which accepts the
|
96
|
-
|
97
|
-
|
98
|
-
```ruby
|
99
|
-
Phlexible::Rails::ButtonTo.new 'My Button', :root
|
100
|
-
```
|
101
|
-
|
102
|
-
Alternatively you can pass a block; the result of which will be used as the value of the button.
|
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.
|
103
131
|
|
104
132
|
```ruby
|
105
|
-
Phlexible::Rails::ButtonTo.new(:root) { '
|
133
|
+
Phlexible::Rails::ButtonTo.new(:root) { 'My Button' }
|
106
134
|
```
|
107
135
|
|
108
136
|
The url argument accepts the same options as Rails `url_for`.
|
@@ -111,7 +139,7 @@ The form submits a POST request by default. You can specify a different HTTP ver
|
|
111
139
|
option.
|
112
140
|
|
113
141
|
```ruby
|
114
|
-
Phlexible::Rails::ButtonTo.new
|
142
|
+
Phlexible::Rails::ButtonTo.new(:root, method: :patch) { 'My Button' }
|
115
143
|
```
|
116
144
|
|
117
145
|
##### Options
|
data/lib/phlexible/page_title.rb
CHANGED
@@ -4,9 +4,10 @@ module Phlexible
|
|
4
4
|
#
|
5
5
|
# Helper to assist in defining page titles within Phlex views. Also includes support for nested
|
6
6
|
# views, where each desendent view class will have its title prepended to the page title. Simply
|
7
|
-
# assign the title to the `page_title` class variable:
|
7
|
+
# include the module and assign the title to the `page_title` class variable:
|
8
8
|
#
|
9
9
|
# class MyView
|
10
|
+
# include Phlexible::PageTitle
|
10
11
|
# self.page_title = 'My Title'
|
11
12
|
# end
|
12
13
|
#
|
@@ -11,39 +11,42 @@
|
|
11
11
|
# You can do this:
|
12
12
|
#
|
13
13
|
# class UsersController
|
14
|
+
# include Phlexible::Rails::ActionController::ImplicitRender
|
14
15
|
# end
|
15
16
|
#
|
16
17
|
module Phlexible
|
17
18
|
module Rails
|
18
19
|
module ActionController
|
19
20
|
module ImplicitRender
|
20
|
-
NUFFIN = 'NUFFIN'
|
21
|
-
|
22
21
|
def default_render
|
23
|
-
|
22
|
+
render_plex_view({ action: action_name }) || super
|
24
23
|
end
|
25
24
|
|
26
|
-
def
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
25
|
+
def assign_phlex_accessors(pview)
|
26
|
+
pview.tap do |view|
|
27
|
+
view.__controller_attributes__.each do |attr|
|
28
|
+
view.instance_variable_set :"@#{attr}", view_assigns[attr.to_s]
|
29
|
+
end
|
30
|
+
end
|
31
31
|
end
|
32
32
|
|
33
|
-
private
|
34
|
-
|
35
33
|
def method_for_action(action_name)
|
36
|
-
if
|
37
|
-
action_name
|
38
|
-
elsif phlex_view
|
39
|
-
'_handle_view_class'
|
40
|
-
elsif respond_to?(:action_missing, true)
|
41
|
-
'_handle_action_missing'
|
42
|
-
end
|
34
|
+
super || ('default_phlex_render' if phlex_view(action_name))
|
43
35
|
end
|
44
36
|
|
45
|
-
def
|
46
|
-
|
37
|
+
def default_phlex_render
|
38
|
+
render assign_phlex_accessors(phlex_view(action_name).new)
|
39
|
+
end
|
40
|
+
|
41
|
+
# @param options [Hash] At a minimum this may contain an `:action` key, which will be used
|
42
|
+
# as the name of the view to render. If no `:action` key is provided, the current
|
43
|
+
# `action_name` is used.
|
44
|
+
def render_plex_view(options)
|
45
|
+
options[:action] ||= action_name
|
46
|
+
|
47
|
+
return unless (view = phlex_view(options[:action]))
|
48
|
+
|
49
|
+
render assign_phlex_accessors(view.new)
|
47
50
|
end
|
48
51
|
|
49
52
|
def phlex_view(action_name = @_action_name)
|
@@ -11,20 +11,13 @@ module Phlexible
|
|
11
11
|
BUTTON_TAG_METHOD_VERBS = %w[patch put delete].freeze
|
12
12
|
DEFAULT_OPTIONS = { method: 'post', form_class: 'button_to' }.freeze
|
13
13
|
|
14
|
-
def initialize(
|
15
|
-
@name = name
|
14
|
+
def initialize(url, options = nil)
|
16
15
|
@url = url
|
17
16
|
@options = options
|
18
17
|
end
|
19
18
|
|
20
|
-
# rubocop:disable Metrics/AbcSize
|
19
|
+
# rubocop:disable Metrics/AbcSize
|
21
20
|
def template(&block)
|
22
|
-
if block_given?
|
23
|
-
@options = @url
|
24
|
-
@url = @name
|
25
|
-
@name = nil
|
26
|
-
end
|
27
|
-
|
28
21
|
action = helpers.url_for(@url)
|
29
22
|
@options = DEFAULT_OPTIONS.merge((@options || {}).symbolize_keys)
|
30
23
|
|
@@ -38,7 +31,7 @@ module Phlexible
|
|
38
31
|
block_given? ? button(**button_attrs, &block) : button(**button_attrs) { @name }
|
39
32
|
end
|
40
33
|
end
|
41
|
-
# rubocop:enable Metrics/AbcSize
|
34
|
+
# rubocop:enable Metrics/AbcSize
|
42
35
|
|
43
36
|
private
|
44
37
|
|
@@ -0,0 +1,44 @@
|
|
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
|
+
module Phlexible
|
22
|
+
module Rails
|
23
|
+
module ControllerAttributes
|
24
|
+
extend ActiveSupport::Concern
|
25
|
+
|
26
|
+
included do
|
27
|
+
class_attribute :__controller_attributes__, instance_predicate: false, default: Set.new
|
28
|
+
end
|
29
|
+
|
30
|
+
class_methods do
|
31
|
+
def controller_attribute(*names, **kwargs)
|
32
|
+
self.__controller_attributes__ += names
|
33
|
+
|
34
|
+
return if kwargs.empty?
|
35
|
+
|
36
|
+
names.each do |name|
|
37
|
+
attr_reader name if kwargs[:attr_reader]
|
38
|
+
alias_method kwargs[:alias], name if kwargs[:alias]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -5,21 +5,25 @@ module Phlexible
|
|
5
5
|
module Responder
|
6
6
|
# Overridden to support implicit rendering of phlex views.
|
7
7
|
def default_render
|
8
|
+
return super if format != :html
|
9
|
+
|
8
10
|
if @default_response
|
9
11
|
@default_response.call(options)
|
10
12
|
elsif !get? && has_errors?
|
11
|
-
render_phlex_view
|
13
|
+
render_phlex_view({ status: error_status }.merge!(options))
|
12
14
|
else
|
13
15
|
render_phlex_view options
|
14
16
|
end
|
15
17
|
end
|
16
18
|
|
17
|
-
# Render the Phlex view with the current resource. Falls back to default controller rendering
|
18
|
-
# no Phlex view exists.
|
19
|
+
# Render the Phlex view with the current resource. Falls back to default controller rendering
|
20
|
+
# if no Phlex view exists. Also passes the current resource to the view, which is then
|
21
|
+
# available as `@resource`.
|
19
22
|
#
|
20
|
-
# @see Phlexible::Rails::ActionController::ImplicitRender#
|
23
|
+
# @see Phlexible::Rails::ActionController::ImplicitRender#render_plex_view
|
21
24
|
def render_phlex_view(options)
|
22
|
-
controller.
|
25
|
+
controller.instance_variable_set :@resource, @resource
|
26
|
+
controller.render_plex_view(options) || controller.render(options)
|
23
27
|
end
|
24
28
|
alias render render_phlex_view
|
25
29
|
end
|
data/lib/phlexible/rails.rb
CHANGED
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.4.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-05-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: phlex
|
@@ -16,28 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
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
|
-
version:
|
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
|
-
version:
|
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
|
-
version:
|
40
|
+
version: 1.0.0
|
41
41
|
description: A bunch of helpers and goodies intended to make life with Phlex even
|
42
42
|
easier!
|
43
43
|
email:
|
@@ -72,6 +72,7 @@ files:
|
|
72
72
|
- lib/phlexible/rails/a_element.rb
|
73
73
|
- lib/phlexible/rails/action_controller/implicit_render.rb
|
74
74
|
- lib/phlexible/rails/button_to.rb
|
75
|
+
- lib/phlexible/rails/controller_attributes.rb
|
75
76
|
- lib/phlexible/rails/responder.rb
|
76
77
|
- lib/phlexible/version.rb
|
77
78
|
homepage: https://github.com/joelmoss/phlexible
|
@@ -97,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
97
98
|
- !ruby/object:Gem::Version
|
98
99
|
version: '0'
|
99
100
|
requirements: []
|
100
|
-
rubygems_version: 3.4.
|
101
|
+
rubygems_version: 3.4.10
|
101
102
|
signing_key:
|
102
103
|
specification_version: 4
|
103
104
|
summary: A bunch of helpers and goodies intended to make life with Phlex even easier!
|