Skip to content

Instantly share code, notes, and snippets.

@cspeer
Last active June 28, 2017 22:22
Show Gist options
  • Save cspeer/cf0861fbfff83a4f65e6 to your computer and use it in GitHub Desktop.
Save cspeer/cf0861fbfff83a4f65e6 to your computer and use it in GitHub Desktop.
Will Paginate Semantic UI Renderer
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
@cspeer
Copy link
Author

cspeer commented May 10, 2014

Just save as Rails initializer and it's done :)

@Abdenasser
Copy link

awesome (Y)

@timkleier
Copy link

Excellent solution!

@gilderlan
Copy link

Thank you.

@rramirez0203
Copy link

Thanks!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment