Home > Rails > Bootstrap2 style will_paginate

Bootstrap2 style will_paginate

# config/initializers/will_paginate.rb

require 'will_paginate/view_helpers/action_view'

module WillPaginate
  module ActionView
    def will_paginate(collection = nil, options = {})
      options, collection = collection, nil if collection.is_a? Hash

      collection ||= infer_collection_from_controller
      options[:renderer] ||= BootstrapLinkRenderer
      options[:class] = 'pagination pagination-centered'
      options[:previous_label] = '< rel_value(page))
        else
          link(page, "#", :class => 'active')
        end
      end

      def gap
        tag (:li, link(super, '#'), :class => 'disabled')
      end

      def previous_page
        num = @collection.current_page > 1 && @collection.current_page - 1
        previous_or_next_page(num, @options[:previous_label], @options[:previous_page_class])
      end

      def next_page
        num = @collection.current_page < @collection.total_pages && @collection.current_page + 1         previous_or_next_page(num, @options[:next_label], @options[:next_page_class])       end       def previous_or_next_page(page, text, classname)         if page           link(text, page)         else           link(text, "#", :class => 'disabled')
        end
      end

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

      private

      def link(text, target, attributes = {})
        if target.is_a? Fixnum
          attributes[:rel] = rel_value(target)
          target = url(target)
        end

        unless target == "#"
          attributes[:href] = target
        end

        classname = attributes[:class]
        attributes.delete(:classname)
        attributes.delete(:class)
        tag(:li, tag(:a, text, attributes), :class => classname)
      end

    end
  end
end

 

For more info ;

https://github.com/yrgoldteeth/bootstrap-will_paginate/blob/master/config/initializers/will_paginate.rb

https://github.com/mislav/will_paginate/issues/158

 

Advertisements
Categories: Rails Tags: , ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: