class NicePartials::Partial

Public Class Methods

new(view_context) click to toggle source
# File lib/nice_partials/partial.rb, line 5
def initialize(view_context)
  @view_context = view_context
  @key = SecureRandom.uuid
end

Public Instance Methods

content_for(name, content = nil, options = {}, &block) click to toggle source

See the ‘ActionView::PartialRenderer` monkey patch in `lib/nice_partials/monkey_patch.rb` for something similar.

# File lib/nice_partials/partial.rb, line 20
def content_for(name, content = nil, options = {}, &block)
  if block_given?
    partial_prefix = nice_partials_locale_prefix_from_view_context_and_block(@view_context, block)
    @view_context.nice_partials_push_t_prefix(partial_prefix)
  end

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

  if block_given?
    @view_context.nice_partials_pop_t_prefix
  end

  return result
end
content_for?(name) click to toggle source
# File lib/nice_partials/partial.rb, line 35
def content_for?(name)
  @view_context.content_for?("#{name}_#{@key}".to_sym)
end
helpers(&block) click to toggle source
# File lib/nice_partials/partial.rb, line 15
def helpers(&block)
  class_eval &block
end
yield(name = nil) click to toggle source
# File lib/nice_partials/partial.rb, line 10
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