Module: ActionView::Component::RenderMonkeyPatch

Defined in:
lib/action_view/component/render_monkey_patch.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#render(options = {}, args = {}, &block) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/action_view/component/render_monkey_patch.rb', line 7

def render(options = {}, args = {}, &block)
  if options.respond_to?(:render_in)
    options.render_in(self, &block)
  elsif options.is_a?(Class) && options < ActionView::Component::Base
    ActiveSupport::Deprecation.warn(
      "`render MyComponent, foo: :bar` has been deprecated and will be removed in v2.0.0. Use `render MyComponent.new(foo: :bar)` instead."
    )

    options.new(args).render_in(self, &block)
  elsif options.is_a?(Hash) && options.has_key?(:component)
    ActiveSupport::Deprecation.warn(
      "`render component: MyComponent, locals: { foo: :bar }` has been deprecated and will be removed in v2.0.0. Use `render MyComponent.new(foo: :bar)` instead."
    )

    options[:component].new(options[:locals]).render_in(self, &block)
  elsif options.respond_to?(:to_component_class) && !options.to_component_class.nil?
    ActiveSupport::Deprecation.warn(
      "rendering objects that respond_to `to_component_class` has been deprecated and will be removed in v2.0.0. Use `render MyComponent.new(foo: :bar)` instead."
    )

    options.to_component_class.new(options).render_in(self, &block)
  else
    super
  end
end