view_component 2.31.0 → 2.35.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of view_component might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/app/assets/vendor/prism.css +196 -0
- data/app/assets/vendor/prism.min.js +12 -0
- data/app/helpers/preview_helper.rb +19 -0
- data/app/views/test_mailer/test_email.html.erb +1 -0
- data/app/views/view_components/_preview_source.html.erb +17 -0
- data/app/views/view_components/preview.html.erb +6 -2
- data/{CHANGELOG.md → docs/CHANGELOG.md} +131 -1
- data/lib/rails/generators/abstract_generator.rb +29 -0
- data/lib/rails/generators/component/component_generator.rb +5 -5
- data/lib/rails/generators/erb/component_generator.rb +7 -16
- data/lib/rails/generators/haml/component_generator.rb +6 -16
- data/lib/rails/generators/slim/component_generator.rb +6 -16
- data/lib/view_component.rb +2 -0
- data/lib/view_component/base.rb +142 -74
- data/lib/view_component/collection.rb +3 -1
- data/lib/view_component/compile_cache.rb +1 -0
- data/lib/view_component/compiler.rb +58 -54
- data/lib/view_component/content_areas.rb +50 -0
- data/lib/view_component/engine.rb +19 -2
- data/lib/view_component/instrumentation.rb +17 -0
- data/lib/view_component/preview.rb +14 -7
- data/lib/view_component/previewable.rb +16 -18
- data/lib/view_component/slot_v2.rb +28 -27
- data/lib/view_component/slotable.rb +2 -1
- data/lib/view_component/slotable_v2.rb +23 -22
- data/lib/view_component/test_helpers.rb +6 -1
- data/lib/view_component/translatable.rb +6 -5
- data/lib/view_component/version.rb +1 -1
- data/lib/view_component/with_content_helper.rb +1 -1
- data/lib/yard/mattr_accessor_handler.rb +19 -0
- metadata +94 -43
@@ -123,6 +123,7 @@ module ViewComponent
|
|
123
123
|
slot_instance = args.present? ? slot_class.new(**args) : slot_class.new
|
124
124
|
|
125
125
|
# Capture block and assign to slot_instance#content
|
126
|
+
# rubocop:disable Rails/OutputSafety
|
126
127
|
slot_instance.content = view_context.capture(&block).to_s.strip.html_safe if block_given?
|
127
128
|
|
128
129
|
if slot[:collection]
|
@@ -135,7 +136,7 @@ module ViewComponent
|
|
135
136
|
# Append Slot instance to collection accessor Array
|
136
137
|
instance_variable_get(slot[:instance_variable_name]) << slot_instance
|
137
138
|
else
|
138
|
-
|
139
|
+
# Assign the Slot instance to the slot accessor
|
139
140
|
instance_variable_set(slot[:instance_variable_name], slot_instance)
|
140
141
|
end
|
141
142
|
|
@@ -60,7 +60,7 @@ module ViewComponent
|
|
60
60
|
# helper method with the same name as the slot.
|
61
61
|
#
|
62
62
|
# <%= render_inline(MyComponent.new) do |component| %>
|
63
|
-
#
|
63
|
+
# <% component.header(classes: "Foo") do %>
|
64
64
|
# <p>Bar</p>
|
65
65
|
# <% end %>
|
66
66
|
# <% end %>
|
@@ -95,7 +95,7 @@ module ViewComponent
|
|
95
95
|
# helper method with the same name as the slot.
|
96
96
|
#
|
97
97
|
# <h1>
|
98
|
-
#
|
98
|
+
# <% items.each do |item| %>
|
99
99
|
# <%= item %>
|
100
100
|
# <% end %>
|
101
101
|
# </h1>
|
@@ -107,11 +107,11 @@ module ViewComponent
|
|
107
107
|
# called multiple times to append to the slot.
|
108
108
|
#
|
109
109
|
# <%= render_inline(MyComponent.new) do |component| %>
|
110
|
-
#
|
110
|
+
# <% component.item(name: "Foo") do %>
|
111
111
|
# <p>One</p>
|
112
112
|
# <% end %>
|
113
113
|
#
|
114
|
-
#
|
114
|
+
# <% component.item(name: "Bar") do %>
|
115
115
|
# <p>two</p>
|
116
116
|
# <% end %>
|
117
117
|
# <% end %>
|
@@ -190,10 +190,10 @@ module ViewComponent
|
|
190
190
|
content unless content_evaluated? # ensure content is loaded so slots will be defined
|
191
191
|
|
192
192
|
slot = self.class.registered_slots[slot_name]
|
193
|
-
@
|
193
|
+
@__vc_set_slots ||= {}
|
194
194
|
|
195
|
-
if @
|
196
|
-
return @
|
195
|
+
if @__vc_set_slots[slot_name]
|
196
|
+
return @__vc_set_slots[slot_name]
|
197
197
|
end
|
198
198
|
|
199
199
|
if slot[:collection]
|
@@ -217,42 +217,43 @@ module ViewComponent
|
|
217
217
|
# 2. Since we have to pass block content to components when calling
|
218
218
|
# `render`, evaluating the block here would require us to call
|
219
219
|
# `view_context.capture` twice, which is slower
|
220
|
-
slot.
|
220
|
+
slot.__vc_content_block = block if block_given?
|
221
221
|
|
222
222
|
# If class
|
223
223
|
if slot_definition[:renderable]
|
224
|
-
slot.
|
224
|
+
slot.__vc_component_instance = slot_definition[:renderable].new(*args, **kwargs)
|
225
225
|
# If class name as a string
|
226
226
|
elsif slot_definition[:renderable_class_name]
|
227
|
-
slot.
|
227
|
+
slot.__vc_component_instance = self.class.const_get(slot_definition[:renderable_class_name]).new(*args, **kwargs)
|
228
228
|
# If passed a lambda
|
229
229
|
elsif slot_definition[:renderable_function]
|
230
230
|
# Use `bind(self)` to ensure lambda is executed in the context of the
|
231
231
|
# current component. This is necessary to allow the lambda to access helper
|
232
232
|
# methods like `content_tag` as well as parent component state.
|
233
|
-
renderable_value =
|
234
|
-
|
235
|
-
|
233
|
+
renderable_value =
|
234
|
+
if block_given?
|
235
|
+
slot_definition[:renderable_function].bind(self).call(*args, **kwargs) do |*args, **kwargs|
|
236
|
+
view_context.capture(*args, **kwargs, &block)
|
237
|
+
end
|
238
|
+
else
|
239
|
+
slot_definition[:renderable_function].bind(self).call(*args, **kwargs)
|
236
240
|
end
|
237
|
-
else
|
238
|
-
slot_definition[:renderable_function].bind(self).call(*args, **kwargs)
|
239
|
-
end
|
240
241
|
|
241
242
|
# Function calls can return components, so if it's a component handle it specially
|
242
243
|
if renderable_value.respond_to?(:render_in)
|
243
|
-
slot.
|
244
|
+
slot.__vc_component_instance = renderable_value
|
244
245
|
else
|
245
|
-
slot.
|
246
|
+
slot.__vc_content = renderable_value
|
246
247
|
end
|
247
248
|
end
|
248
249
|
|
249
|
-
@
|
250
|
+
@__vc_set_slots ||= {}
|
250
251
|
|
251
252
|
if slot_definition[:collection]
|
252
|
-
@
|
253
|
-
@
|
253
|
+
@__vc_set_slots[slot_name] ||= []
|
254
|
+
@__vc_set_slots[slot_name].push(slot)
|
254
255
|
else
|
255
|
-
@
|
256
|
+
@__vc_set_slots[slot_name] = slot
|
256
257
|
end
|
257
258
|
|
258
259
|
slot
|
@@ -39,7 +39,12 @@ module ViewComponent
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def request
|
42
|
-
@request ||=
|
42
|
+
@request ||=
|
43
|
+
begin
|
44
|
+
request = ActionDispatch::TestRequest.create
|
45
|
+
request.session = ActionController::TestSession.new
|
46
|
+
request
|
47
|
+
end
|
43
48
|
end
|
44
49
|
|
45
50
|
def with_variant(variant)
|
@@ -52,7 +52,7 @@ module ViewComponent
|
|
52
52
|
|
53
53
|
def scope_data(data)
|
54
54
|
@i18n_scope.reverse_each do |part|
|
55
|
-
data = { part => data}
|
55
|
+
data = { part => data }
|
56
56
|
end
|
57
57
|
data
|
58
58
|
end
|
@@ -70,9 +70,10 @@ module ViewComponent
|
|
70
70
|
key = key&.to_s unless key.is_a?(String)
|
71
71
|
key = "#{i18n_scope}#{key}" if key.start_with?(".")
|
72
72
|
|
73
|
-
translated =
|
74
|
-
|
75
|
-
|
73
|
+
translated =
|
74
|
+
catch(:exception) do
|
75
|
+
i18n_backend.translate(locale, key, options)
|
76
|
+
end
|
76
77
|
|
77
78
|
# Fallback to the global translations
|
78
79
|
if translated.is_a? ::I18n::MissingTranslation
|
@@ -80,7 +81,7 @@ module ViewComponent
|
|
80
81
|
end
|
81
82
|
|
82
83
|
if HTML_SAFE_TRANSLATION_KEY.match?(key)
|
83
|
-
translated = translated.html_safe
|
84
|
+
translated = translated.html_safe # rubocop:disable Rails/OutputSafety
|
84
85
|
end
|
85
86
|
|
86
87
|
translated
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module YARD
|
4
|
+
# YARD Handler to parse `mattr_accessor` calls.
|
5
|
+
class MattrAccessorHandler < YARD::Handlers::Ruby::Base
|
6
|
+
handles method_call(:mattr_accessor)
|
7
|
+
namespace_only
|
8
|
+
|
9
|
+
process do
|
10
|
+
name = statement.parameters.first.jump(:tstring_content, :ident).source
|
11
|
+
object = YARD::CodeObjects::MethodObject.new(namespace, name)
|
12
|
+
register(object)
|
13
|
+
parse_block(statement.last, owner: object)
|
14
|
+
|
15
|
+
object.dynamic = true
|
16
|
+
object[:mattr_accessor] = true
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: view_component
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.35.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GitHub Open Source
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-07-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -19,7 +19,7 @@ dependencies:
|
|
19
19
|
version: 5.0.0
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '
|
22
|
+
version: '8.0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -29,7 +29,21 @@ dependencies:
|
|
29
29
|
version: 5.0.0
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '
|
32
|
+
version: '8.0'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: method_source
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '1.0'
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '1.0'
|
33
47
|
- !ruby/object:Gem::Dependency
|
34
48
|
name: benchmark-ips
|
35
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -45,47 +59,47 @@ dependencies:
|
|
45
59
|
- !ruby/object:Gem::Version
|
46
60
|
version: 2.8.2
|
47
61
|
- !ruby/object:Gem::Dependency
|
48
|
-
name:
|
62
|
+
name: better_html
|
49
63
|
requirement: !ruby/object:Gem::Requirement
|
50
64
|
requirements:
|
51
65
|
- - "~>"
|
52
66
|
- !ruby/object:Gem::Version
|
53
|
-
version: '1
|
67
|
+
version: '1'
|
54
68
|
type: :development
|
55
69
|
prerelease: false
|
56
70
|
version_requirements: !ruby/object:Gem::Requirement
|
57
71
|
requirements:
|
58
72
|
- - "~>"
|
59
73
|
- !ruby/object:Gem::Version
|
60
|
-
version: '1
|
74
|
+
version: '1'
|
61
75
|
- !ruby/object:Gem::Dependency
|
62
|
-
name:
|
76
|
+
name: bundler
|
63
77
|
requirement: !ruby/object:Gem::Requirement
|
64
78
|
requirements:
|
65
79
|
- - "~>"
|
66
80
|
- !ruby/object:Gem::Version
|
67
|
-
version: '
|
81
|
+
version: '2.2'
|
68
82
|
type: :development
|
69
83
|
prerelease: false
|
70
84
|
version_requirements: !ruby/object:Gem::Requirement
|
71
85
|
requirements:
|
72
86
|
- - "~>"
|
73
87
|
- !ruby/object:Gem::Version
|
74
|
-
version: '
|
88
|
+
version: '2.2'
|
75
89
|
- !ruby/object:Gem::Dependency
|
76
|
-
name:
|
90
|
+
name: erb_lint
|
77
91
|
requirement: !ruby/object:Gem::Requirement
|
78
92
|
requirements:
|
79
|
-
- -
|
93
|
+
- - "~>"
|
80
94
|
- !ruby/object:Gem::Version
|
81
|
-
version:
|
95
|
+
version: 0.0.37
|
82
96
|
type: :development
|
83
97
|
prerelease: false
|
84
98
|
version_requirements: !ruby/object:Gem::Requirement
|
85
99
|
requirements:
|
86
|
-
- -
|
100
|
+
- - "~>"
|
87
101
|
- !ruby/object:Gem::Version
|
88
|
-
version:
|
102
|
+
version: 0.0.37
|
89
103
|
- !ruby/object:Gem::Dependency
|
90
104
|
name: haml
|
91
105
|
requirement: !ruby/object:Gem::Requirement
|
@@ -101,75 +115,75 @@ dependencies:
|
|
101
115
|
- !ruby/object:Gem::Version
|
102
116
|
version: '5'
|
103
117
|
- !ruby/object:Gem::Dependency
|
104
|
-
name:
|
118
|
+
name: jbuilder
|
105
119
|
requirement: !ruby/object:Gem::Requirement
|
106
120
|
requirements:
|
107
121
|
- - "~>"
|
108
122
|
- !ruby/object:Gem::Version
|
109
|
-
version: '
|
123
|
+
version: '2'
|
110
124
|
type: :development
|
111
125
|
prerelease: false
|
112
126
|
version_requirements: !ruby/object:Gem::Requirement
|
113
127
|
requirements:
|
114
128
|
- - "~>"
|
115
129
|
- !ruby/object:Gem::Version
|
116
|
-
version: '
|
130
|
+
version: '2'
|
117
131
|
- !ruby/object:Gem::Dependency
|
118
|
-
name:
|
132
|
+
name: minitest
|
119
133
|
requirement: !ruby/object:Gem::Requirement
|
120
134
|
requirements:
|
121
|
-
- -
|
135
|
+
- - '='
|
122
136
|
- !ruby/object:Gem::Version
|
123
|
-
version:
|
137
|
+
version: 5.6.0
|
124
138
|
type: :development
|
125
139
|
prerelease: false
|
126
140
|
version_requirements: !ruby/object:Gem::Requirement
|
127
141
|
requirements:
|
128
|
-
- -
|
142
|
+
- - '='
|
129
143
|
- !ruby/object:Gem::Version
|
130
|
-
version:
|
144
|
+
version: 5.6.0
|
131
145
|
- !ruby/object:Gem::Dependency
|
132
|
-
name:
|
146
|
+
name: pry
|
133
147
|
requirement: !ruby/object:Gem::Requirement
|
134
148
|
requirements:
|
135
149
|
- - "~>"
|
136
150
|
- !ruby/object:Gem::Version
|
137
|
-
version: '
|
151
|
+
version: '0.13'
|
138
152
|
type: :development
|
139
153
|
prerelease: false
|
140
154
|
version_requirements: !ruby/object:Gem::Requirement
|
141
155
|
requirements:
|
142
156
|
- - "~>"
|
143
157
|
- !ruby/object:Gem::Version
|
144
|
-
version: '
|
158
|
+
version: '0.13'
|
145
159
|
- !ruby/object:Gem::Dependency
|
146
|
-
name:
|
160
|
+
name: rake
|
147
161
|
requirement: !ruby/object:Gem::Requirement
|
148
162
|
requirements:
|
149
|
-
- -
|
163
|
+
- - "~>"
|
150
164
|
- !ruby/object:Gem::Version
|
151
|
-
version: '0
|
165
|
+
version: '13.0'
|
152
166
|
type: :development
|
153
167
|
prerelease: false
|
154
168
|
version_requirements: !ruby/object:Gem::Requirement
|
155
169
|
requirements:
|
156
|
-
- -
|
170
|
+
- - "~>"
|
157
171
|
- !ruby/object:Gem::Version
|
158
|
-
version: '0
|
172
|
+
version: '13.0'
|
159
173
|
- !ruby/object:Gem::Dependency
|
160
174
|
name: rubocop-github
|
161
175
|
requirement: !ruby/object:Gem::Requirement
|
162
176
|
requirements:
|
163
177
|
- - "~>"
|
164
178
|
- !ruby/object:Gem::Version
|
165
|
-
version: 0.
|
179
|
+
version: 0.16.1
|
166
180
|
type: :development
|
167
181
|
prerelease: false
|
168
182
|
version_requirements: !ruby/object:Gem::Requirement
|
169
183
|
requirements:
|
170
184
|
- - "~>"
|
171
185
|
- !ruby/object:Gem::Version
|
172
|
-
version: 0.
|
186
|
+
version: 0.16.1
|
173
187
|
- !ruby/object:Gem::Dependency
|
174
188
|
name: simplecov
|
175
189
|
requirement: !ruby/object:Gem::Requirement
|
@@ -199,33 +213,67 @@ dependencies:
|
|
199
213
|
- !ruby/object:Gem::Version
|
200
214
|
version: 0.7.2
|
201
215
|
- !ruby/object:Gem::Dependency
|
202
|
-
name:
|
216
|
+
name: slim
|
203
217
|
requirement: !ruby/object:Gem::Requirement
|
204
218
|
requirements:
|
205
219
|
- - "~>"
|
206
220
|
- !ruby/object:Gem::Version
|
207
|
-
version: '0
|
221
|
+
version: '4.0'
|
208
222
|
type: :development
|
209
223
|
prerelease: false
|
210
224
|
version_requirements: !ruby/object:Gem::Requirement
|
211
225
|
requirements:
|
212
226
|
- - "~>"
|
213
227
|
- !ruby/object:Gem::Version
|
214
|
-
version: '0
|
215
|
-
|
228
|
+
version: '4.0'
|
229
|
+
- !ruby/object:Gem::Dependency
|
230
|
+
name: yard
|
231
|
+
requirement: !ruby/object:Gem::Requirement
|
232
|
+
requirements:
|
233
|
+
- - "~>"
|
234
|
+
- !ruby/object:Gem::Version
|
235
|
+
version: 0.9.25
|
236
|
+
type: :development
|
237
|
+
prerelease: false
|
238
|
+
version_requirements: !ruby/object:Gem::Requirement
|
239
|
+
requirements:
|
240
|
+
- - "~>"
|
241
|
+
- !ruby/object:Gem::Version
|
242
|
+
version: 0.9.25
|
243
|
+
- !ruby/object:Gem::Dependency
|
244
|
+
name: yard-activesupport-concern
|
245
|
+
requirement: !ruby/object:Gem::Requirement
|
246
|
+
requirements:
|
247
|
+
- - ">="
|
248
|
+
- !ruby/object:Gem::Version
|
249
|
+
version: '0'
|
250
|
+
type: :development
|
251
|
+
prerelease: false
|
252
|
+
version_requirements: !ruby/object:Gem::Requirement
|
253
|
+
requirements:
|
254
|
+
- - ">="
|
255
|
+
- !ruby/object:Gem::Version
|
256
|
+
version: '0'
|
257
|
+
description:
|
216
258
|
email:
|
217
259
|
- opensource+view_component@github.com
|
218
260
|
executables: []
|
219
261
|
extensions: []
|
220
262
|
extra_rdoc_files: []
|
221
263
|
files:
|
222
|
-
- CHANGELOG.md
|
223
264
|
- LICENSE.txt
|
224
265
|
- README.md
|
266
|
+
- app/assets/vendor/prism.css
|
267
|
+
- app/assets/vendor/prism.min.js
|
225
268
|
- app/controllers/view_components_controller.rb
|
269
|
+
- app/helpers/preview_helper.rb
|
270
|
+
- app/views/test_mailer/test_email.html.erb
|
271
|
+
- app/views/view_components/_preview_source.html.erb
|
226
272
|
- app/views/view_components/index.html.erb
|
227
273
|
- app/views/view_components/preview.html.erb
|
228
274
|
- app/views/view_components/previews.html.erb
|
275
|
+
- docs/CHANGELOG.md
|
276
|
+
- lib/rails/generators/abstract_generator.rb
|
229
277
|
- lib/rails/generators/component/USAGE
|
230
278
|
- lib/rails/generators/component/component_generator.rb
|
231
279
|
- lib/rails/generators/component/templates/component.rb.tt
|
@@ -247,7 +295,9 @@ files:
|
|
247
295
|
- lib/view_component/compile_cache.rb
|
248
296
|
- lib/view_component/compiler.rb
|
249
297
|
- lib/view_component/component_error.rb
|
298
|
+
- lib/view_component/content_areas.rb
|
250
299
|
- lib/view_component/engine.rb
|
300
|
+
- lib/view_component/instrumentation.rb
|
251
301
|
- lib/view_component/preview.rb
|
252
302
|
- lib/view_component/preview_template_error.rb
|
253
303
|
- lib/view_component/previewable.rb
|
@@ -267,12 +317,13 @@ files:
|
|
267
317
|
- lib/view_component/translatable.rb
|
268
318
|
- lib/view_component/version.rb
|
269
319
|
- lib/view_component/with_content_helper.rb
|
320
|
+
- lib/yard/mattr_accessor_handler.rb
|
270
321
|
homepage: https://github.com/github/view_component
|
271
322
|
licenses:
|
272
323
|
- MIT
|
273
324
|
metadata:
|
274
325
|
allowed_push_host: https://rubygems.org
|
275
|
-
post_install_message:
|
326
|
+
post_install_message:
|
276
327
|
rdoc_options: []
|
277
328
|
require_paths:
|
278
329
|
- lib
|
@@ -280,15 +331,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
280
331
|
requirements:
|
281
332
|
- - ">="
|
282
333
|
- !ruby/object:Gem::Version
|
283
|
-
version: 2.
|
334
|
+
version: 2.4.0
|
284
335
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
285
336
|
requirements:
|
286
337
|
- - ">="
|
287
338
|
- !ruby/object:Gem::Version
|
288
339
|
version: '0'
|
289
340
|
requirements: []
|
290
|
-
rubygems_version: 3.1.
|
291
|
-
signing_key:
|
341
|
+
rubygems_version: 3.1.4
|
342
|
+
signing_key:
|
292
343
|
specification_version: 4
|
293
344
|
summary: View components for Rails
|
294
345
|
test_files: []
|