Sha256: ea2102f6dbdbf687bac680e1fcc1cad5f61988587d25ae8b54221f2ccaf0d56d

Contents?: true

Size: 1.34 KB

Versions: 17

Compression:

Stored size: 1.34 KB

Contents

module Padrino
  module Helpers
    module RenderHelpers
      ##
      # Partials implementation which includes collections support
      #
      # ==== Examples
      #
      #   partial 'photo/item', :object => @photo
      #   partial 'photo/item', :collection => @photos
      #   partial 'photo/item', :locals => { :foo => :bar }
      #
      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 { |member|
            counter += 1
            options[:locals].merge!(object_name => member, "#{object_name}_counter".to_sym => counter)
            render(template_path, nil, options.dup)
          }.join("\n")
        else
          if member = options.delete(:object)
            options[:locals].merge!(object_name => member)
          end
          render(template_path, nil, options.dup)
        end
      end
      alias :render_partial :partial
    end # RenderHelpers
  end # Helpers
end # Padrino

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
padrino-helpers-0.9.24 lib/padrino-helpers/render_helpers.rb
padrino-helpers-0.9.23 lib/padrino-helpers/render_helpers.rb
padrino-helpers-0.9.22 lib/padrino-helpers/render_helpers.rb
padrino-helpers-0.9.21 lib/padrino-helpers/render_helpers.rb
padrino-helpers-0.9.20 lib/padrino-helpers/render_helpers.rb
padrino-helpers-0.9.19 lib/padrino-helpers/render_helpers.rb
padrino-helpers-0.9.18 lib/padrino-helpers/render_helpers.rb
padrino-helpers-0.9.17 lib/padrino-helpers/render_helpers.rb
padrino-helpers-0.9.16 lib/padrino-helpers/render_helpers.rb
padrino-helpers-0.9.15 lib/padrino-helpers/render_helpers.rb
padrino-helpers-0.9.14 lib/padrino-helpers/render_helpers.rb
padrino-helpers-0.9.13 lib/padrino-helpers/render_helpers.rb
padrino-helpers-0.9.12 lib/padrino-helpers/render_helpers.rb
padrino-helpers-0.9.11 lib/padrino-helpers/render_helpers.rb
padrino-helpers-0.9.10 lib/padrino-helpers/render_helpers.rb
padrino-helpers-0.9.9 lib/padrino-helpers/render_helpers.rb
padrino-helpers-0.9.7 lib/padrino-helpers/render_helpers.rb