Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance/previous or next page #31

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ To use Bootstrap 4 version:

<%= will_paginate(@things, :renderer => WillPaginate::ActionView::Bootstrap4LinkRenderer) %>

To use Bootstrap 2 version:

<%= will_paginate(@things, :renderer => WillPaginate::ActionView::Bootstrap2LinkRenderer) %>

### Size and Alignment of the Pagination Component

You can easily change the pagination components' appearance by passing the correct Bootstrap classes as options:
Expand Down
42 changes: 40 additions & 2 deletions config/initializers/will_paginate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,24 @@ def html_container(html)
end

def page_number(page)
tag :li, link(page, page, :rel => rel_value(page)), :class => ('active' if page == current_page)
if page == current_page
tag :li, tag(:span, page), :class => 'active disabled'
else
tag :li, link(page, page, :rel => rel_value(page))
end
end

def gap
tag :li, link('&hellip;'.html_safe, '#'), :class => 'disabled'
end

def previous_or_next_page(page, text, classname)
tag :li, link(text, page || '#'), :class => [(classname[0..3] if @options[:page_links]), (classname if @options[:page_links]), ('disabled' unless page)].join(' ')
if page
tag :li, link(text, page),
:class => [(classname[0..3] if @options[:page_links]), (classname if @options[:page_links])].join(' ')
else
tag :li, tag(:span, text), :class => classname + ' disabled'
end
end

def ul_class
Expand Down Expand Up @@ -67,5 +76,34 @@ def ul_class
["pagination", container_attributes[:class]].compact.join(" ")
end
end

class Bootstrap2LinkRenderer < LinkRenderer
protected

def html_container(html)
tag :div, tag(:ul, html), container_attributes
end

def page_number(page)
if page == current_page
tag :li, tag(:span, page), :class => 'active disabled'
else
tag :li, link(page, page, :rel => rel_value(page))
end
end

def gap
tag :li, link('&hellip;'.html_safe, '#'), :class => 'disabled'
end

def previous_or_next_page(page, text, classname)
if page
tag :li, link(text, page),
:class => [(classname[0..3] if @options[:page_links]), (classname if @options[:page_links])].join(' ')
else
tag :li, tag(:span, text), :class => classname + ' disabled'
end
end
end
end
end