phlexible 0.7.0 → 1.0.0.beta.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +0 -1
- data/Gemfile.lock +36 -36
- data/README.md +61 -9
- data/fixtures/dummy/app/views/articles/show.rb +7 -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/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 +7 -4
- 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,16 +1,16 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
phlexible (0.
|
4
|
+
phlexible (1.0.0.beta.1)
|
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
|
-
actionpack (7.1.
|
12
|
-
actionview (= 7.1.
|
13
|
-
activesupport (= 7.1.
|
11
|
+
actionpack (7.1.3)
|
12
|
+
actionview (= 7.1.3)
|
13
|
+
activesupport (= 7.1.3)
|
14
14
|
nokogiri (>= 1.8.5)
|
15
15
|
racc
|
16
16
|
rack (>= 2.2.4)
|
@@ -18,13 +18,13 @@ GEM
|
|
18
18
|
rack-test (>= 0.6.3)
|
19
19
|
rails-dom-testing (~> 2.2)
|
20
20
|
rails-html-sanitizer (~> 1.6)
|
21
|
-
actionview (7.1.
|
22
|
-
activesupport (= 7.1.
|
21
|
+
actionview (7.1.3)
|
22
|
+
activesupport (= 7.1.3)
|
23
23
|
builder (~> 3.1)
|
24
24
|
erubi (~> 1.11)
|
25
25
|
rails-dom-testing (~> 2.2)
|
26
26
|
rails-html-sanitizer (~> 1.6)
|
27
|
-
activesupport (7.1.
|
27
|
+
activesupport (7.1.3)
|
28
28
|
base64
|
29
29
|
bigdecimal
|
30
30
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
@@ -36,59 +36,59 @@ GEM
|
|
36
36
|
tzinfo (~> 2.0)
|
37
37
|
ast (2.4.2)
|
38
38
|
base64 (0.2.0)
|
39
|
-
bigdecimal (3.1.
|
39
|
+
bigdecimal (3.1.6)
|
40
40
|
builder (3.2.4)
|
41
|
-
cgi (0.4.
|
42
|
-
combustion (1.
|
41
|
+
cgi (0.4.1)
|
42
|
+
combustion (1.4.0)
|
43
43
|
activesupport (>= 3.0.0)
|
44
44
|
railties (>= 3.0.0)
|
45
45
|
thor (>= 0.14.6)
|
46
|
-
concurrent-ruby (1.2.
|
46
|
+
concurrent-ruby (1.2.3)
|
47
47
|
connection_pool (2.4.1)
|
48
48
|
crass (1.0.6)
|
49
49
|
drb (2.2.0)
|
50
50
|
ruby2_keywords
|
51
|
-
erb (4.0.
|
51
|
+
erb (4.0.4)
|
52
52
|
cgi (>= 0.3.3)
|
53
53
|
erubi (1.12.0)
|
54
54
|
i18n (1.14.1)
|
55
55
|
concurrent-ruby (~> 1.0)
|
56
|
-
io-console (0.
|
57
|
-
irb (1.
|
56
|
+
io-console (0.7.2)
|
57
|
+
irb (1.11.1)
|
58
58
|
rdoc
|
59
|
-
reline (>= 0.
|
60
|
-
json (2.
|
59
|
+
reline (>= 0.4.2)
|
60
|
+
json (2.7.1)
|
61
61
|
language_server-protocol (3.17.0.3)
|
62
62
|
loofah (2.22.0)
|
63
63
|
crass (~> 1.0.2)
|
64
64
|
nokogiri (>= 1.12.0)
|
65
|
-
minitest (5.
|
65
|
+
minitest (5.21.2)
|
66
66
|
mutex_m (0.2.0)
|
67
|
-
nokogiri (1.
|
67
|
+
nokogiri (1.16.0-arm64-darwin)
|
68
68
|
racc (~> 1.4)
|
69
|
-
nokogiri (1.
|
69
|
+
nokogiri (1.16.0-x86_64-darwin)
|
70
70
|
racc (~> 1.4)
|
71
|
-
nokogiri (1.
|
71
|
+
nokogiri (1.16.0-x86_64-linux)
|
72
72
|
racc (~> 1.4)
|
73
|
-
parallel (1.
|
74
|
-
parser (3.
|
73
|
+
parallel (1.24.0)
|
74
|
+
parser (3.3.0.5)
|
75
75
|
ast (~> 2.4.1)
|
76
76
|
racc
|
77
77
|
phlex (1.9.0)
|
78
78
|
concurrent-ruby (~> 1.2)
|
79
79
|
erb (>= 4)
|
80
80
|
zeitwerk (~> 2.6)
|
81
|
-
phlex-rails (1.1.
|
81
|
+
phlex-rails (1.1.1)
|
82
82
|
phlex (~> 1.9)
|
83
83
|
railties (>= 6.1, < 8)
|
84
84
|
zeitwerk (~> 2.6)
|
85
85
|
phlex-testing-nokogiri (0.1.0)
|
86
86
|
nokogiri (~> 1.13)
|
87
87
|
phlex (>= 0.5)
|
88
|
-
psych (5.1.
|
88
|
+
psych (5.1.2)
|
89
89
|
stringio
|
90
90
|
racc (1.7.3)
|
91
|
-
rack (3.0.
|
91
|
+
rack (3.0.9)
|
92
92
|
rack-session (2.0.0)
|
93
93
|
rack (>= 3.0.0)
|
94
94
|
rack-test (2.1.0)
|
@@ -103,9 +103,9 @@ GEM
|
|
103
103
|
rails-html-sanitizer (1.6.0)
|
104
104
|
loofah (~> 2.21)
|
105
105
|
nokogiri (~> 1.14)
|
106
|
-
railties (7.1.
|
107
|
-
actionpack (= 7.1.
|
108
|
-
activesupport (= 7.1.
|
106
|
+
railties (7.1.3)
|
107
|
+
actionpack (= 7.1.3)
|
108
|
+
activesupport (= 7.1.3)
|
109
109
|
irb
|
110
110
|
rackup (>= 1.0.0)
|
111
111
|
rake (>= 12.2)
|
@@ -113,29 +113,29 @@ GEM
|
|
113
113
|
zeitwerk (~> 2.6)
|
114
114
|
rainbow (3.1.1)
|
115
115
|
rake (13.1.0)
|
116
|
-
rdoc (6.6.
|
116
|
+
rdoc (6.6.2)
|
117
117
|
psych (>= 4.0.0)
|
118
|
-
regexp_parser (2.
|
119
|
-
reline (0.4.
|
118
|
+
regexp_parser (2.9.0)
|
119
|
+
reline (0.4.2)
|
120
120
|
io-console (~> 0.5)
|
121
121
|
rexml (3.2.6)
|
122
|
-
rubocop (1.
|
122
|
+
rubocop (1.60.2)
|
123
123
|
json (~> 2.3)
|
124
124
|
language_server-protocol (>= 3.17.0)
|
125
125
|
parallel (~> 1.10)
|
126
|
-
parser (>= 3.
|
126
|
+
parser (>= 3.3.0.2)
|
127
127
|
rainbow (>= 2.2.2, < 4.0)
|
128
128
|
regexp_parser (>= 1.8, < 3.0)
|
129
129
|
rexml (>= 3.2.5, < 4.0)
|
130
|
-
rubocop-ast (>= 1.
|
130
|
+
rubocop-ast (>= 1.30.0, < 2.0)
|
131
131
|
ruby-progressbar (~> 1.7)
|
132
132
|
unicode-display_width (>= 2.4.0, < 3.0)
|
133
133
|
rubocop-ast (1.30.0)
|
134
134
|
parser (>= 3.2.1.0)
|
135
135
|
ruby-progressbar (1.13.0)
|
136
136
|
ruby2_keywords (0.0.5)
|
137
|
-
stringio (3.0
|
138
|
-
sus (0.
|
137
|
+
stringio (3.1.0)
|
138
|
+
sus (0.24.5)
|
139
139
|
thor (1.3.0)
|
140
140
|
tzinfo (2.0.6)
|
141
141
|
concurrent-ruby (~> 1.0)
|
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
|
|
@@ -138,7 +158,39 @@ Phlexible::Rails::ButtonTo.new(:root, method: :patch) { 'My Button' }
|
|
138
158
|
- `:form_attributes` - Hash of HTML attributes for the form tag.
|
139
159
|
- `:data` - This option can be used to add custom data attributes.
|
140
160
|
- `: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,
|
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
|
|
@@ -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
|
@@ -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,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: 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
|
@@ -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
|