Skip to content

Commit

Permalink
add rel attribute for a link
Browse files Browse the repository at this point in the history
add new config file for docs build
  • Loading branch information
lixxu committed Oct 23, 2023
1 parent a37b21d commit 88e2617
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 32 deletions.
31 changes: 31 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Read the Docs configuration file for Sphinx projects
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

# Required
version: 2

# Set the OS, Python version and other tools you might need
build:
os: ubuntu-22.04
tools:
python: "3.11"

# Build documentation in the "docs/" directory with Sphinx
sphinx:
configuration: docs/conf.py
# You can configure Sphinx to use a different builder, for instance use the dirhtml builder for simpler URLs
# builder: "dirhtml"
# Fail on all warnings to avoid broken references
# fail_on_warning: true

# Optionally build your docs in additional formats such as PDF and ePub
# formats:
# - pdf
# - epub

# Optional but recommended, declare the Python requirements required
# to build your documentation
# See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
# python:
# install:
# - requirements: docs/requirements.txt
8 changes: 3 additions & 5 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
import os
import sys

sys.path.insert(
0, os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
)
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
sys.path.append(os.path.abspath("_themes"))

# If extensions (or modules to document with autodoc) are in another directory,
Expand Down Expand Up @@ -62,9 +60,9 @@
# built documents.
#
# The short X.Y version.
version = "2021.10.29"
version = "2023.10.24"
# The full version, including alpha/beta/rc tags.
release = "2021.10.29"
release = "2023.10.24"

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
41 changes: 34 additions & 7 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ flask-paginate |release| documentation

Overview
---------
Latest version: **2021.10.29**
Latest version: **2023.10.24**

**flask-paginate** is a simple paginate extension for
`flask`_ which is reference to `will_paginate`_,
and supports several css frameworks.

**2023.10.24 update**: **rel** parameters was added

**2021.10.26 update**: **bootstrap5** is now supported

**0.6.0 update**: `bulma`_ is now supported (use **css_framework** parameter)::
Expand Down Expand Up @@ -119,10 +121,11 @@ In your flask views file (e.g. views/users.py)::
# you can set PER_PAGE parameter in config file
# e.g. Pagination(per_page_parameter='pp')

return render_template('users/index.html',
users=users,
pagination=pagination,
)
return render_template(
"index.html",
users=users,
pagination=pagination,
)

In the **users/index.html**:

Expand Down Expand Up @@ -233,14 +236,18 @@ Below are the parameters for **Pagination.__init__()**. You can change the setti

**bulma_style**: page link style for bulma css framework

**prev_rel**: rel of previous page

**next_rel**: rel of next page

API
------------------

.. autoclass:: Pagination
:members:
:members:

.. toctree::
:maxdepth: 2
:maxdepth: 2


Contributors
Expand All @@ -266,6 +273,26 @@ Contributors

Changelog
---------
Version 2023.10.24
-------------

- add rel `issue 109 <https://github.com/lixxu/flask-paginate/issues/109>`

Version 2023.10.08
-------------

- fix typos `PR 104 <https://github.com/lixxu/flask-paginate/pull/104>`

Version 2022.01.08
-------------

- make `bs_version` only for bootstrap

Version 2021.12.28
-------------

- set `bs_version` to integer

Version 2021.10.29
-------------

Expand Down
2 changes: 1 addition & 1 deletion example/app.cfg.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PER_PAGE = 10
CSS_FRAMEWORK = "bootstrap3"
CSS_FRAMEWORK = "bootstrap5"
LINK_SIZE = "sm"

# decide whether or not a single page returns pagination
Expand Down
2 changes: 2 additions & 0 deletions example/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ def get_pagination(**kwargs):
link_size=get_link_size(),
alignment=get_alignment(),
show_single_page=show_single_page_or_not(),
prev_rel="prev",
next_rel="next prefetch",
**kwargs
)

Expand Down
67 changes: 48 additions & 19 deletions flask_paginate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,23 @@
from flask import current_app, request, url_for
from markupsafe import Markup

__version__ = "2023.10.08"
__version__ = "2023.10.24"

PY2 = sys.version_info[0] == 2

_bs = '<li class="previous"><a href="{0}">{1}</a></li>'
_bs33 = '<li><a href="{0}" aria-label="Previous">\
# previous link
_bs = '<li class="previous"><a href="{0}"{2}>{1}</a></li>'
_bs33 = '<li><a href="{0}" aria-label="Previous"{2}>\
<span aria-hidden="true">{1}</span></a></li>'
_bs4 = '<li class="page-item">\
<a class="page-link" href="{0}" aria-label="Previous">\
<a class="page-link" href="{0}" aria-label="Previous"{2}>\
<span aria-hidden="true">{1}</span>\
<span class="sr-only">Previous</span></a></li>'
_bs5 = '<li class="page-item">\
<a class="page-link" href="{0}" aria-label="Previous">\
<a class="page-link" href="{0}" aria-label="Previous"{2}>\
<span aria-hidden="true">{1}</span></a></li>'
_bulma = '<a class="pagination-previous" href={0} aria-label="Previous">{1}</a>'
_materialize = '<li class="waves-effect"><a href="{0}">\
_bulma = '<a class="pagination-previous" href={0} aria-label="Previous"{2}>{1}</a>'
_materialize = '<li class="waves-effect"><a href="{0}"{1}>\
<i class="material-icons">chevron_left</i></a></li>'

PREV_PAGES = dict(
Expand All @@ -43,24 +44,25 @@
bootstrap3_3=_bs33,
bootstrap4=_bs4,
bootstrap5=_bs5,
semantic='<a class="item arrow" href="{0}">{1}</a>',
foundation='<li class="arrow"><a href="{0}">{1}</a></li>',
semantic='<a class="item arrow" href="{0}"{2}>{1}</a>',
foundation='<li class="arrow"><a href="{0}"{2}>{1}</a></li>',
bulma=_bulma,
materialize=_materialize,
)

_bs = '<li class="next"><a href="{0}">{1}</a></li>'
_bs33 = '<li><a href="{0}" aria-label="Next">\
# next link
_bs = '<li class="next"><a href="{0}"{2}>{1}</a></li>'
_bs33 = '<li><a href="{0}" aria-label="Next"{2}>\
<span aria-hidden="true">{1}</span></a></li>'
_bs4 = '<li class="page-item">\
<a class="page-link" href="{0}" aria-label="Next">\
<a class="page-link" href="{0}" aria-label="Next"{2}>\
<span aria-hidden="true">{1}</span>\
<span class="sr-only">Next</span></a></li>'
_bs5 = '<li class="page-item">\
<a class="page-link" href="{0}" aria-label="Next">\
<a class="page-link" href="{0}" aria-label="Next"{2}>\
<span aria-hidden="true">{1}</span></a></li>'
_bulma = '<a class="pagination-next" href={0} aria-label="Next">{1}</a>'
_materialize = '<li class="waves-effect"><a href="{0}">\
_bulma = '<a class="pagination-next" href={0} aria-label="Next"{2}>{1}</a>'
_materialize = '<li class="waves-effect"><a href="{0}"{1}>\
<i class="material-icons">chevron_right</i></a></li>'
NEXT_PAGES = dict(
bootstrap=_bs,
Expand All @@ -69,12 +71,13 @@
bootstrap3_3=_bs33,
bootstrap4=_bs4,
bootstrap5=_bs5,
semantic='<a class="item arrow" href="{0}">{1}</a>',
foundation='<li class="arrow"><a href="{0}">{1}</a></li>',
semantic='<a class="item arrow" href="{0}"{2}>{1}</a>',
foundation='<li class="arrow"><a href="{0}"{2}>{1}</a></li>',
bulma=_bulma,
materialize=_materialize,
)

# current page
_bs = '<li class="active"><a>{0}</a></li>'
_bs33 = '<li class="active"><span>{0} \
<span class="sr-only">(current)</span></span></li>'
Expand All @@ -98,13 +101,15 @@
materialize=_materialize,
)

# normal link
LINK = '<li><a href="{0}">{1}</a></li>'
SEMANTIC_LINK = '<a class="item" href="{0}">{1}</a>'
BS4_LINK = '<li class="page-item"><a class="page-link" href="{0}">{1}</a></li>'
BS5_LINK = '<li class="page-item"><a class="page-link" href="{0}">{1}</a></li>'
BULMA_LINK = '<li><a class="pagination-link" href={0}>{1}</a></li>'
MATERIALIZE_LINK = '<li><a class="waves-effect" href="{0}">{1}</a></li>'

# disabled link
_bs = '<li class="disabled"><a>...</a></li>'
_bs33 = '<li class="disabled"><span>\
<span aria-hidden="true">...</span></span></li>'
Expand All @@ -127,6 +132,7 @@
materialize=_materialize,
)

# previous disabled link
_bs = '<li class="previous disabled unavailable"><a> {0} </a></li>'
_bs33 = '<li class="disabled"><span>\
<span aria-hidden="true">{0}</span></span></li>'
Expand All @@ -152,6 +158,7 @@
materialize=_materialize,
)

# next disabled link
_bs = '<li class="next disabled"><a> {0} </a></li>'
_bs33 = '<li class="disabled"><span>\
<span aria-hidden="true">{0}</span></span></li>'
Expand Down Expand Up @@ -335,6 +342,10 @@ def __init__(self, found=0, **kwargs):
**bulma_style**: page link style for bulma css framework
**prev_rel**: rel of previous page
**next_rel**: rel of next page
"""
self.found = found
page_parameter = kwargs.get("page_parameter")
Expand Down Expand Up @@ -409,6 +420,14 @@ def __init__(self, found=0, **kwargs):
if self.bulma_style:
self.bulma_style = " is-{0}".format(self.bulma_style)

self.prev_rel = kwargs.get("prev_rel", "")
if self.prev_rel:
self.prev_rel = ' rel="{}"'.format(self.prev_rel)

self.next_rel = kwargs.get("next_rel", "")
if self.next_rel:
self.next_rel = ' rel="{}"'.format(self.next_rel)

self.alignment = kwargs.get("alignment", "")
if self.alignment and self.css_framework.startswith("bootstrap"):
if self.css_framework in ("bootstrap4", "bootstrap5"):
Expand Down Expand Up @@ -496,15 +515,25 @@ def prev_page(self):
if self.has_prev:
page = self.page - 1 if self.page > 2 else None
url = self.page_href(page)
return self.prev_page_fmt.format(url, self.prev_label)
if self.css_framework == "materialize":
args = (url, self.prev_rel)
else:
args = (url, self.prev_label, self.prev_rel)

return self.prev_page_fmt.format(*args)

return self.prev_disabled_page_fmt.format(self.prev_label)

@property
def next_page(self):
if self.has_next:
url = self.page_href(self.page + 1)
return self.next_page_fmt.format(url, self.next_label)
if self.css_framework == "materialize":
args = (url, self.next_rel)
else:
args = (url, self.next_label, self.next_rel)

return self.next_page_fmt.format(*args)

return self.next_disabled_page_fmt.format(self.next_label)

Expand Down
5 changes: 5 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"""
import io
import os.path

from setuptools import setup

version = ""
Expand Down Expand Up @@ -45,5 +46,9 @@
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
],
)

0 comments on commit 88e2617

Please sign in to comment.