Sha256: 0157589c4219836b16c41e0043b89a5dcadc92232f7ed7e5586025b9cab190e9

Contents?: true

Size: 1.65 KB

Versions: 32

Compression:

Stored size: 1.65 KB

Contents

<% # much of this paging code adopted from will_paginate plugin for view


  total_pages = (@hits / @batch_size)
  total_pages += 1 unless (@hits % @batch_size == 0)

  if total_pages > 1
    
    # Arguments for paging actions, just add 'page'
    args= params.clone
    # Need to take out that annoying legacy journal key, sorry.
    args.delete('journal')
    
    inner_window ||= 2 #how many links are shown on each side of current page
    outer_window ||= 2 #how many links are around the first and the last page
    
    min = @page - inner_window
    max = @page + inner_window
    
    # adjust lower or upper limit if other is out of bounds
    if max > total_pages
      min -= max - total_pages
    elsif min < 1 
      max += 1 - min
    end
    
    current   = min..max
    beginning = 1..(1 + outer_window)
    tail      = (total_pages - outer_window)..total_pages
    visible   = [beginning, current, tail].map(&:to_a).flatten.sort.uniq
    links, prev = [], 0
    
    visible.each do |n|
      next if n < 1
      break if n > total_pages
    
      unless n - prev > 1
        prev = n
        if ( n != @page )
           links << ( link_to n, args.merge({'page' => n }) )
        else
           links << ( content_tag :span, n )
        end
      else
        # ellipsis represents the gap between windows
        prev = n - 1
        links << '...'
        redo
      end
    end
    
    # Next and previous buttons
    links.unshift(link_to('Previous', args.merge({'page' => @page -1 }))) if @page > 1
    links.push(link_to('Next', args.merge({'page' => @page + 1}))) if @page < total_pages
%>
<%= content_tag :div, links.join(' ').html_safe %>
<%
  end
%>

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
umlaut-3.0.5 app/views/search/_pager.html.erb
umlaut-3.0.4 app/views/search/_pager.html.erb
umlaut-3.0.3 app/views/search/_pager.html.erb
umlaut-3.0.2 app/views/search/_pager.html.erb
umlaut-3.0.1 app/views/search/_pager.html.erb
umlaut-3.0.0 app/views/search/_pager.html.erb
umlaut-3.0.0rc1 app/views/search/_pager.html.erb
umlaut-3.0.0beta10 app/views/search/_pager.html.erb
umlaut-3.0.0beta9 app/views/search/_pager.html.erb
umlaut-3.0.0beta8 app/views/search/_pager.html.erb
umlaut-3.0.0beta7 app/views/search/_pager.html.erb
umlaut-3.0.0beta6 app/views/search/_pager.html.erb
umlaut-3.0.0beta5 app/views/search/_pager.html.erb
umlaut-3.0.0beta4 app/views/search/_pager.html.erb
umlaut-3.0.0beta3 app/views/search/_pager.html.erb
umlaut-3.0.0beta2 app/views/search/_pager.html.erb
umlaut-3.0.0beta1 app/views/search/_pager.html.erb
umlaut-3.0.0alpha15 app/views/search/_pager.html.erb
umlaut-3.0.0alpha14 app/views/search/_pager.html.erb
umlaut-3.0.0alpha13 app/views/search/_pager.html.erb