Class: Listpress::PaginateRenderer

Inherits:
WillPaginate::ActionView::LinkRenderer
  • Object
show all
Defined in:
lib/listpress/paginate_renderer.rb

Instance Method Summary collapse

Instance Method Details

#html_container(html) ⇒ Object



6
7
8
# File 'lib/listpress/paginate_renderer.rb', line 6

def html_container(html)
  tag(:nav, tag(:ul, html, class: "pagination"))
end


36
37
38
39
40
41
42
43
44
# File 'lib/listpress/paginate_renderer.rb', line 36

def link(text, target, attributes = {})
  if target.is_a?(Integer)
    attributes[:rel] = rel_value(target)
    target = url(target)
  end
  attributes[:href] = target
  attributes[:class] = 'page-link'
  tag(:a, text, attributes)
end

#next_pageObject



23
24
25
26
# File 'lib/listpress/paginate_renderer.rb', line 23

def next_page
  num = @collection.current_page < total_pages && @collection.current_page + 1
  previous_or_next_page(num, "<i class=\"fas fa-chevron-right\"></i>")
end

#page_number(page) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/listpress/paginate_renderer.rb', line 10

def page_number(page)
  if page == current_page
    "<li class=\"page-item active\">" + link(page, page, rel: rel_value(page), "data-page": page) + "</li>"
  else
    "<li class=\"page-item\">" + link(page, page, rel: rel_value(page), "data-page": page) + "</li>"
  end
end

#previous_or_next_page(page, text) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/listpress/paginate_renderer.rb', line 28

def previous_or_next_page(page, text)
  if page
    "<li class=\"page-item\">" + link(text, page, "data-page": page) + "</li>"
  else
    "<li class=\"page-item disabled\"><span class=\"page-link\">" + text + "</span></li>"
  end
end

#previous_pageObject



18
19
20
21
# File 'lib/listpress/paginate_renderer.rb', line 18

def previous_page
  num = @collection.current_page > 1 && @collection.current_page - 1
  previous_or_next_page(num, "<i class=\"fas fa-chevron-left\"></i>")
end