Class: Blocks::NestingBlocksRenderer

Inherits:
AbstractRenderer show all
Defined in:
lib/blocks/renderers/nesting_blocks_renderer.rb

Constant Summary

Constants inherited from AbstractRenderer

AbstractRenderer::RENDERERS

Instance Attribute Summary

Attributes inherited from AbstractRenderer

#main_renderer

Instance Method Summary collapse

Methods inherited from AbstractRenderer

#capture, #initialize

Constructor Details

This class inherits a constructor from Blocks::AbstractRenderer

Instance Method Details

#render(hook, runtime_context) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/blocks/renderers/nesting_blocks_renderer.rb', line 3

def render(hook, runtime_context)
  block = block_for(runtime_context.block_name)
  hooks = block.try(:hooks_for, hook)
  if hooks.present?
    content_block = Proc.new { with_output_buffer { yield } }

    renderer = hooks.inject(content_block) do |inner_content, hook_definition|
      hook_runtime_context = runtime_context.extend_to_block_definition(hook_definition)
      Proc.new {
        with_output_buffer do
          block_renderer.render(inner_content, hook_runtime_context)
        end
      }
    end

    output_buffer << renderer.call
  else
    yield
  end

end