Last active
August 29, 2015 14:20
-
-
Save jkcorrea/050fd220999afb72210d to your computer and use it in GitHub Desktop.
Extend will_paginate to work with Materialize
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
# config/initializers/will_paginate.rb | |
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) | |
c = classname[0..3] | |
tag :li, | |
link(tag(:i, nil, class: "mdi-navigation-chevron-#{c == 'next' ? 'right' : 'left'}"), page || '#!'), | |
class: [c, classname, ('disabled' unless page)].join(' ') | |
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
I fixed it by replacing the content of the will_paginate method with this: