view_component 2.82.0 → 3.0.0.rc2

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.

@@ -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 = 0
7
7
  PATCH = 0
8
+ PRE = "rc2"
8
9
 
9
- STRING = [MAJOR, MINOR, PATCH].join(".")
10
+ STRING = [MAJOR, MINOR, PATCH, PRE].compact.join(".")
10
11
  end
11
12
  end
12
13
 
@@ -7,6 +7,7 @@ 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
@@ -23,13 +24,4 @@ module ViewComponent
23
24
  autoload :Translatable
24
25
  end
25
26
 
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:
27
+ 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.0.0.rc2
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-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -353,18 +353,17 @@ files:
353
353
  - lib/rails/generators/test_unit/templates/component_test.rb.tt
354
354
  - lib/view_component.rb
355
355
  - lib/view_component/base.rb
356
+ - lib/view_component/capture_compatibility.rb
356
357
  - lib/view_component/collection.rb
357
358
  - lib/view_component/compile_cache.rb
358
359
  - lib/view_component/compiler.rb
359
360
  - lib/view_component/component_error.rb
360
361
  - lib/view_component/config.rb
361
- - lib/view_component/content_areas.rb
362
362
  - lib/view_component/deprecation.rb
363
363
  - lib/view_component/docs_builder_component.html.erb
364
364
  - lib/view_component/docs_builder_component.rb
365
365
  - lib/view_component/engine.rb
366
366
  - lib/view_component/instrumentation.rb
367
- - lib/view_component/polymorphic_slots.rb
368
367
  - lib/view_component/preview.rb
369
368
  - lib/view_component/preview_template_error.rb
370
369
  - lib/view_component/rails/tasks/view_component.rake
@@ -375,9 +374,7 @@ files:
375
374
  - lib/view_component/rendering_component_helper.rb
376
375
  - lib/view_component/rendering_monkey_patch.rb
377
376
  - lib/view_component/slot.rb
378
- - lib/view_component/slot_v2.rb
379
377
  - lib/view_component/slotable.rb
380
- - lib/view_component/slotable_v2.rb
381
378
  - lib/view_component/system_test_case.rb
382
379
  - lib/view_component/system_test_helpers.rb
383
380
  - lib/view_component/template_error.rb
@@ -402,12 +399,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
402
399
  requirements:
403
400
  - - ">="
404
401
  - !ruby/object:Gem::Version
405
- version: 2.4.0
402
+ version: 2.7.0
406
403
  required_rubygems_version: !ruby/object:Gem::Requirement
407
404
  requirements:
408
- - - ">="
405
+ - - ">"
409
406
  - !ruby/object:Gem::Version
410
- version: '0'
407
+ version: 1.3.1
411
408
  requirements: []
412
409
  rubygems_version: 3.2.32
413
410
  signing_key:
@@ -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
@@ -1,103 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ViewComponent
4
- module PolymorphicSlots
5
- # In older rails versions, using a concern isn't a good idea here because they appear to not work with
6
- # Module#prepend and class methods.
7
- def self.included(base)
8
- if base != ViewComponent::Base
9
- # :nocov:
10
- location = Kernel.caller_locations(1, 1)[0]
11
-
12
- warn(
13
- "warning: ViewComponent::PolymorphicSlots is now included in ViewComponent::Base by default " \
14
- "and can be removed from #{location.path}:#{location.lineno}"
15
- )
16
- # :nocov:
17
- end
18
-
19
- base.singleton_class.prepend(ClassMethods)
20
- base.include(InstanceMethods)
21
- end
22
-
23
- module ClassMethods
24
- def renders_one(slot_name, callable = nil)
25
- return super unless callable.is_a?(Hash) && callable.key?(:types)
26
-
27
- validate_singular_slot_name(slot_name)
28
- register_polymorphic_slot(slot_name, callable[:types], collection: false)
29
- end
30
-
31
- def renders_many(slot_name, callable = nil)
32
- return super unless callable.is_a?(Hash) && callable.key?(:types)
33
-
34
- validate_plural_slot_name(slot_name)
35
- register_polymorphic_slot(slot_name, callable[:types], collection: true)
36
- end
37
-
38
- def register_polymorphic_slot(slot_name, types, collection:)
39
- unless types.empty?
40
- getter_name = slot_name
41
-
42
- define_method(getter_name) do
43
- get_slot(slot_name)
44
- end
45
-
46
- define_method("#{getter_name}?") do
47
- get_slot(slot_name).present?
48
- end
49
- end
50
-
51
- renderable_hash = types.each_with_object({}) do |(poly_type, poly_callable), memo|
52
- memo[poly_type] = define_slot(
53
- "#{slot_name}_#{poly_type}", collection: collection, callable: poly_callable
54
- )
55
-
56
- setter_name =
57
- if collection
58
- "#{ActiveSupport::Inflector.singularize(slot_name)}_#{poly_type}"
59
- else
60
- "#{slot_name}_#{poly_type}"
61
- end
62
-
63
- define_method(setter_name) do |*args, &block|
64
- if _warn_on_deprecated_slot_setter
65
- ViewComponent::Deprecation.deprecation_warning(
66
- "Using polymorphic slot setters like `#{setter_name}`",
67
- :"`with_#{setter_name}`"
68
- )
69
- end
70
-
71
- set_polymorphic_slot(slot_name, poly_type, *args, &block)
72
- end
73
- ruby2_keywords(setter_name.to_sym) if respond_to?(:ruby2_keywords, true)
74
-
75
- define_method("with_#{setter_name}") do |*args, &block|
76
- set_polymorphic_slot(slot_name, poly_type, *args, &block)
77
- end
78
- ruby2_keywords(:"with_#{setter_name}") if respond_to?(:ruby2_keywords, true)
79
- end
80
-
81
- registered_slots[slot_name] = {
82
- collection: collection,
83
- renderable_hash: renderable_hash
84
- }
85
- end
86
- end
87
-
88
- module InstanceMethods
89
- def set_polymorphic_slot(slot_name, poly_type = nil, *args, &block)
90
- slot_definition = self.class.registered_slots[slot_name]
91
-
92
- if !slot_definition[:collection] && (defined?(@__vc_set_slots) && @__vc_set_slots[slot_name])
93
- raise ArgumentError, "content for slot '#{slot_name}' has already been provided"
94
- end
95
-
96
- poly_def = slot_definition[:renderable_hash][poly_type]
97
-
98
- set_slot(slot_name, poly_def, *args, &block)
99
- end
100
- ruby2_keywords(:set_polymorphic_slot) if respond_to?(:ruby2_keywords, true)
101
- end
102
- end
103
- end
@@ -1,98 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "view_component/with_content_helper"
4
-
5
- module ViewComponent
6
- class SlotV2
7
- include ViewComponent::WithContentHelper
8
-
9
- attr_writer :__vc_component_instance, :__vc_content_block, :__vc_content
10
-
11
- def initialize(parent)
12
- @parent = parent
13
- end
14
-
15
- # Used to render the slot content in the template
16
- #
17
- # There's currently 3 different values that may be set, that we can render.
18
- #
19
- # If the slot renderable is a component, the string class name of a
20
- # component, or a function that returns a component, we render that
21
- # component instance, returning the string.
22
- #
23
- # If the slot renderable is a function and returns a string, it's
24
- # set as `@__vc_content` and is returned directly.
25
- #
26
- # If there is no slot renderable, we evaluate the block passed to
27
- # the slot and return it.
28
- def to_s
29
- return @content if defined?(@content)
30
-
31
- view_context = @parent.send(:view_context)
32
-
33
- if defined?(@__vc_content_block) && defined?(@__vc_content_set_by_with_content)
34
- raise ArgumentError.new(
35
- "It looks like a block was provided after calling `with_content` on #{self.class.name}, " \
36
- "which means that ViewComponent doesn't know which content to use.\n\n" \
37
- "To fix this issue, use either `with_content` or a block."
38
- )
39
- end
40
-
41
- @content =
42
- if defined?(@__vc_component_instance)
43
- @__vc_component_instance.__vc_original_view_context = @parent.__vc_original_view_context
44
-
45
- if defined?(@__vc_content_set_by_with_content)
46
- @__vc_component_instance.with_content(@__vc_content_set_by_with_content)
47
-
48
- @__vc_component_instance.render_in(view_context)
49
- elsif defined?(@__vc_content_block)
50
- # render_in is faster than `parent.render`
51
- @__vc_component_instance.render_in(view_context, &@__vc_content_block)
52
- else
53
- @__vc_component_instance.render_in(view_context)
54
- end
55
- elsif defined?(@__vc_content)
56
- @__vc_content
57
- elsif defined?(@__vc_content_block)
58
- view_context.capture(&@__vc_content_block)
59
- elsif defined?(@__vc_content_set_by_with_content)
60
- @__vc_content_set_by_with_content
61
- end
62
-
63
- @content = @content.to_s
64
- end
65
-
66
- # Allow access to public component methods via the wrapper
67
- #
68
- # for example
69
- #
70
- # calling `header.name` (where `header` is a slot) will call `name`
71
- # on the `HeaderComponent` instance.
72
- #
73
- # Where the component may look like:
74
- #
75
- # class MyComponent < ViewComponent::Base
76
- # has_one :header, HeaderComponent
77
- #
78
- # class HeaderComponent < ViewComponent::Base
79
- # def name
80
- # @name
81
- # end
82
- # end
83
- # end
84
- #
85
- def method_missing(symbol, *args, &block)
86
- @__vc_component_instance.public_send(symbol, *args, &block)
87
- end
88
- ruby2_keywords(:method_missing) if respond_to?(:ruby2_keywords, true)
89
-
90
- def html_safe?
91
- to_s.html_safe?
92
- end
93
-
94
- def respond_to_missing?(symbol, include_all = false)
95
- defined?(@__vc_component_instance) && @__vc_component_instance.respond_to?(symbol, include_all)
96
- end
97
- end
98
- end