Class: WillPaginate::ViewHelpers::LinkRendererBase

### Home Classes Methods

### In Files

- lib/will_paginate/view_helpers/link_renderer_base.rb

### Parent

Object

### Methods

- #pagination
- #prepare
- #windowed_page_numbers

### Class/Module Index

Quicksearch

- WillPaginate
- WillPaginate::ActionView
- WillPaginate::ActionView::LinkRenderer
- WillPaginate::ActiveRecord
- WillPaginate::ActiveRecord::BaseMethods
- WillPaginate::ActiveRecord::Pagination
- WillPaginate::ActiveRecord::RelationMethods
- WillPaginate::Collection
- WillPaginate::CollectionMethods
- WillPaginate::DataMapper
- WillPaginate::DataMapper::CollectionMethods
- WillPaginate::DataMapper::Pagination
- WillPaginate::Deprecation
- WillPaginate::Deprecation::Hash
- WillPaginate::I18n
- WillPaginate::InvalidPage
- WillPaginate::Merb
- WillPaginate::Merb::LinkRenderer
- WillPaginate::PageNumber
- WillPaginate::PerPage
- WillPaginate::PerPage::Inheritance
- WillPaginate::Railtie
- WillPaginate::Railtie::ControllerRescuePatch
- WillPaginate::Railtie::ShowExceptionsPatch
- WillPaginate::SequelMethods
- WillPaginate::Sinatra
- WillPaginate::Sinatra::Helpers
- WillPaginate::Sinatra::LinkRenderer
- WillPaginate::ViewHelpers
- WillPaginate::ViewHelpers::LinkRenderer
- WillPaginate::ViewHelpers::LinkRendererBase
- Array
- Object

No matching classes.

# WillPaginate::ViewHelpers::LinkRendererBase

This class does the heavy lifting of actually building the pagination links. It is used by `will_paginate` helper internally.

### Public Instance Methods

pagination() click to toggle source

    # File lib/will_paginate/view_helpers/link_renderer_base.rb, line 18
    def pagination
      items = @options[:page_links] ? windowed_page_numbers : []
      items.unshift :previous_page
      items.push :next_page
    end

prepare(collection, options) click to toggle source

- `collection` is a WillPaginate::Collection instance or any other object that conforms to that API

- `options` are forwarded from `will_paginate` view helper

    # File lib/will_paginate/view_helpers/link_renderer_base.rb, line 10
    def prepare(collection, options)
      @collection = collection
      @options    = options

      # reset values in case we're re-using this instance
      @total_pages = nil
    end

### Protected Instance Methods

windowed_page_numbers() click to toggle source

Calculates visible page numbers using the `:inner_window` and `:outer_window` options.

    # File lib/will_paginate/view_helpers/link_renderer_base.rb, line 28
    def windowed_page_numbers
      inner_window, outer_window = @options[:inner_window].to_i, @options[:outer_window].to_i
      window_from = current_page - inner_window
      window_to = current_page + inner_window

      # adjust lower or upper limit if other is out of bounds
      if window_to > total_pages
        window_from -= window_to - total_pages
        window_to = total_pages
      end
      if window_from < 1
        window_to += 1 - window_from
        window_from = 1
        window_to = total_pages if window_to > total_pages
      end

      # these are always visible
      middle = window_from..window_to

      # left window
      if outer_window + 3 < middle.first # there's a gap
        left = (1..(outer_window + 1)).to_a
        left << :gap
      else # runs into visible pages
        left = 1...middle.first
      end

      # right window
      if total_pages - outer_window - 2 > middle.last # again, gap
        right = ((total_pages - outer_window)..total_pages).to_a
        right.unshift :gap
      else # runs into visible pages
        right = (middle.last + 1)..total_pages
      end

      left.to_a + middle.to_a + right.to_a
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.