Last active
November 17, 2017 03:59
-
-
Save Jake-Day-Williams/6e7f6b7aebf1dd9e05fffea14fd5c5ae to your computer and use it in GitHub Desktop.
How to get will_paginate to work with materialize
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
# Working with Rails 5.1.3 | |
# With 'will_paginate', '~> 3.1', '>= 3.1.6' | |
# Simply put <%= will_paginate @collection %> in your view. | |
# Add the below to config/initializers/will_paginate.rb | |
# Restart server. | |
# Sip wine. | |
module WillPaginate | |
module ActionView | |
def will_paginate(collection = nil, options = {}) | |
options[:renderer] ||= MaterializeLinkRenderer | |
super.try :html_safe | |
end | |
class MaterializeLinkRenderer < LinkRenderer | |
protected | |
def html_container(html) | |
tag :ul, html, container_attributes | |
end | |
def page_number(page) | |
tag :li, | |
link(page, page, rel: rel_value(page)), | |
class: (page == current_page ? 'active' : 'waves-effect') | |
end | |
def previous_or_next_page(page, text, classname) | |
if classname == "previous_page" | |
tag :li, link('<i class="material-icons">chevron_left</i>', page || '#'), :class => ["waves-effect", classname, ('disabled' unless page)].join(' ') | |
else | |
tag :li, link('<i class="material-icons">chevron_right</i>', page || '#'), :class => ["waves-effect", classname, ('disabled' unless page)].join(' ') | |
end | |
end | |
def gap | |
text = @template.will_paginate_translate(:page_gap) { '…' } | |
%(<li><span class="gap">#{text}</span></li>) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment