Sha256: 827c9b896fb98b45a10fd93979147d2cf4c6ae9edf7539fdd0eb65174a164913

Contents?: true

Size: 1.46 KB

Versions: 8

Compression:

Stored size: 1.46 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 }
      #   partial 'photo/item', :engine => :erb
      #
      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]}"
        explicit_engine = options.delete(:engine)
        template_path = File.join(path).to_sym
        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.map { |member|
            counter += 1
            options[:locals].merge!(object_name => member, "#{object_name}_counter".to_sym => counter)
            render(explicit_engine, template_path, options.dup)
          }.join("\n")
        else
          if member = options.delete(:object)
            options[:locals].merge!(object_name => member)
          end
          render(explicit_engine, template_path, options.dup)
        end
      end
      alias :render_partial :partial
    end # RenderHelpers
  end # Helpers
end # Padrino

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
middleman-2.0.7 lib/middleman/vendor/padrino-helpers-0.10.0/lib/padrino-helpers/render_helpers.rb
middleman-2.0.6 lib/middleman/vendor/padrino-helpers-0.10.0/lib/padrino-helpers/render_helpers.rb
middleman-2.0.5 lib/middleman/vendor/padrino-helpers-0.10.0/lib/padrino-helpers/render_helpers.rb
padrino-helpers-0.10.1 lib/padrino-helpers/render_helpers.rb
padrino-helpers-0.10.0 lib/padrino-helpers/render_helpers.rb
padrino-helpers-0.9.29 lib/padrino-helpers/render_helpers.rb
padrino-helpers-0.9.28 lib/padrino-helpers/render_helpers.rb
padrino-helpers-0.9.27 lib/padrino-helpers/render_helpers.rb