forked from openHPI/xikolo-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpagination_renderer.rb
56 lines (46 loc) · 1.41 KB
/
pagination_renderer.rb
1
2
3
4
5
6
7
8
9
10
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# frozen_string_literal: true
# This self-made tag building thing is no standard Rails rendering
# context, the recommended context tag changes do not work here:
#
# rubocop:disable Rails/ContentTag
class PaginationRenderer < WillPaginate::ActionView::LinkRenderer
include ActionView::Helpers::OutputSafetyHelper
protected
def page_number(page)
if page == current_page
tag(:li, tag(:a, 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(:a, text), class: "#{classname} disabled")
end
end
def html_container(html)
tag(:div, tag(:ul, html, container_attributes), class: 'pinboard-paginate')
end
def gap
tag(:li, tag(:a, '…'), class: 'disabled')
end
def previous_page
previous_or_next_page(
@collection.current_page > 1 && (@collection.current_page - 1),
'<span class="xi-icon fa-regular fa-chevron-left mr5"></span>' \
"#{I18n.t(:'pinboard.pagination.previous')}",
''
)
end
def next_page
previous_or_next_page(
@collection.current_page < total_pages && (@collection.current_page + 1),
"#{I18n.t(:'pinboard.pagination.next')}" \
'<span class="xi-icon fa-regular fa-chevron-right ml5"></span>',
''
)
end
end
# rubocop:enable all