Skip to content

Commit 6f9a36c

Browse files
committed
[#85679260] add bootstrap pagination
1 parent 39b9e59 commit 6f9a36c

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

lib/liquid-rails/filters/misc_filter.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,37 @@ def default_pagination(paginate)
4040
html << %(<span class="next">#{link_to(paginate['next']['title'], paginate['next']['url'])}</span>) if paginate['next']
4141
html.join(' ')
4242
end
43+
44+
def bootstrap_pagination(paginate, size="")
45+
html = []
46+
nav_ele = %{<nav><ul class="pagination #{size}">}
47+
html << nav_ele
48+
49+
if paginate['previous']
50+
html << %(<li><a href="#{paginate['previous']['url']}" aria-label="Previous"><span aria-hidden="true"> #{paginate['previous']['title']}</span></a></li>)
51+
else
52+
html << %(<li class="disabled"><a href="#" aria-label="Previous"><span aria-hidden="true">&laquo; Previous</span></a></li>)
53+
end
54+
55+
for part in paginate['parts']
56+
if part['is_link']
57+
html << %(<li><a href="#{part['url']}">#{part['title']}</a></li>)
58+
elsif part['hellip_break']
59+
html << %(<li><a href="#">#{part['title']}</a></li>)
60+
else
61+
html << %(<li class="active"><a href="#">#{part['title']}</a></li>)
62+
end
63+
end
64+
65+
if paginate['next']
66+
html << %(<li><a href="#{paginate['next']['url']}" aria-label="Next"><span aria-hidden="true">#{paginate['next']['title']}</span></a></li>)
67+
else
68+
html << %(<li class="disabled"><a href="#" aria-label="Next"><span aria-hidden="true">Next &raquo;</span></a></li>)
69+
end
70+
71+
html << '</nav></ul>'
72+
html.join(' ')
73+
end
4374
end
4475
end
4576
end

lib/liquid-rails/tags/paginate_tag.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def render(context)
5454
pagination['pages'] = page_count
5555
pagination['items'] = paginated_collection.total_count
5656
pagination['previous'] = link('&laquo; Previous'.html_safe, current_page-1 ) unless 1 >= current_page
57-
pagination['next'] = link('Next &raquo;'.html_safe, current_page+1 ) unless page_count <= current_page+1
57+
pagination['next'] = link('Next &raquo;'.html_safe, current_page+1 ) unless page_count < current_page+1
5858
pagination['parts'] = []
5959

6060
hellip_break = false

0 commit comments

Comments
 (0)