Skip to content

Instantly share code, notes, and snippets.

@Jake-Day-Williams
Last active November 17, 2017 03:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jake-Day-Williams/6e7f6b7aebf1dd9e05fffea14fd5c5ae to your computer and use it in GitHub Desktop.
Save Jake-Day-Williams/6e7f6b7aebf1dd9e05fffea14fd5c5ae to your computer and use it in GitHub Desktop.
How to get will_paginate to work with materialize
# 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) { '&hellip;' }
%(<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