view_component 2.82.0 → 3.1.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.

Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/concerns/view_component/preview_actions.rb +4 -0
  3. data/app/controllers/view_components_system_test_controller.rb +24 -1
  4. data/app/helpers/preview_helper.rb +2 -4
  5. data/docs/CHANGELOG.md +320 -0
  6. data/lib/view_component/base.rb +50 -96
  7. data/lib/view_component/capture_compatibility.rb +44 -0
  8. data/lib/view_component/collection.rb +2 -5
  9. data/lib/view_component/compiler.rb +51 -28
  10. data/lib/view_component/config.rb +9 -13
  11. data/lib/view_component/deprecation.rb +1 -1
  12. data/lib/view_component/docs_builder_component.html.erb +5 -1
  13. data/lib/view_component/docs_builder_component.rb +28 -9
  14. data/lib/view_component/engine.rb +12 -22
  15. data/lib/view_component/errors.rb +223 -0
  16. data/lib/view_component/inline_template.rb +55 -0
  17. data/lib/view_component/preview.rb +1 -7
  18. data/lib/view_component/rails/tasks/view_component.rake +1 -1
  19. data/lib/view_component/slot.rb +109 -1
  20. data/lib/view_component/slotable.rb +364 -96
  21. data/lib/view_component/system_test_helpers.rb +5 -5
  22. data/lib/view_component/test_helpers.rb +67 -54
  23. data/lib/view_component/translatable.rb +35 -23
  24. data/lib/view_component/version.rb +4 -3
  25. data/lib/view_component/with_content_helper.rb +3 -8
  26. data/lib/view_component.rb +3 -12
  27. metadata +45 -34
  28. data/lib/view_component/content_areas.rb +0 -56
  29. data/lib/view_component/polymorphic_slots.rb +0 -103
  30. data/lib/view_component/preview_template_error.rb +0 -6
  31. data/lib/view_component/slot_v2.rb +0 -98
  32. data/lib/view_component/slotable_v2.rb +0 -391
  33. data/lib/view_component/template_error.rb +0 -9
@@ -28,17 +28,10 @@ module ViewComponent
28
28
  # :nocov:
29
29
  end
30
30
 
31
- # @private
32
- attr_reader :rendered_content
33
-
34
31
  # Returns the result of a render_inline call.
35
32
  #
36
- # @return [String]
37
- def rendered_component
38
- ViewComponent::Deprecation.deprecation_warning("`rendered_component`", :"`page`")
39
-
40
- rendered_content
41
- end
33
+ # @return [ActionView::OutputBuffer]
34
+ attr_reader :rendered_content
42
35
 
43
36
  # Render a component inline. Internally sets `page` to be a `Capybara::Node::Simple`,
44
37
  # allowing for Capybara assertions to be used:
@@ -54,9 +47,9 @@ module ViewComponent
54
47
  @page = nil
55
48
  @rendered_content =
56
49
  if Rails.version.to_f >= 6.1
57
- controller.view_context.render(component, args, &block)
50
+ vc_test_controller.view_context.render(component, args, &block)
58
51
  else
59
- controller.view_context.render_component(component, &block)
52
+ vc_test_controller.view_context.render_component(component, &block)
60
53
  end
61
54
 
62
55
  Nokogiri::HTML.fragment(@rendered_content)
@@ -81,8 +74,8 @@ module ViewComponent
81
74
  # @param from [ViewComponent::Preview] The class of the preview to be rendered.
82
75
  # @param params [Hash] Parameters to be passed to the preview.
83
76
  # @return [Nokogiri::HTML]
84
- def render_preview(name, from: preview_class, params: {})
85
- previews_controller = build_controller(Rails.application.config.view_component.preview_controller.constantize)
77
+ def render_preview(name, from: __vc_test_helpers_preview_class, params: {})
78
+ previews_controller = __vc_test_helpers_build_controller(Rails.application.config.view_component.preview_controller.constantize)
86
79
 
87
80
  # From what I can tell, it's not possible to overwrite all request parameters
88
81
  # at once, so we set them individually here.
@@ -104,7 +97,7 @@ module ViewComponent
104
97
  # Capybara assertions to be used. All arguments are forwarded to the block.
105
98
  #
106
99
  # ```ruby
107
- # render_in_view_context(arg1, arg2:) do |arg1, arg2:|
100
+ # render_in_view_context(arg1, arg2: nil) do |arg1, arg2:|
108
101
  # render(MyComponent.new(arg1, arg2))
109
102
  # end
110
103
  #
@@ -112,26 +105,11 @@ module ViewComponent
112
105
  # ```
113
106
  def render_in_view_context(*args, &block)
114
107
  @page = nil
115
- @rendered_content = controller.view_context.instance_exec(*args, &block)
108
+ @rendered_content = vc_test_controller.view_context.instance_exec(*args, &block)
116
109
  Nokogiri::HTML.fragment(@rendered_content)
117
110
  end
118
111
  ruby2_keywords(:render_in_view_context) if respond_to?(:ruby2_keywords, true)
119
112
 
120
- # @private
121
- def controller
122
- @controller ||= build_controller(Base.test_controller.constantize)
123
- end
124
-
125
- # @private
126
- def request
127
- @request ||=
128
- begin
129
- request = ActionDispatch::TestRequest.create
130
- request.session = ActionController::TestSession.new
131
- request
132
- end
133
- end
134
-
135
113
  # Set the Action Pack request variant for the given block:
136
114
  #
137
115
  # ```ruby
@@ -142,12 +120,12 @@ module ViewComponent
142
120
  #
143
121
  # @param variant [Symbol] The variant to be set for the provided block.
144
122
  def with_variant(variant)
145
- old_variants = controller.view_context.lookup_context.variants
123
+ old_variants = vc_test_controller.view_context.lookup_context.variants
146
124
 
147
- controller.view_context.lookup_context.variants = variant
125
+ vc_test_controller.view_context.lookup_context.variants = variant
148
126
  yield
149
127
  ensure
150
- controller.view_context.lookup_context.variants = old_variants
128
+ vc_test_controller.view_context.lookup_context.variants = old_variants
151
129
  end
152
130
 
153
131
  # Set the controller to be used while executing the given block,
@@ -161,12 +139,12 @@ module ViewComponent
161
139
  #
162
140
  # @param klass [ActionController::Base] The controller to be used.
163
141
  def with_controller_class(klass)
164
- old_controller = defined?(@controller) && @controller
142
+ old_controller = defined?(@vc_test_controller) && @vc_test_controller
165
143
 
166
- @controller = build_controller(klass)
144
+ @vc_test_controller = __vc_test_helpers_build_controller(klass)
167
145
  yield
168
146
  ensure
169
- @controller = old_controller
147
+ @vc_test_controller = old_controller
170
148
  end
171
149
 
172
150
  # Set the URL of the current request (such as when using request-dependent path helpers):
@@ -179,34 +157,69 @@ module ViewComponent
179
157
  #
180
158
  # @param path [String] The path to set for the current request.
181
159
  def with_request_url(path)
182
- old_request_path_info = request.path_info
183
- old_request_path_parameters = request.path_parameters
184
- old_request_query_parameters = request.query_parameters
185
- old_request_query_string = request.query_string
186
- old_controller = defined?(@controller) && @controller
160
+ old_request_path_info = vc_test_request.path_info
161
+ old_request_path_parameters = vc_test_request.path_parameters
162
+ old_request_query_parameters = vc_test_request.query_parameters
163
+ old_request_query_string = vc_test_request.query_string
164
+ old_controller = defined?(@vc_test_controller) && @vc_test_controller
187
165
 
188
166
  path, query = path.split("?", 2)
189
- request.path_info = path
190
- request.path_parameters = Rails.application.routes.recognize_path_with_request(request, path, {})
191
- request.set_header("action_dispatch.request.query_parameters", Rack::Utils.parse_nested_query(query))
192
- request.set_header(Rack::QUERY_STRING, query)
167
+ vc_test_request.path_info = path
168
+ vc_test_request.path_parameters = Rails.application.routes.recognize_path_with_request(vc_test_request, path, {})
169
+ vc_test_request.set_header("action_dispatch.request.query_parameters", Rack::Utils.parse_nested_query(query))
170
+ vc_test_request.set_header(Rack::QUERY_STRING, query)
193
171
  yield
194
172
  ensure
195
- request.path_info = old_request_path_info
196
- request.path_parameters = old_request_path_parameters
197
- request.set_header("action_dispatch.request.query_parameters", old_request_query_parameters)
198
- request.set_header(Rack::QUERY_STRING, old_request_query_string)
199
- @controller = old_controller
173
+ vc_test_request.path_info = old_request_path_info
174
+ vc_test_request.path_parameters = old_request_path_parameters
175
+ vc_test_request.set_header("action_dispatch.request.query_parameters", old_request_query_parameters)
176
+ vc_test_request.set_header(Rack::QUERY_STRING, old_request_query_string)
177
+ @vc_test_controller = old_controller
200
178
  end
201
179
 
202
- # @private
203
- def build_controller(klass)
204
- klass.new.tap { |c| c.request = request }.extend(Rails.application.routes.url_helpers)
180
+ # Access the controller used by `render_inline`:
181
+ #
182
+ # ```ruby
183
+ # test "logged out user sees login link" do
184
+ # vc_test_controller.expects(:logged_in?).at_least_once.returns(false)
185
+ # render_inline(LoginComponent.new)
186
+ # assert_selector("[aria-label='You must be signed in']")
187
+ # end
188
+ # ```
189
+ #
190
+ # @return [ActionController::Base]
191
+ def vc_test_controller
192
+ @vc_test_controller ||= __vc_test_helpers_build_controller(Base.test_controller.constantize)
205
193
  end
206
194
 
195
+ # Access the request used by `render_inline`:
196
+ #
197
+ # ```ruby
198
+ # test "component does not render in Firefox" do
199
+ # request.env["HTTP_USER_AGENT"] = "Mozilla/5.0"
200
+ # render_inline(NoFirefoxComponent.new)
201
+ # refute_component_rendered
202
+ # end
203
+ # ```
204
+ #
205
+ # @return [ActionDispatch::TestRequest]
206
+ def vc_test_request
207
+ @vc_test_request ||=
208
+ begin
209
+ out = ActionDispatch::TestRequest.create
210
+ out.session = ActionController::TestSession.new
211
+ out
212
+ end
213
+ end
214
+
215
+ # Note: We prefix private methods here to prevent collisions in consumer's tests.
207
216
  private
208
217
 
209
- def preview_class
218
+ def __vc_test_helpers_build_controller(klass)
219
+ klass.new.tap { |c| c.request = vc_test_request }.extend(Rails.application.routes.url_helpers)
220
+ end
221
+
222
+ def __vc_test_helpers_preview_class
210
223
  result = if respond_to?(:described_class)
211
224
  raise "`render_preview` expected a described_class, but it is nil." if described_class.nil?
212
225
 
@@ -21,7 +21,7 @@ module ViewComponent
21
21
  end
22
22
 
23
23
  def build_i18n_backend
24
- return if CompileCache.compiled? self
24
+ return if compiled?
25
25
 
26
26
  self.i18n_backend = if (translation_files = sidecar_files(%w[yml yaml])).any?
27
27
  # Returning nil cleans up if translations file has been removed since the last compilation
@@ -32,6 +32,27 @@ module ViewComponent
32
32
  )
33
33
  end
34
34
  end
35
+
36
+ def i18n_key(key, scope = nil)
37
+ scope = scope.join(".") if scope.is_a? Array
38
+ key = key&.to_s unless key.is_a?(String)
39
+ key = "#{scope}.#{key}" if scope
40
+ key = "#{i18n_scope}#{key}" if key.start_with?(".")
41
+ key
42
+ end
43
+
44
+ def translate(key = nil, **options)
45
+ return key.map { |k| translate(k, **options) } if key.is_a?(Array)
46
+
47
+ ensure_compiled
48
+
49
+ locale = options.delete(:locale) || ::I18n.locale
50
+ key = i18n_key(key, options.delete(:scope))
51
+
52
+ i18n_backend.translate(locale, key, options)
53
+ end
54
+
55
+ alias_method :t, :translate
35
56
  end
36
57
 
37
58
  class I18nBackend < ::I18n::Backend::Simple
@@ -60,19 +81,16 @@ module ViewComponent
60
81
  end
61
82
 
62
83
  def translate(key = nil, **options)
84
+ raise ViewComponent::TranslateCalledBeforeRenderError if view_context.nil?
85
+
63
86
  return super unless i18n_backend
64
87
  return key.map { |k| translate(k, **options) } if key.is_a?(Array)
65
88
 
66
89
  locale = options.delete(:locale) || ::I18n.locale
67
- scope = options.delete(:scope)
68
- scope = scope.join(".") if scope.is_a? Array
69
- key = key&.to_s unless key.is_a?(String)
70
- key = "#{scope}.#{key}" if scope
71
- key = "#{i18n_scope}#{key}" if key.start_with?(".")
72
-
73
- if HTML_SAFE_TRANSLATION_KEY.match?(key)
74
- html_escape_translation_options!(options)
75
- end
90
+ key = self.class.i18n_key(key, options.delete(:scope))
91
+ as_html = HTML_SAFE_TRANSLATION_KEY.match?(key)
92
+
93
+ html_escape_translation_options!(options) if as_html
76
94
 
77
95
  if key.start_with?(i18n_scope + ".")
78
96
  translated =
@@ -85,10 +103,7 @@ module ViewComponent
85
103
  return super(key, locale: locale, **options)
86
104
  end
87
105
 
88
- if HTML_SAFE_TRANSLATION_KEY.match?(key)
89
- translated = html_safe_translation(translated)
90
- end
91
-
106
+ translated = html_safe_translation(translated) if as_html
92
107
  translated
93
108
  else
94
109
  super(key, locale: locale, **options)
@@ -101,6 +116,8 @@ module ViewComponent
101
116
  self.class.i18n_scope
102
117
  end
103
118
 
119
+ private
120
+
104
121
  def html_safe_translation(translation)
105
122
  if translation.respond_to?(:map)
106
123
  translation.map { |element| html_safe_translation(element) }
@@ -112,18 +129,13 @@ module ViewComponent
112
129
  end
113
130
  end
114
131
 
115
- private
116
-
117
132
  def html_escape_translation_options!(options)
118
133
  options.each do |name, value|
119
- unless i18n_option?(name) || (name == :count && value.is_a?(Numeric))
120
- options[name] = ERB::Util.html_escape(value.to_s)
121
- end
122
- end
123
- end
134
+ next if ::I18n.reserved_keys_pattern.match?(name)
135
+ next if name == :count && value.is_a?(Numeric)
124
136
 
125
- def i18n_option?(name)
126
- (@i18n_option_names ||= I18n::RESERVED_KEYS.to_set).include?(name)
137
+ options[name] = ERB::Util.html_escape(value.to_s)
138
+ end
127
139
  end
128
140
  end
129
141
  end
@@ -2,11 +2,12 @@
2
2
 
3
3
  module ViewComponent
4
4
  module VERSION
5
- MAJOR = 2
6
- MINOR = 82
5
+ MAJOR = 3
6
+ MINOR = 1
7
7
  PATCH = 0
8
+ PRE = nil
8
9
 
9
- STRING = [MAJOR, MINOR, PATCH].join(".")
10
+ STRING = [MAJOR, MINOR, PATCH, PRE].compact.join(".")
10
11
  end
11
12
  end
12
13
 
@@ -3,14 +3,9 @@
3
3
  module ViewComponent
4
4
  module WithContentHelper
5
5
  def with_content(value)
6
- if value.nil?
7
- raise ArgumentError.new(
8
- "No content provided to `#with_content` for #{self}.\n\n" \
9
- "To fix this issue, pass a value."
10
- )
11
- else
12
- @__vc_content_set_by_with_content = value
13
- end
6
+ raise NilWithContentError if value.nil?
7
+
8
+ @__vc_content_set_by_with_content = value
14
9
 
15
10
  self
16
11
  end
@@ -7,29 +7,20 @@ module ViewComponent
7
7
  extend ActiveSupport::Autoload
8
8
 
9
9
  autoload :Base
10
+ autoload :CaptureCompatibility
10
11
  autoload :Compiler
11
12
  autoload :CompileCache
12
13
  autoload :ComponentError
13
14
  autoload :Config
14
15
  autoload :Deprecation
16
+ autoload :InlineTemplate
15
17
  autoload :Instrumentation
16
18
  autoload :Preview
17
- autoload :PreviewTemplateError
18
19
  autoload :TestHelpers
19
20
  autoload :SystemTestHelpers
20
21
  autoload :TestCase
21
22
  autoload :SystemTestCase
22
- autoload :TemplateError
23
23
  autoload :Translatable
24
24
  end
25
25
 
26
- # :nocov:
27
- if defined?(ViewComponent::Engine)
28
- ViewComponent::Deprecation.deprecation_warning(
29
- "Manually loading the engine",
30
- "remove `require \"view_component/engine\"`"
31
- )
32
- elsif defined?(Rails::Engine)
33
- require "view_component/engine"
34
- end
35
- # :nocov:
26
+ require "view_component/engine" if defined?(Rails::Engine)
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.82.0
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ViewComponent Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-11 00:00:00.000000000 Z
11
+ date: 2023-05-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -78,28 +78,28 @@ dependencies:
78
78
  requirements:
79
79
  - - "~>"
80
80
  - !ruby/object:Gem::Version
81
- version: 2.8.2
81
+ version: 2.12.0
82
82
  type: :development
83
83
  prerelease: false
84
84
  version_requirements: !ruby/object:Gem::Requirement
85
85
  requirements:
86
86
  - - "~>"
87
87
  - !ruby/object:Gem::Version
88
- version: 2.8.2
88
+ version: 2.12.0
89
89
  - !ruby/object:Gem::Dependency
90
90
  name: better_html
91
91
  requirement: !ruby/object:Gem::Requirement
92
92
  requirements:
93
- - - "~>"
93
+ - - ">="
94
94
  - !ruby/object:Gem::Version
95
- version: '1'
95
+ version: '0'
96
96
  type: :development
97
97
  prerelease: false
98
98
  version_requirements: !ruby/object:Gem::Requirement
99
99
  requirements:
100
- - - "~>"
100
+ - - ">="
101
101
  - !ruby/object:Gem::Version
102
- version: '1'
102
+ version: '0'
103
103
  - !ruby/object:Gem::Dependency
104
104
  name: bundler
105
105
  requirement: !ruby/object:Gem::Requirement
@@ -118,30 +118,30 @@ dependencies:
118
118
  name: erb_lint
119
119
  requirement: !ruby/object:Gem::Requirement
120
120
  requirements:
121
- - - "~>"
121
+ - - ">="
122
122
  - !ruby/object:Gem::Version
123
- version: 0.0.37
123
+ version: '0'
124
124
  type: :development
125
125
  prerelease: false
126
126
  version_requirements: !ruby/object:Gem::Requirement
127
127
  requirements:
128
- - - "~>"
128
+ - - ">="
129
129
  - !ruby/object:Gem::Version
130
- version: 0.0.37
130
+ version: '0'
131
131
  - !ruby/object:Gem::Dependency
132
132
  name: haml
133
133
  requirement: !ruby/object:Gem::Requirement
134
134
  requirements:
135
135
  - - "~>"
136
136
  - !ruby/object:Gem::Version
137
- version: '5'
137
+ version: '6'
138
138
  type: :development
139
139
  prerelease: false
140
140
  version_requirements: !ruby/object:Gem::Requirement
141
141
  requirements:
142
142
  - - "~>"
143
143
  - !ruby/object:Gem::Version
144
- version: '5'
144
+ version: '6'
145
145
  - !ruby/object:Gem::Dependency
146
146
  name: jbuilder
147
147
  requirement: !ruby/object:Gem::Requirement
@@ -174,16 +174,16 @@ dependencies:
174
174
  name: minitest
175
175
  requirement: !ruby/object:Gem::Requirement
176
176
  requirements:
177
- - - '='
177
+ - - "~>"
178
178
  - !ruby/object:Gem::Version
179
- version: 5.6.0
179
+ version: '5.18'
180
180
  type: :development
181
181
  prerelease: false
182
182
  version_requirements: !ruby/object:Gem::Requirement
183
183
  requirements:
184
- - - '='
184
+ - - "~>"
185
185
  - !ruby/object:Gem::Version
186
- version: 5.6.0
186
+ version: '5.18'
187
187
  - !ruby/object:Gem::Dependency
188
188
  name: pry
189
189
  requirement: !ruby/object:Gem::Requirement
@@ -212,6 +212,20 @@ dependencies:
212
212
  - - "~>"
213
213
  - !ruby/object:Gem::Version
214
214
  version: '13.0'
215
+ - !ruby/object:Gem::Dependency
216
+ name: rubocop-md
217
+ requirement: !ruby/object:Gem::Requirement
218
+ requirements:
219
+ - - "~>"
220
+ - !ruby/object:Gem::Version
221
+ version: '1'
222
+ type: :development
223
+ prerelease: false
224
+ version_requirements: !ruby/object:Gem::Requirement
225
+ requirements:
226
+ - - "~>"
227
+ - !ruby/object:Gem::Version
228
+ version: '1'
215
229
  - !ruby/object:Gem::Dependency
216
230
  name: standard
217
231
  requirement: !ruby/object:Gem::Requirement
@@ -232,56 +246,56 @@ dependencies:
232
246
  requirements:
233
247
  - - "~>"
234
248
  - !ruby/object:Gem::Version
235
- version: 0.18.0
249
+ version: 0.22.0
236
250
  type: :development
237
251
  prerelease: false
238
252
  version_requirements: !ruby/object:Gem::Requirement
239
253
  requirements:
240
254
  - - "~>"
241
255
  - !ruby/object:Gem::Version
242
- version: 0.18.0
256
+ version: 0.22.0
243
257
  - !ruby/object:Gem::Dependency
244
258
  name: simplecov-console
245
259
  requirement: !ruby/object:Gem::Requirement
246
260
  requirements:
247
261
  - - "~>"
248
262
  - !ruby/object:Gem::Version
249
- version: 0.7.2
263
+ version: 0.9.1
250
264
  type: :development
251
265
  prerelease: false
252
266
  version_requirements: !ruby/object:Gem::Requirement
253
267
  requirements:
254
268
  - - "~>"
255
269
  - !ruby/object:Gem::Version
256
- version: 0.7.2
270
+ version: 0.9.1
257
271
  - !ruby/object:Gem::Dependency
258
272
  name: slim
259
273
  requirement: !ruby/object:Gem::Requirement
260
274
  requirements:
261
275
  - - "~>"
262
276
  - !ruby/object:Gem::Version
263
- version: '4.0'
277
+ version: '5.1'
264
278
  type: :development
265
279
  prerelease: false
266
280
  version_requirements: !ruby/object:Gem::Requirement
267
281
  requirements:
268
282
  - - "~>"
269
283
  - !ruby/object:Gem::Version
270
- version: '4.0'
284
+ version: '5.1'
271
285
  - !ruby/object:Gem::Dependency
272
286
  name: sprockets-rails
273
287
  requirement: !ruby/object:Gem::Requirement
274
288
  requirements:
275
289
  - - "~>"
276
290
  - !ruby/object:Gem::Version
277
- version: 3.2.2
291
+ version: 3.4.2
278
292
  type: :development
279
293
  prerelease: false
280
294
  version_requirements: !ruby/object:Gem::Requirement
281
295
  requirements:
282
296
  - - "~>"
283
297
  - !ruby/object:Gem::Version
284
- version: 3.2.2
298
+ version: 3.4.2
285
299
  - !ruby/object:Gem::Dependency
286
300
  name: yard
287
301
  requirement: !ruby/object:Gem::Requirement
@@ -353,20 +367,20 @@ files:
353
367
  - lib/rails/generators/test_unit/templates/component_test.rb.tt
354
368
  - lib/view_component.rb
355
369
  - lib/view_component/base.rb
370
+ - lib/view_component/capture_compatibility.rb
356
371
  - lib/view_component/collection.rb
357
372
  - lib/view_component/compile_cache.rb
358
373
  - lib/view_component/compiler.rb
359
374
  - lib/view_component/component_error.rb
360
375
  - lib/view_component/config.rb
361
- - lib/view_component/content_areas.rb
362
376
  - lib/view_component/deprecation.rb
363
377
  - lib/view_component/docs_builder_component.html.erb
364
378
  - lib/view_component/docs_builder_component.rb
365
379
  - lib/view_component/engine.rb
380
+ - lib/view_component/errors.rb
381
+ - lib/view_component/inline_template.rb
366
382
  - lib/view_component/instrumentation.rb
367
- - lib/view_component/polymorphic_slots.rb
368
383
  - lib/view_component/preview.rb
369
- - lib/view_component/preview_template_error.rb
370
384
  - lib/view_component/rails/tasks/view_component.rake
371
385
  - lib/view_component/render_component_helper.rb
372
386
  - lib/view_component/render_component_to_string_helper.rb
@@ -375,12 +389,9 @@ files:
375
389
  - lib/view_component/rendering_component_helper.rb
376
390
  - lib/view_component/rendering_monkey_patch.rb
377
391
  - lib/view_component/slot.rb
378
- - lib/view_component/slot_v2.rb
379
392
  - lib/view_component/slotable.rb
380
- - lib/view_component/slotable_v2.rb
381
393
  - lib/view_component/system_test_case.rb
382
394
  - lib/view_component/system_test_helpers.rb
383
- - lib/view_component/template_error.rb
384
395
  - lib/view_component/test_case.rb
385
396
  - lib/view_component/test_helpers.rb
386
397
  - lib/view_component/translatable.rb
@@ -402,14 +413,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
402
413
  requirements:
403
414
  - - ">="
404
415
  - !ruby/object:Gem::Version
405
- version: 2.4.0
416
+ version: 2.7.0
406
417
  required_rubygems_version: !ruby/object:Gem::Requirement
407
418
  requirements:
408
419
  - - ">="
409
420
  - !ruby/object:Gem::Version
410
421
  version: '0'
411
422
  requirements: []
412
- rubygems_version: 3.2.32
423
+ rubygems_version: 3.4.5
413
424
  signing_key:
414
425
  specification_version: 4
415
426
  summary: A framework for building reusable, testable & encapsulated view components
@@ -1,56 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "active_support/concern"
4
-
5
- require "view_component/slot"
6
-
7
- # DEPRECATED - ContentAreas is deprecated and will be removed in v3.0.0
8
- module ViewComponent
9
- module ContentAreas
10
- extend ActiveSupport::Concern
11
-
12
- # Assign the provided content to the content area accessor
13
- #
14
- # @private
15
- def with(area, content = nil, &block)
16
- unless content_areas.include?(area)
17
- raise ArgumentError.new(
18
- "Unknown content_area '#{area}' for #{self} - expected one of '#{content_areas}'.\n\n" \
19
- "To fix this issue, add `with_content_area :#{area}` to #{self} or reference " \
20
- "a valid content area."
21
- )
22
- end
23
-
24
- if block
25
- content = view_context.capture(&block)
26
- end
27
-
28
- instance_variable_set("@#{area}".to_sym, content)
29
- nil
30
- end
31
-
32
- class_methods do
33
- def with_content_areas(*areas)
34
- ViewComponent::Deprecation.deprecation_warning(
35
- "`with_content_areas`", "use slots (https://viewcomponent.org/guide/slots.html) instead"
36
- )
37
-
38
- if areas.include?(:content)
39
- raise ArgumentError.new(
40
- "#{self} defines a content area called :content, which is a reserved name. \n\n" \
41
- "To fix this issue, use another name, such as `:body`."
42
- )
43
- end
44
-
45
- areas.each do |area|
46
- define_method area.to_sym do
47
- content unless content_evaluated? # ensure content is loaded so content_areas will be defined
48
- instance_variable_get(:"@#{area}") if instance_variable_defined?(:"@#{area}")
49
- end
50
- end
51
-
52
- self.content_areas = areas
53
- end
54
- end
55
- end
56
- end