Giter VIP home page Giter VIP logo

Comments (3)

delef avatar delef commented on July 20, 2024 19

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

from will_paginate-bootstrap.

Nikolay-Lipovtsev avatar Nikolay-Lipovtsev commented on July 20, 2024 3

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

from will_paginate-bootstrap.

manueltorrez avatar manueltorrez commented on July 20, 2024 2

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

from will_paginate-bootstrap.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.