Sha256: 2a011cc945bf5c54864b1758117f5676efc3eb393fe16a7ac79aa916667fc6c1

Contents?: true

Size: 1.94 KB

Versions: 4

Compression:

Stored size: 1.94 KB

Contents

# frozen_string_literal: true

module Blocks
  # TODO: Make this render order customizable
  class BlockWithHooksRenderer
    def self.render(runtime_context)
      runtime_context.with_output_buffer do
        if runtime_context.skip_completely
          # noop
        elsif runtime_context.hooks_or_wrappers_present?
          render_hooks(HookDefinition::BEFORE_ALL, runtime_context)
          render_hooks(HookDefinition::AROUND_ALL, runtime_context) do
            WrapperRenderer.render(runtime_context.wrap_all, :wrap_all, runtime_context) do
              CollectionRenderer.render(runtime_context) do |runtime_context|
                WrapperRenderer.render(runtime_context.wrap_each, :wrap_each, runtime_context) do
                  render_hooks(HookDefinition::AROUND, runtime_context) do
                    render_hooks(HookDefinition::BEFORE, runtime_context)
                    if !runtime_context.skip_content
                      WrapperRenderer.render(runtime_context.wrap_with, :wrapper, runtime_context) do
                        render_hooks(HookDefinition::SURROUND, runtime_context) do
                          render_hooks(HookDefinition::PREPEND, runtime_context)
                          BlockRenderer.render(runtime_context)
                          render_hooks(HookDefinition::APPEND, runtime_context)
                        end
                      end
                    end
                    render_hooks(HookDefinition::AFTER, runtime_context)
                  end
                end
              end
            end
          end
          render_hooks(HookDefinition::AFTER_ALL, runtime_context)
        elsif !runtime_context.skip_content
          BlockRenderer.render(runtime_context)
        end
      end
    end

    def self.render_hooks(hook_type, runtime_context, &block)
      renderer_class = block ? NestingBlocksRenderer : AdjacentBlocksRenderer
      renderer_class.render(hook_type, runtime_context, &block)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

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