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 373
373: def initialize(page, padding=2)
374: @paginator = page.paginator
375: @page = page
376: self.padding = padding
377: 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 382
382: def padding=(padding)
383: @padding = padding < 0 ? 0 : padding
384: # Find the beginning and end pages of the window
385: @first = @paginator.has_page_number?(@page.number - @padding) ?
386: @paginator[@page.number - @padding] : @paginator.first
387: @last = @paginator.has_page_number?(@page.number + @padding) ?
388: @paginator[@page.number + @padding] : @paginator.last
389: 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 393
393: def pages
394: (@first.number..@last.number).to_a.collect! {|n| @paginator[n]}
395: end
Alias for pages