-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, '…', 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