Sha256: 91d4d0662a4cdeca06b97dfaafa62671a8caf2dcd95ddf36737ced707093ccbd

Contents?: true

Size: 1.28 KB

Versions: 2

Compression:

Stored size: 1.28 KB

Contents

# frozen_string_literal: true

require "will_paginate/view_helpers/action_view"

module Playbook
  module Pagination
    class Rails < WillPaginate::ActionView::LinkRenderer
      def container_attributes
        { class: "pb_pagination" }
      end

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

      def previous_or_next_page(page, text, classname)
        if page
          tag("li", link(text, page), class: classname)
        else
          tag("li", tag("span", text), class: "%s disabled")
        end
      end

      def gap; end

      def previous_page
        num = @collection.current_page > 1 && @collection.current_page - 1
        previous_or_next_page(
          num,
          "<i> pb_rails('icon', props: { icon: 'chevron-left', fixed_width: true, size: 'xs' }) </i>",
          "prev"
        )
      end

      def next_page
        num = @collection.current_page < @collection.total_pages && @collection.current_page + 1
        previous_or_next_page(
          num,
          "<i> pb_rails('icon', props: { icon: 'chevron-right', fixed_width: true, size: 'xs' }) </i>",
          "next"
        )
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
playbook_ui-14.4.0.pre.alpha.PLAY1529removefaeasy3898 lib/playbook/pagination_renderer.rb
playbook_ui-14.4.0.pre.alpha.PLAY1529removefaeasy3876 lib/playbook/pagination_renderer.rb