Sha256: e946969ea8c59a9b9b096802013ca6f32d5178954954bc5126d4c558456374f5

Contents?: true

Size: 1.24 KB

Versions: 13

Compression:

Stored size: 1.24 KB

Contents

module Padrino
  module Helpers
    module RenderHelpers
      # Partials implementation which includes collections support
      # partial 'photo/_item', :object => @photo
      # partial 'photo/_item', :collection => @photos
      def partial(template, options={})
        options.reverse_merge!(:locals => {}, :layout => false)
        path = template.to_s.split(File::SEPARATOR)
        object_name = path[-1].to_sym
        path[-1] = "_#{path[-1]}"
        template_path = File.join(path)
        raise 'Partial collection specified but is nil' if options.has_key?(:collection) && options[:collection].nil?
        if collection = options.delete(:collection)
          options.delete(:object)
          counter = 0
          collection.collect do |member|
            counter += 1
            options[:locals].merge!(object_name => member, "#{object_name}_counter".to_sym => counter)
            render(template_path, nil, options.merge(:layout => false))
          end.join("\n")
        else
          if member = options.delete(:object)
            options[:locals].merge!(object_name => member)
          end
          render(template_path, nil, options.merge(:layout => false))
        end
      end
      alias :render_partial :partial
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
padrino-helpers-0.7.5 lib/padrino-helpers/render_helpers.rb
padrino-helpers-0.7.4 lib/padrino-helpers/render_helpers.rb
padrino-helpers-0.7.3 lib/padrino-helpers/render_helpers.rb
padrino-helpers-0.7.2 lib/padrino-helpers/render_helpers.rb
padrino-helpers-0.7.1 lib/padrino-helpers/render_helpers.rb
padrino-helpers-0.7.0 lib/padrino-helpers/render_helpers.rb
padrino-helpers-0.6.7 lib/padrino-helpers/render_helpers.rb
padrino-helpers-0.6.3 lib/padrino-helpers/render_helpers.rb
padrino-helpers-0.6.2 lib/padrino-helpers/render_helpers.rb
padrino-helpers-0.6.1 lib/padrino-helpers/render_helpers.rb
padrino-helpers-0.5.0 lib/padrino-helpers/render_helpers.rb
padrino-helpers-0.4.6 lib/padrino-helpers/render_helpers.rb
padrino-helpers-0.4.5 lib/padrino-helpers/render_helpers.rb