A class for representing ranges around a given page.
Methods
Attributes
| [R] | first | |
| [R] | last | |
| [R] | padding | |
| [R] | page | |
| [R] | paginator |
Public Class methods
Creates a new Window object for the given page with the specified padding.
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/pagination.rb, line 367
367: def initialize(page, padding=2)
368: @paginator = page.paginator
369: @page = page
370: self.padding = padding
371: end
Public Instance methods
Sets the window’s padding (the number of pages on either side of the window page).
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/pagination.rb, line 376
376: def padding=(padding)
377: @padding = padding < 0 ? 0 : padding
378: # Find the beginning and end pages of the window
379: @first = @paginator.has_page_number?(@page.number - @padding) ?
380: @paginator[@page.number - @padding] : @paginator.first
381: @last = @paginator.has_page_number?(@page.number + @padding) ?
382: @paginator[@page.number + @padding] : @paginator.last
383: end
Returns an array of Page objects in the current window.
This method is also aliased as
to_a
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/pagination.rb, line 387
387: def pages
388: (@first.number..@last.number).to_a.collect! {|n| @paginator[n]}
389: end
Alias for pages