module Hanami::Pagination::View

Public Instance Methods

current_page_tag() click to toggle source
# File lib/hanami/pagination/view.rb, line 60
def current_page_tag
  html.span(class: 'pagination-current-page') do
    pager.current_page
  end
end
ellipsis_tag() click to toggle source
# File lib/hanami/pagination/view.rb, line 78
def ellipsis_tag
  html.span(class: 'pagination-ellipsis') do
    '...'
  end
end
first_page_tag(page) click to toggle source
# File lib/hanami/pagination/view.rb, line 48
def first_page_tag(page)
  html.a(href: n_page_path(page, 1), class: 'pagination-first-page') do
    '1'
  end
end
last_page_tag(page) click to toggle source
# File lib/hanami/pagination/view.rb, line 66
def last_page_tag(page)
  html.a(href: n_page_path(page, pager.total_pages), class: 'pagination-last-page') do
    pager.total_pages
  end
end
n_page_path(page, n) click to toggle source
# File lib/hanami/pagination/view.rb, line 28
def n_page_path(page, n)
  routes.path(page, **params, page: n)
end
next_page_path(page) click to toggle source
# File lib/hanami/pagination/view.rb, line 24
def next_page_path(page)
  routes.path(page, **params, page: pager.next_page)
end
next_page_tag(page) click to toggle source
# File lib/hanami/pagination/view.rb, line 72
def next_page_tag(page)
  html.a(href: next_page_path(page), class: 'pagination-next-page') do
    pager.next_page
  end
end
next_page_url() click to toggle source
# File lib/hanami/pagination/view.rb, line 8
def next_page_url
  page_url(pager.next_page)
end
page_url(page) click to toggle source
# File lib/hanami/pagination/view.rb, line 16
def page_url(page)
  "#{params.env['REQUEST_PATH']}?page=#{page}"
end
paginate(page) click to toggle source
# File lib/hanami/pagination/view.rb, line 32
def paginate(page)
  html.nav(class: 'pagination') do
    content = []

    content << first_page_tag(page) unless pager.first_page?
    content << ellipsis_tag if pager.current_page > 3
    content << previous_page_tag(page) if pager.current_page > 2
    content << current_page_tag
    content << next_page_tag(page) if (pager.total_pages - pager.current_page) > 1
    content << ellipsis_tag if (pager.total_pages - pager.current_page) > 3
    content << last_page_tag(page) unless pager.last_page?

    raw(content.map(&:to_s).join)
  end
end
prev_page_url() click to toggle source
# File lib/hanami/pagination/view.rb, line 12
def prev_page_url
  page_url(pager.prev_page)
end
previous_page_path(page) click to toggle source
# File lib/hanami/pagination/view.rb, line 20
def previous_page_path(page)
  routes.path(page, **params, page: pager.prev_page)
end
previous_page_tag(page) click to toggle source
# File lib/hanami/pagination/view.rb, line 54
def previous_page_tag(page)
  html.a(href: previous_page_path(page), class: 'pagination-previous-page') do
    pager.prev_page
  end
end