Sha256: 735f7fc6ba08d1e24982e7b27f54a47cbc03cbbda20b77635eae7d8dc019ab8f

Contents?: true

Size: 1.06 KB

Versions: 2

Compression:

Stored size: 1.06 KB

Contents

module ActionController::PartialHelper
  def partial_for(name)
    case name
    when String then  name
    when Array  then  partial_for name.first
    else              "sh/#{name.class.name.underscore}"
    end
  end

  #
  # partial <partial-name>, <object>, <locals> or
  # partial <object>, <locals>
  #
  def partial(partial, object=nil, locals=nil)
    #
    # set up object and locals
    unless partial.is_a?(String) 
      object, locals = partial, object
    end
    if !locals && object.is_a?(Hash)
      locals, object = object, nil
    end
    
    opts = { 
      :partial => partial_for(partial), 
      :locals => locals 
    }
    
    if object
      opts[:object] = object
    elsif locals && locals[:collection]
      opts[:collection] = locals[:collection]
    end
    
    if self.is_a?(ActionController::Base)
      render_to_string(opts)
    else
      render(opts)
    end
  end

  def partial?(*args)
    partial *args
  rescue ActionView::MissingTemplate
    logger.debug $!.to_s
    nil
  end
end

ActionController::Base.helper ActionController::PartialHelper

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
vex-0.4.2 lib/vex/action_controller/partial_helper.rb
vex-0.3.3 lib/vex/action_controller/partial_helper.rb