Sha256: 6d8aa04b224bde8d39c2d6d2de6814369cbc470c185fd253863cafe3da8c9f0e

Contents?: true

Size: 1.09 KB

Versions: 1

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true

module Blocks
  class CollectionRenderer
    def self.render(runtime_context)
      collection = runtime_context.collection
      if collection
        original_collection_item = runtime_context.collection_item
        original_collection_item_index = runtime_context.collection_item_index
        original_runtime_args = runtime_context.runtime_args
        collection.each_with_index do |item, index|
          runtime_context.collection_item = item
          runtime_context.collection_item_index = index

          if Blocks.collection_item_passed_to_block_as_first_arg
            runtime_context.runtime_args = runtime_context.runtime_args.try(:clone) || []
            runtime_context.runtime_args = [item] + Array(runtime_context.runtime_args)
          end

          yield runtime_context
        end
        runtime_context.collection_item = original_collection_item
        runtime_context.collection_item_index = original_collection_item_index
        runtime_context.runtime_args = original_runtime_args
      else
        yield runtime_context
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
blocks-4.0.0.rc1 lib/blocks/renderers/collection_renderer.rb