Class: Blocks::BlockWithHooksRenderer

Inherits:
Object
  • Object
show all
Defined in:
lib/blocks/renderers/block_with_hooks_renderer.rb

Overview

TODO: Make this render order customizable

Class Method Summary collapse

Class Method Details

.render(runtime_context) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/blocks/renderers/block_with_hooks_renderer.rb', line 6

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

.render_hooks(hook_type, runtime_context, &block) ⇒ Object



40
41
42
43
# File 'lib/blocks/renderers/block_with_hooks_renderer.rb', line 40

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