Last active
September 26, 2017 21:55
-
-
Save zandroid/8ed85b518fd3ce441f0864477aa7eb86 to your computer and use it in GitHub Desktop.
This is a custom link renderer that will format the pagination bar with Bootstrap4
This file contains hidden or 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(:ul, html, class: "pagination")) | |
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"), class: "page-item 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"), class: "page-item active") | |
end | |
end | |
def gap | |
tag(:li, tag(:a, '…', class: "page-link"), class: "page-item disabled") | |
end | |
end ## end of class | |
def bs_will_paginate(collection = nil, options = {}) | |
options, collection = collection, nil if collection.is_a? Hash | |
options = options.merge( | |
renderer: PaginateHelper::LinkRenderer, | |
previous_label: "«", | |
next_label: "»" | |
) | |
will_paginate(collection, options) | |
end | |
end |
Thanks! It works perfectly.
Works great! 👍 Thanks!
Great work!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example of usage: just
bs_will_paginate
orbs_will_paginate @users