lib/will_paginate/view_helpers/default_page_number_renderer.rb
# Calculates visible page numbers using the <tt>:inner_window</tt> and
# <tt>:outer_window</tt> options.
Calculates visible page numbers using the :inner_window and
:outer_window options.
Calculates visible page numbers using the : inner_window and : outer_window options .
def 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
          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
          middle = window_from..window_to
          if outer_window + 3 < middle.first 
            left = (1..(outer_window + 1)).to_a
            left << :gap
            left << ((outer_window + 1 + middle.first)/2).floor
            left << :gap
          else 
            left = 1...middle.first
          end
          if @total_pages - outer_window - 2 > middle.last 
            right = ((@total_pages - outer_window)..@total_pages).to_a
            right.unshift :gap
            right.unshift ((@total_pages - outer_window + middle.last)/2).floor
            right.unshift :gap
          else 
            right = (middle.last + 1)..@total_pages  
          end
          left.to_a + middle.to_a + right.to_a
        end
def 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 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 middle = window_from .. window_to if outer_window + 3 < middle . first left = ( 1 .. ( outer_window + 1 ) ) . to_a left << :gap left << ( ( outer_window + 1 + middle . first ) / 2 ) . floor left << :gap else left = 1 ... middle . first end if @total_pages - outer_window - 2 > middle . last right = ( ( @total_pages - outer_window ) .. @total_pages ) . to_a right . unshift :gap right . unshift ( ( @total_pages - outer_window + middle . last ) / 2 ) . floor right . unshift :gap else right = ( middle . last + 1 ) .. @total_pages end left . to_a + middle . to_a + right . to_a end
Calculates visible page numbers using the <tt>:inner_window</tt> and
<tt>:outer_window</tt> options.
Calculates visible page numbers using the <tt > : inner_window< / tt > and <tt > : outer_window< / tt > options .
# adjust lower or upper limit if either is out of bounds # these are always visible # left window # there's a gap # runs into visible pages # right window # again, gap # runs into visible pages