Skip to content

Instantly share code, notes, and snippets.

@angeliquejw
Forked from zandroid/paginate_helper.rb
Last active May 19, 2017 17:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save angeliquejw/f45349f08c2647bd82701249c4212141 to your computer and use it in GitHub Desktop.
Save angeliquejw/f45349f08c2647bd82701249c4212141 to your computer and use it in GitHub Desktop.
This is a custom link renderer that will format the pagination bar as an ordered list and with appropriate accessibility markup.
module PaginateHelper
class LinkRenderer < WillPaginate::ActionView::LinkRenderer
protected
def html_container(html)
tag(:nav, tag(:ol, html, class: "pagination-list"), class: "pagination", role: "navigation", "aria-label": "pagination navigation")
end
def previous_or_next_page(page, text, classname)
if page
tag(:li, link(text, page, class: "page-link"), class: "page-item")
else
tag(:li, tag(:a, text, class: "page-link", "aria-label": "Page #{text}"), class: "page-item is-disabled")
end
end
def page_number(page)
unless page == current_page
tag(:li, link(page, page, class: "page-link"), class: "page-item")
else
tag(:li, tag(:a, page, class: "page-link", "aria-label": "Current page", "aria-current": "true"), class: "page-item is-active")
end
end
def gap
tag(:li, tag(:a, '&hellip;', class: "page-link", "aria-hidden": "true"), class: "page-item is-disabled")
end
end ## end of class
def fa_will_paginate(collection = nil, options = {})
options, collection = collection, nil if collection.is_a? Hash
options = options.merge(
renderer: PaginateHelper::LinkRenderer
)
will_paginate(collection, options)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment