Sha256: 8acd2023ea6102780b0168269773c108a38d5fcca98ffb8a3aed9386791b0a08

Contents?: true

Size: 1011 Bytes

Versions: 4

Compression:

Stored size: 1011 Bytes

Contents

# frozen_string_literal: true

# Monkey patch ActionView::Base#render to support ActionView::Component
#
# A version of this monkey patch was upstreamed in https://github.com/rails/rails/pull/36388
# We'll need to upstream an updated version of this eventually.
class ActionView::Base
  module RenderMonkeyPatch
    def render(options = {}, args = {}, &block)
      if options.respond_to?(:render_in)
        ActiveSupport::Deprecation.warn(
          "passing component instances (`render MyComponent.new(foo: :bar)`) has been deprecated and will be removed in v2.0.0. Use `render MyComponent, foo: :bar` instead."
        )

        options.render_in(self, &block)
      elsif options.is_a?(Class) && options < ActionView::Component::Base
        options.new(args).render_in(self, &block)
      elsif options.is_a?(Hash) && options.has_key?(:component)
        options[:component].new(options[:locals]).render_in(self, &block)
      else
        super
      end
    end
  end

  prepend RenderMonkeyPatch
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
actionview-component-1.5.3 lib/action_view/component/monkey_patch.rb
actionview-component-1.5.2 lib/action_view/component/monkey_patch.rb
actionview-component-1.5.1 lib/action_view/component/monkey_patch.rb
actionview-component-1.5.0 lib/action_view/component/monkey_patch.rb