Sha256: 7de7e2c14ca4ecd2b848728f7aed35d843d61baa8cb3b0d6ed67b94dd3f3ec67

Contents?: true

Size: 782 Bytes

Versions: 3

Compression:

Stored size: 782 Bytes

Contents

module Blocks
  class PartialRenderer < AbstractRenderer
    def render(partial, options={}, &block)
      if !options.is_a?(Blocks::RuntimeContext)
        options = RuntimeContext.new(builder, options).to_hash.with_indifferent_access.deep_dup
      end
      overrides_and_provided_content = capture(builder, options, &block) if block_given?
      locals = options.merge(
        (options[:builder_variable] || :builder) => builder,
      ).symbolize_keys
      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
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
blocks-3.0.0.rc6 lib/blocks/renderers/partial_renderer.rb
blocks-3.0.0.rc5 lib/blocks/renderers/partial_renderer.rb
blocks-3.0.0.rc4 lib/blocks/renderers/partial_renderer.rb