Sha256: 3de6a90405f60201aca7eaaa4e3498e45fb8905a73dcb9f10a7bd0565a98bef7

Contents?: true

Size: 879 Bytes

Versions: 95

Compression:

Stored size: 879 Bytes

Contents

# frozen_string_literal: true

module Primer
  # :nodoc:
  module ExperimentalRenderHelpers
    def self.included(base)
      base.include(InstanceMethods)
    end

    # :nodoc:
    module InstanceMethods
      def evaluate_block(*args, **kwargs, &block)
        # Prevent double renders by using the capture method on the component
        # that originally received the block.
        #
        # Handle blocks that originate from C code such as `&:method` by checking
        # source_location. Such blocks don't allow access to their receiver.
        return unless block

        return yield(*args, **kwargs) if block&.source_location.nil?

        block_context = block.binding.receiver

        if block_context.class < ActionView::Base
          block_context.capture(*args, &block)
        else
          capture(*args, &block)
        end
      end
    end
  end
end

Version data entries

95 entries across 95 versions & 2 rubygems

Version Path
primer_view_components-0.19.0 app/lib/primer/experimental_render_helpers.rb
openproject-primer_view_components-0.22.2 app/lib/primer/experimental_render_helpers.rb
primer_view_components-0.18.2 app/lib/primer/experimental_render_helpers.rb
openproject-primer_view_components-0.22.1 app/lib/primer/experimental_render_helpers.rb
primer_view_components-0.18.1 app/lib/primer/experimental_render_helpers.rb
openproject-primer_view_components-0.22.0 app/lib/primer/experimental_render_helpers.rb
primer_view_components-0.18.0 app/lib/primer/experimental_render_helpers.rb
openproject-primer_view_components-0.21.0 app/lib/primer/experimental_render_helpers.rb
primer_view_components-0.17.0 app/lib/primer/experimental_render_helpers.rb
openproject-primer_view_components-0.20.0 app/lib/primer/experimental_render_helpers.rb
primer_view_components-0.16.1 app/lib/primer/experimental_render_helpers.rb
primer_view_components-0.16.0 app/lib/primer/experimental_render_helpers.rb
openproject-primer_view_components-0.19.0 app/lib/primer/experimental_render_helpers.rb
primer_view_components-0.15.1 app/lib/primer/experimental_render_helpers.rb
primer_view_components-0.15.0 app/lib/primer/experimental_render_helpers.rb