Class: Blocks::PartialRenderer

Inherits:
AbstractRenderer show all
Defined in:
lib/blocks/renderers/partial_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(partial, options = {}, &block) ⇒ Object



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

def render(partial, options={}, &block)
  if !options.is_a?(Blocks::RuntimeContext)
    options = RuntimeContext.new(builder, options).to_hash.with_indifferent_access
  end
  overrides_and_provided_content = capture(builder, options, &block) if block_given?
  locals = options.merge(
    (options[:builder_variable] || :builder) => builder,
  )
  locals = if locals.respond_to?(:deep_symbolize_keys)
    locals.deep_symbolize_keys
  else
    locals.symbolize_keys
  end
  partial = partial.to_partial_path if partial.respond_to?(:to_partial_path)
  locals[:options] = options
  view.render(layout: partial, locals: locals) do |*args|
    if overrides_and_provided_content
      overrides_and_provided_content.to_str.gsub(/PLACEHOLDER_FOR_([\w]+)/) do |s|
        builder.render $1, *args
      end.html_safe
    end
  end
end