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

Bootstrap 4 support? #45

Open
gitviola opened this issue Jan 6, 2016 · 3 comments
Open

Bootstrap 4 support? #45

gitviola opened this issue Jan 6, 2016 · 3 comments

Comments

@gitviola
Copy link

gitviola commented Jan 6, 2016

Hi, are there any plans on supporting bootstrap 4?

http://v4-alpha.getbootstrap.com/components/pagination/

@gitviola gitviola changed the title Bootstrap 4 support Bootstrap 4 support? Jan 6, 2016
@Nikolay-Lipovtsev
Copy link

You can create pagination_helper.rb in you_app/assets/helpers/

require "will_paginate/view_helpers/action_view"

module PaginationHelper

  module BootstrapRenderer

    def to_html
      html = pagination.map do |item|
        item.is_a?(Fixnum) ?
          page_number(item) :
          send(item)
      end.join(@options[:link_separator])

      html = html_container(html) if @options[:container]

      tag("nav", tag("ul", html, class: @options[:class]))
    end

    protected

    def page_item(text, url, link_status = nil)
      text = text.to_s + tag(:span, "(current)", class: "sr-only") if link_status == "active"
      link_tag = link_status.nil? ? link(text, url, class: "page-link", rel: text) : tag(:span, text, class: "page-link")

      tag(:li, link_tag, class: "page-item #{link_status}")
    end

    def page_number(page)
      link_status = "active" if page == current_page
      page_item(page, page, link_status)
    end

    def gap
      text = @template.will_paginate_translate(:page_gap) { '…' }
      page_item(text, nil, "disabled")
    end

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

    def next_page
      num = @collection.current_page < total_pages && @collection.current_page + 1
      previous_or_next_page(num, @options[:next_label], "Next")
    end

    def previous_or_next_page(page, text, aria_label)
      link_status = "disabled" unless page
      page_item(text, page, link_status)
    end
  end
end

WillPaginate::ActionView::LinkRenderer.send :include, PaginationHelper::BootstrapRenderer

@delef
Copy link

delef commented Sep 29, 2016

https://github.com/delef/will_paginate-bootstrap4

@manueltorrez
Copy link

@delef you've just saved my day, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants