Sha256: 3a83a5ae217bf15d5767c13f5d2bb66643ceb9df4b4c9b32aee7346c1b03be29

Contents?: true

Size: 855 Bytes

Versions: 1

Compression:

Stored size: 855 Bytes

Contents

class NicePartials::Partial::Section
  def initialize(view_context)
    @view_context = view_context
    @content = @pending_content = nil
  end

  def content_for(*arguments, &block)
    if write_content_for(arguments.first, &block)
      nil
    else
      capture_content_for(*arguments) if pending?
      @content
    end
  end

  def content?
    pending? || @content
  end

  private

  def write_content_for(content = nil, &block)
    if content && !pending?
      concat content
    else
      @pending_content = block if block
    end
  end

  def capture_content_for(*arguments)
    concat @view_context.capture(*arguments, &@pending_content)
    @pending_content = nil
  end

  def concat(string)
    @content ||= ActiveSupport::SafeBuffer.new
    @content << string.to_s if string.present?
  end

  def pending?
    @pending_content
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nice_partials-0.1.9 lib/nice_partials/partial/section.rb