phlexible 0.3.0 → 0.4.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/Gemfile.lock +72 -72
- data/README.md +34 -26
- data/lib/phlexible/rails/action_controller/implicit_render.rb +23 -27
- data/lib/phlexible/rails/button_to.rb +3 -10
- data/lib/phlexible/rails/controller_attributes.rb +44 -0
- data/lib/phlexible/rails/responder.rb +8 -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: 4f5bc2167c1561048483003a2409f70153abcb79a94107c3fec5408ccfe33436
|
|
4
|
+
data.tar.gz: 8e59526996b1734e16933da161d42f930febc4f0f960852c2fec6a3a531293da
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7f6344c05d305195c98828c7709d229b45616fb31e2bb73403990f8d402aa3184b54c83cb04924e21373923aeaf00a92fd152ed9f780b84a6ba3f5451472f8a4
|
|
7
|
+
data.tar.gz: 2c2e2367325c27ab5055543a2b0e88d573bf186ae1a31ec3c94d2f73515a1db27e93f8b86687e09e968f186a734f392862c0548a295a1a29e56f67be04c3b2b1
|
data/Gemfile.lock
CHANGED
|
@@ -1,74 +1,74 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
phlexible (0.
|
|
5
|
-
phlex (~> 1.
|
|
6
|
-
phlex-rails (~> 0.
|
|
4
|
+
phlexible (0.4.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)
|
|
@@ -91,7 +91,7 @@ GEM
|
|
|
91
91
|
i18n (1.12.0)
|
|
92
92
|
concurrent-ruby (~> 1.0)
|
|
93
93
|
json (2.6.3)
|
|
94
|
-
loofah (2.
|
|
94
|
+
loofah (2.20.0)
|
|
95
95
|
crass (~> 1.0.2)
|
|
96
96
|
nokogiri (>= 1.5.9)
|
|
97
97
|
mail (2.8.1)
|
|
@@ -112,72 +112,72 @@ GEM
|
|
|
112
112
|
timeout
|
|
113
113
|
net-smtp (0.3.3)
|
|
114
114
|
net-protocol
|
|
115
|
-
nio4r (2.5.
|
|
116
|
-
nokogiri (1.14.
|
|
115
|
+
nio4r (2.5.9)
|
|
116
|
+
nokogiri (1.14.3-arm64-darwin)
|
|
117
117
|
racc (~> 1.4)
|
|
118
|
-
nokogiri (1.14.
|
|
118
|
+
nokogiri (1.14.3-x86_64-darwin)
|
|
119
119
|
racc (~> 1.4)
|
|
120
|
-
nokogiri (1.14.
|
|
120
|
+
nokogiri (1.14.3-x86_64-linux)
|
|
121
121
|
racc (~> 1.4)
|
|
122
|
-
parallel (1.
|
|
123
|
-
parser (3.2.1
|
|
122
|
+
parallel (1.23.0)
|
|
123
|
+
parser (3.2.2.1)
|
|
124
124
|
ast (~> 2.4.1)
|
|
125
|
-
phlex (1.
|
|
125
|
+
phlex (1.8.1)
|
|
126
126
|
concurrent-ruby (~> 1.2)
|
|
127
127
|
erb (>= 4)
|
|
128
128
|
zeitwerk (~> 2.6)
|
|
129
|
-
phlex-rails (0.
|
|
130
|
-
phlex (~> 1.
|
|
129
|
+
phlex-rails (1.0.0)
|
|
130
|
+
phlex (~> 1.7)
|
|
131
131
|
rails (>= 6.1, < 8)
|
|
132
132
|
zeitwerk (~> 2.6)
|
|
133
133
|
phlex-testing-nokogiri (0.1.0)
|
|
134
134
|
nokogiri (~> 1.13)
|
|
135
135
|
phlex (>= 0.5)
|
|
136
136
|
racc (1.6.2)
|
|
137
|
-
rack (2.2.6.
|
|
138
|
-
rack-test (2.0
|
|
137
|
+
rack (2.2.6.4)
|
|
138
|
+
rack-test (2.1.0)
|
|
139
139
|
rack (>= 1.3)
|
|
140
|
-
rails (7.0.4.
|
|
141
|
-
actioncable (= 7.0.4.
|
|
142
|
-
actionmailbox (= 7.0.4.
|
|
143
|
-
actionmailer (= 7.0.4.
|
|
144
|
-
actionpack (= 7.0.4.
|
|
145
|
-
actiontext (= 7.0.4.
|
|
146
|
-
actionview (= 7.0.4.
|
|
147
|
-
activejob (= 7.0.4.
|
|
148
|
-
activemodel (= 7.0.4.
|
|
149
|
-
activerecord (= 7.0.4.
|
|
150
|
-
activestorage (= 7.0.4.
|
|
151
|
-
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)
|
|
152
152
|
bundler (>= 1.15.0)
|
|
153
|
-
railties (= 7.0.4.
|
|
153
|
+
railties (= 7.0.4.3)
|
|
154
154
|
rails-dom-testing (2.0.3)
|
|
155
155
|
activesupport (>= 4.2.0)
|
|
156
156
|
nokogiri (>= 1.6)
|
|
157
157
|
rails-html-sanitizer (1.5.0)
|
|
158
158
|
loofah (~> 2.19, >= 2.19.1)
|
|
159
|
-
railties (7.0.4.
|
|
160
|
-
actionpack (= 7.0.4.
|
|
161
|
-
activesupport (= 7.0.4.
|
|
159
|
+
railties (7.0.4.3)
|
|
160
|
+
actionpack (= 7.0.4.3)
|
|
161
|
+
activesupport (= 7.0.4.3)
|
|
162
162
|
method_source
|
|
163
163
|
rake (>= 12.2)
|
|
164
164
|
thor (~> 1.0)
|
|
165
165
|
zeitwerk (~> 2.5)
|
|
166
166
|
rainbow (3.1.1)
|
|
167
167
|
rake (13.0.6)
|
|
168
|
-
regexp_parser (2.
|
|
168
|
+
regexp_parser (2.8.0)
|
|
169
169
|
rexml (3.2.5)
|
|
170
|
-
rubocop (1.
|
|
170
|
+
rubocop (1.50.2)
|
|
171
171
|
json (~> 2.3)
|
|
172
172
|
parallel (~> 1.10)
|
|
173
173
|
parser (>= 3.2.0.0)
|
|
174
174
|
rainbow (>= 2.2.2, < 4.0)
|
|
175
175
|
regexp_parser (>= 1.8, < 3.0)
|
|
176
176
|
rexml (>= 3.2.5, < 4.0)
|
|
177
|
-
rubocop-ast (>= 1.
|
|
177
|
+
rubocop-ast (>= 1.28.0, < 2.0)
|
|
178
178
|
ruby-progressbar (~> 1.7)
|
|
179
179
|
unicode-display_width (>= 2.4.0, < 3.0)
|
|
180
|
-
rubocop-ast (1.
|
|
180
|
+
rubocop-ast (1.28.0)
|
|
181
181
|
parser (>= 3.2.1.0)
|
|
182
182
|
ruby-progressbar (1.13.0)
|
|
183
183
|
sus (0.20.3)
|
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
|
|
@@ -65,24 +91,12 @@ class UsersController < ApplicationController
|
|
|
65
91
|
end
|
|
66
92
|
```
|
|
67
93
|
|
|
68
|
-
|
|
69
|
-
argument:
|
|
70
|
-
|
|
71
|
-
```ruby
|
|
72
|
-
class UsersController < ApplicationController
|
|
73
|
-
def index
|
|
74
|
-
respond_with User.all, view_options: { page: 1 }
|
|
75
|
-
end
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
class Views::Users::Index < Phlex::HTML
|
|
79
|
-
def initialize(users, page:); end
|
|
80
|
-
end
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
This responder requires the use of `ActionController::ImplicitRender`, so dont't forget to include
|
|
94
|
+
This responder requires the use of `ActionController::ImplicitRender`, so don't forget to include
|
|
84
95
|
that in your `ApplicationController`.
|
|
85
96
|
|
|
97
|
+
If you use `ControllerAttributes` in your view, and define a `resource` attribute, the responder
|
|
98
|
+
will pass that to your view.
|
|
99
|
+
|
|
86
100
|
#### `AElement`
|
|
87
101
|
|
|
88
102
|
No need to call Rails `link_to` helper, when you can simply render an anchor tag directly with
|
|
@@ -112,17 +126,11 @@ end
|
|
|
112
126
|
|
|
113
127
|
Generates a form containing a single button that submits to the URL created by the set of options.
|
|
114
128
|
|
|
115
|
-
It is similar to Rails `button_to` helper, which accepts the
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
```ruby
|
|
119
|
-
Phlexible::Rails::ButtonTo.new 'My Button', :root
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
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.
|
|
123
131
|
|
|
124
132
|
```ruby
|
|
125
|
-
Phlexible::Rails::ButtonTo.new(:root) { '
|
|
133
|
+
Phlexible::Rails::ButtonTo.new(:root) { 'My Button' }
|
|
126
134
|
```
|
|
127
135
|
|
|
128
136
|
The url argument accepts the same options as Rails `url_for`.
|
|
@@ -131,7 +139,7 @@ The form submits a POST request by default. You can specify a different HTTP ver
|
|
|
131
139
|
option.
|
|
132
140
|
|
|
133
141
|
```ruby
|
|
134
|
-
Phlexible::Rails::ButtonTo.new
|
|
142
|
+
Phlexible::Rails::ButtonTo.new(:root, method: :patch) { 'My Button' }
|
|
135
143
|
```
|
|
136
144
|
|
|
137
145
|
##### Options
|
|
@@ -11,48 +11,44 @@
|
|
|
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
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
render klass.new(**view_options), render_options
|
|
34
|
-
else
|
|
35
|
-
kwargs = {}
|
|
36
|
-
kwargs = render_options.delete(:view_options) if render_options.key?(:view_options)
|
|
37
|
-
|
|
38
|
-
render klass.new(view_options, **kwargs), render_options
|
|
25
|
+
def assign_phlex_accessors(pview)
|
|
26
|
+
pview.tap do |view|
|
|
27
|
+
if view.respond_to?(:__controller_attributes__)
|
|
28
|
+
view.__controller_attributes__.each do |attr|
|
|
29
|
+
view.instance_variable_set :"@#{attr}", view_assigns[attr.to_s]
|
|
30
|
+
end
|
|
31
|
+
end
|
|
39
32
|
end
|
|
40
33
|
end
|
|
41
34
|
|
|
42
|
-
private
|
|
43
|
-
|
|
44
35
|
def method_for_action(action_name)
|
|
45
|
-
if
|
|
46
|
-
action_name
|
|
47
|
-
elsif phlex_view
|
|
48
|
-
'_handle_view_class'
|
|
49
|
-
elsif respond_to?(:action_missing, true)
|
|
50
|
-
'_handle_action_missing'
|
|
51
|
-
end
|
|
36
|
+
super || ('default_phlex_render' if phlex_view(action_name))
|
|
52
37
|
end
|
|
53
38
|
|
|
54
|
-
def
|
|
55
|
-
|
|
39
|
+
def default_phlex_render
|
|
40
|
+
render assign_phlex_accessors(phlex_view(action_name).new)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# @param options [Hash] At a minimum this may contain an `:action` key, which will be used
|
|
44
|
+
# as the name of the view to render. If no `:action` key is provided, the current
|
|
45
|
+
# `action_name` is used.
|
|
46
|
+
def render_plex_view(options)
|
|
47
|
+
options[:action] ||= action_name
|
|
48
|
+
|
|
49
|
+
return unless (view = phlex_view(options[:action]))
|
|
50
|
+
|
|
51
|
+
render assign_phlex_accessors(view.new)
|
|
56
52
|
end
|
|
57
53
|
|
|
58
54
|
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,22 +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
19
|
# Render the Phlex view with the current resource. Falls back to default controller rendering
|
|
18
|
-
# if no Phlex view exists.
|
|
19
|
-
# as
|
|
20
|
+
# if no Phlex view exists. Also passes the current resource to the view, which is then
|
|
21
|
+
# available as `@resource`.
|
|
20
22
|
#
|
|
21
|
-
# @see Phlexible::Rails::ActionController::ImplicitRender#
|
|
23
|
+
# @see Phlexible::Rails::ActionController::ImplicitRender#render_plex_view
|
|
22
24
|
def render_phlex_view(options)
|
|
23
|
-
controller.
|
|
25
|
+
controller.instance_variable_set :@resource, @resource
|
|
26
|
+
controller.render_plex_view(options) || controller.render(options)
|
|
24
27
|
end
|
|
25
28
|
alias render render_phlex_view
|
|
26
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.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: 2023-
|
|
11
|
+
date: 2023-05-11 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: 1.
|
|
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: 1.
|
|
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: 0.
|
|
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: 0.
|
|
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!
|