Sha256: 64dfd0ff73af7a84078cce0b9073393760899311255b1c42aa2acf2ed22854f8

Contents?: true

Size: 899 Bytes

Versions: 3

Compression:

Stored size: 899 Bytes

Contents

# frozen_string_literal: true

# A monkey-patch for Action View `render :partial` that auto-decorates `locals` values.
module ActiveDecorator
  module Monkey
    module ActionView
      module PartialRenderer
        if Rails.version.to_f >= 6.1
          def initialize(*)
            super

            @locals.each_value do |v|
              ActiveDecorator::Decorator.instance.decorate v
            end
          end
        end

        private

        if Rails.version.to_f < 6.1
          def setup(*)
            super

            @locals.each_value do |v|
              ActiveDecorator::Decorator.instance.decorate v
            end if @locals
            ActiveDecorator::Decorator.instance.decorate @object if @object
            ActiveDecorator::Decorator.instance.decorate @collection unless @collection.blank?

            self
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
active_decorator-1.4.1 lib/active_decorator/monkey/action_view/partial_renderer.rb
active_decorator-1.4.0 lib/active_decorator/monkey/action_view/partial_renderer.rb
active_decorator-1.3.4 lib/active_decorator/monkey/action_view/partial_renderer.rb