Sha256: 3fb31ed6e434ada352671b4efa1d27689fa3d87e56bab433da53c63d723c4891

Contents?: true

Size: 1.82 KB

Versions: 13

Compression:

Stored size: 1.82 KB

Contents

require 'will_paginate/view_helpers/action_view'

module Binco
  class PaginationRenderer < WillPaginate::ActionView::LinkRenderer
    ELLIPSIS = '&hellip;'

    def to_html
      list_items = pagination.map do |item|
        case item
          when Fixnum
            page_number(item)
          else
            send(item)
        end
      end.join(@options[:link_separator])

      list_wrapper = tag :ul, list_items, class: 'pagination', role: 'group'
      tag :nav, list_wrapper, class: @options[:class]
    end

    def container_attributes
      super.except(*[:link_options])
    end

    protected

    def page_number(page)
      link_options = @options[:link_options] || {}

      if page == current_page
        tag :li, tag(:span, page, class: 'page-link'), class: 'page-item active'
      else
        link_options.merge! class: 'page-link', rel: rel_value(page)
        tag :li, link(page, page, link_options), class: 'page-item'
      end
    end

    def previous_or_next_page(page, text, classname)
      link_options = @options[:link_options] || {}

      if page
        link_wrapper = link(text, page, link_options.merge(class: 'page-link'))
        tag :li, link_wrapper, class: '%s page-item' % classname
      else
        span_wrapper = tag(:span, text, class: 'page-link')
        tag :li, span_wrapper, class: '%s page-item disabled' % classname
      end
    end

    def gap
      tag :li, tag(:i, ELLIPSIS, class: 'page-link'), class: 'page-item disabled'
    end

    def previous_page
      num = @collection.current_page > 1 && @collection.current_page - 1
      previous_or_next_page num, @options[:previous_label], 'previous'
    end

    def next_page
      num = @collection.current_page < @collection.total_pages && @collection.current_page + 1
      previous_or_next_page num, @options[:next_label], 'next'
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
binco-3.4.0 app/helpers/binco/pagination_renderer.rb
binco-3.3.0 app/helpers/binco/pagination_renderer.rb
binco-3.2.1 app/helpers/binco/pagination_renderer.rb
binco-3.2.0 app/helpers/binco/pagination_renderer.rb
binco-3.1.6 app/helpers/binco/pagination_renderer.rb
binco-3.1.5 app/helpers/binco/pagination_renderer.rb
binco-3.1.4 app/helpers/binco/pagination_renderer.rb
binco-3.1.3 app/helpers/binco/pagination_renderer.rb
binco-3.1.2 app/helpers/binco/pagination_renderer.rb
binco-3.1.1 app/helpers/binco/pagination_renderer.rb
binco-3.1.0 app/helpers/binco/pagination_renderer.rb
binco-3.0.2 app/helpers/binco/pagination_renderer.rb
binco-3.0.1 app/helpers/binco/pagination_renderer.rb