Class: Borges::BatchedList

# Borges::BatchedList (Class)

In: | lib/Borges/Component/BatchedList.rb
Parent: | Object

A BatchedList paginates a list of items.

The user must render the currently displayed list and the page bar.

Example:

class MyList < Borges::Component

      def initialize(items)
        @batcher = Borges::BatchedList.new(items)
      end

      def choose(item)
        call(MyView.new(item)) # MyView is a component that views the item.
      end

      def renderContentOn(r)
        r.list_do(@batcher.batch) do |item|
          r.anchor(item.title do choose(item) end
        end

        r.render(@batcher)
      end

end

## Methods

batch end_index max_pages new next_page on_first_page? on_last_page? previous_page render_content_on start_index

## Constants

DEFAULT_SIZE | = | 10

## Attributes

batch_size | [RW] |
current_page | [RW] |
items | [RW] |

## Public Class methods

new(items = [], size = DEFAULT_SIZE)

Create a new BatchedList from `items`, with `size` items per page.

## Public Instance methods

batch()

The batch of items on the current page

end_index()

The index of the last item from the batch on the current page.

max_pages()

The maximum number of pages (indexed from 1)

next_page()

Move to the next page in the batch.

on_first_page?()

Is the first page in the batch being displayed?

on_last_page?()

Is the last page in the batch being displayed?

previous_page()

Move to the previous page in the batch.

render_content_on(r)

Render the page selector for the batch.

You must supply your own code to render the contents of the batch. See StoreItemList for an example.

start_index()

The index of the first item from the batch on the current page.

[Validate]