Sha256: 32b3cc088f0f696307f94a9c0b7376905bbbabd59831f1ad260eec30416c8706

Contents?: true

Size: 793 Bytes

Versions: 1

Compression:

Stored size: 793 Bytes

Contents

module NicePartials
  class Partial
    def initialize(view_context)
      @view_context = view_context
      @key = SecureRandom.uuid
    end

    def yield(name = nil)
      raise "You can only use Nice Partial's yield method to retrieve the content of named content area blocks. If you're not trying to fetch the content of a named content area block, you don't need Nice Partials! You can just call the vanilla Rails `yield`." unless name
      content_for(name)
    end

    def helpers(&block)
      class_eval &block
    end

    def content_for(name, content = nil, options = {}, &block)
      @view_context.content_for("#{name}_#{@key}".to_sym, content, options, &block)
    end

    def content_for?(name)
      @view_context.content_for?("#{name}_#{@key}".to_sym)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nice_partials-0.1.2 lib/nice_partials/partial.rb