Forked from cspeer/config_initializers_willPaginateRenderer.rb
Last active
August 29, 2015 14:20
-
-
Save chrise86/ae23691f183f80e4d916 to your computer and use it in GitHub Desktop.
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
require 'will_paginate/view_helpers/link_renderer' | |
module WillPaginate | |
module ViewHelpers | |
class LinkRenderer | |
protected | |
def page_number(page) | |
page == current_page ? tag(:span, page, class: 'active item') : link(page, page, class: 'item', rel: rel_value(page)) | |
end | |
def gap | |
tag(:span, '...', class: 'disabled item') | |
end | |
def previous_page | |
num = @collection.current_page > 1 && @collection.current_page - 1 | |
previous_or_next_page(:left, num) | |
end | |
def next_page | |
num = @collection.current_page < total_pages && @collection.current_page + 1 | |
previous_or_next_page(:right, num) | |
end | |
def previous_or_next_page(left_or_right, page) | |
class_names = 'icon item' | |
icon = tag(:i, '', class: "icon #{left_or_right} arrow") | |
page ? link(icon, page, class: class_names) : tag(:span, icon, class: class_names) | |
end | |
def html_container(html) | |
pagination = tag(:div, html, container_attributes.merge({ class: 'ui blue pagination menu' })) | |
tag(:div, pagination, class: 'ui center aligned basic segment') | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment