Sha256: b0dfe9fbe3262064255985bb85dc1199c4090001e1c3713cc6f870223781bb69

Contents?: true

Size: 676 Bytes

Versions: 4

Compression:

Stored size: 676 Bytes

Contents

# frozen_string_literal: true

module Blocks
  class NestingBlocksRenderer
    def self.render(hook, runtime_context)
      hooks = runtime_context.hooks_for(hook)
      if hooks.present?
        content_block = Proc.new { runtime_context.with_output_buffer { yield } }

        renderer = hooks.inject(content_block) do |inner_content, hook_definition|
          hook_runtime_context = runtime_context.extend_from_definition(hook_definition, &inner_content)
          Proc.new {
            BlockWithHooksRenderer.render(hook_runtime_context)
          }
        end

        runtime_context.output_buffer << renderer.call
      else
        yield
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
blocks-4.0.1 lib/blocks/renderers/nesting_blocks_renderer.rb
blocks-4.0.0 lib/blocks/renderers/nesting_blocks_renderer.rb
blocks-4.0.0.rc2 lib/blocks/renderers/nesting_blocks_renderer.rb
blocks-4.0.0.rc1 lib/blocks/renderers/nesting_blocks_renderer.rb