Sha256: 58c6a7787d9c14a863d0046abea4a90cbf032354d52fad1e8b8b928cb55663b7

Contents?: true

Size: 953 Bytes

Versions: 4

Compression:

Stored size: 953 Bytes

Contents

# frozen_string_literal: true

module Blocks
  class PartialRenderer
    def self.render(runtime_context)
      builder = runtime_context.builder
      view = builder.view
      partial = runtime_context.render_item
      partial = partial.to_partial_path if partial.respond_to?(:to_partial_path)
      runtime_block = runtime_context.runtime_block

      options = runtime_context.to_hash
      overrides_and_provided_content = builder.capture(builder, options, &runtime_context.runtime_block) if runtime_block

      locals = options.merge(
        (runtime_context[:builder_variable] || :builder) => builder,
      )
      locals[:options] = options

      builder.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

4 entries across 4 versions & 1 rubygems

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