Module: NitroKit::PaginationHelper

Includes:
Pagy::UrlHelpers
Defined in:
app/helpers/nitro_kit/pagination_helper.rb

Instance Method Summary collapse

Instance Method Details

#nk_pagination(**attrs, &block) ⇒ Object



7
8
9
# File 'app/helpers/nitro_kit/pagination_helper.rb', line 7

def nk_pagination(**attrs, &block)
  render(Pagination.from_template(**attrs), &block)
end

#nk_pagy_nav(pagy, id: nil, aria_label: nil, **attrs) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/helpers/nitro_kit/pagination_helper.rb', line 11

def nk_pagy_nav(pagy, id: nil, aria_label: nil, **attrs)
  attrs[:aria] ||= { label: aria_label }

  nk_pagination(id:, **attrs) do |p|
    if prev_page = pagy.prev
      p.prev(href: pagy_url_for(pagy, prev_page))
    else
      p.prev(disabled: true)
    end

    pagy.series.each do |item|
      case item
      when Integer
        p.page(item.to_s, href: pagy_url_for(pagy, item))
      when String
        p.page(item, current: true)
      when :gap
        p.ellipsis
      else
        raise ArgumentError, "Unknown item type: #{item.class}"
      end
    end

    if next_page = pagy.next
      p.next(href: pagy_url_for(pagy, next_page))
    else
      p.next(disabled: true)
    end
  end
end