gabriel / musehub public
pagination.html html
67 lines 2.3 KB
Raw
sha256:3c58668648c7323bb9f5c6881cfe6a3f14fc93fcb73b537d253732952a5bf8bf chore: bump version to 0.2.0rc12 Sonnet 4.6 patch 8 days ago
1 {#
2 pagination — renders numbered page navigation (Prev / Next) for offset-based pages.
3
4 Shows a "Prev" link when page > 1 and a "Next →" link when page < total_pages.
5 Renders nothing when total_pages <= 1 (no navigation required).
6
7 Parameters
8 ----------
9 page : int
10 Current 1-based page number.
11 total_pages : int
12 Total number of pages.
13 url : str
14 Base URL for page links (without query string). Page number is appended
15 as ``?page=N``.
16
17 Usage
18 -----
19 {% from "musehub/macros/pagination.html" import pagination %}
20 {{ pagination(page=current_page, total_pages=total_pages, url="/owner/repo/symbols") }}
21 #}
22 {% macro pagination(page, total_pages, url) %}
23 {% if total_pages > 1 %}
24 <nav class="pagination" aria-label="Pagination">
25 {% if page > 1 %}
26 <a class="btn btn-ghost btn-sm" href="{{ url }}?page={{ page - 1 }}">← Prev</a>
27 {% endif %}
28 <span class="pagination-info">Page {{ page }} of {{ total_pages }}</span>
29 {% if page < total_pages %}
30 <a class="btn btn-ghost btn-sm" href="{{ url }}?page={{ page + 1 }}">Next →</a>
31 {% endif %}
32 </nav>
33 {% endif %}
34 {% endmacro %}
35
36
37 {#
38 cursor_pagination — renders cursor-based page navigation (Next →).
39
40 Shows a "Next →" link when more items exist (next_cursor is not None).
41 Renders nothing when next_cursor is None (last page) so callers never
42 need to guard against it.
43
44 Parameters
45 ----------
46 next_cursor : str | None
47 Opaque cursor token from the server. Pass as ``?cursor=`` on the
48 next request. ``None`` means this is the last page.
49 url : str
50 Base URL for page links (without query string).
51 extra_params : dict[str, str]
52 Additional query-string parameters to preserve across page links
53 (e.g. {"q": search_term, "state": active_state}). Defaults to {}.
54
55 Usage
56 -----
57 {% from "musehub/macros/pagination.html" import cursor_pagination %}
58 {{ cursor_pagination(next_cursor, url="/owner/repo/sessions",
59 extra_params={"q": q}) }}
60 #}
61 {% macro cursor_pagination(next_cursor, url, extra_params={}) %}
62 {% if next_cursor %}
63 <nav class="pagination" aria-label="Pagination">
64 <a class="btn btn-ghost btn-sm" href="{{ url }}?cursor={{ next_cursor | urlencode }}{% for k,v in extra_params.items() %}&{{ k }}={{ v }}{% endfor %}">Next →</a>
65 </nav>
66 {% endif %}
67 {% endmacro %}
File History 1 commit
sha256:35d76015db2541686c33edd44343ea2d9f751325b4a5556cc9c4c9c0f84edbbe chore: bump version to 0.2.0rc12 Sonnet 4.6 patch 6 days ago