-
Notifications
You must be signed in to change notification settings - Fork 160
/
Copy pathbootstrap_renderer.rb
66 lines (53 loc) · 1.66 KB
/
bootstrap_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
57
58
59
60
61
62
63
64
65
66
require "bootstrap_pagination/version"
module BootstrapPagination
# Contains functionality shared by all renderer classes.
module BootstrapRenderer
ELLIPSIS = "…"
def to_html
list_items = pagination.map do |item|
case item
when Fixnum
page_number(item)
else
send(item)
end
end.join(@options[:link_separator])
tag("ul", list_items, class: ul_class)
end
def container_attributes
super.except(*[:link_options])
end
protected
def page_number(page)
link_options = @options[:link_options] || {}
if page == current_page
tag("li", tag("span", page), class: "active")
else
tag("li", link(page, page, link_options.merge(rel: rel_value(page))))
end
end
def previous_or_next_page(page, text, classname)
link_options = @options[:link_options] || {}
if page
tag("li", link(text, page, link_options), class: classname)
else
tag("li", tag("span", text), class: "%s disabled" % classname)
end
end
def gap
tag("li", tag("span", ELLIPSIS), class: "disabled")
end
def previous_page
num = @collection.current_page > 1 && @collection.current_page - 1
previous_or_next_page(num, @options[:previous_label], "previous")
end
def next_page
num = @collection.current_page < @collection.total_pages && @collection.current_page + 1
previous_or_next_page(num, @options[:next_label], "next")
end
def ul_class
base_class = (@options[:page_links]) ? "pagination" : "pager"
[base_class, @options[:class]].compact.join(" ")
end
end
end