diff --git a/README.markdown b/README.markdown index 8620448..4fa6b7a 100644 --- a/README.markdown +++ b/README.markdown @@ -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: diff --git a/config/initializers/will_paginate.rb b/config/initializers/will_paginate.rb index 4a08a55..bd69a64 100644 --- a/config/initializers/will_paginate.rb +++ b/config/initializers/will_paginate.rb @@ -23,7 +23,11 @@ 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 @@ -31,7 +35,12 @@ def gap 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 @@ -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('…'.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