diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7d44098 --- /dev/null +++ b/.gitignore @@ -0,0 +1,59 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +env/ +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +*.egg-info/ +.installed.cfg +*.egg + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*,cover +.hypothesis/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ diff --git a/flask_nav/elements.py b/flask_nav/elements.py index dd1ad59..752a3b7 100644 --- a/flask_nav/elements.py +++ b/flask_nav/elements.py @@ -79,6 +79,25 @@ def active(self): return request.path == self.get_url() +class ViewImg(View): + """View with img instead of text. + The ``endpoint``, ``*args`` and ``**kwargs`` are passed on to + :func:`~flask.url_for` to get the link. + :param img_src: The source of img for the link. + :param img_alt: The alternate text of img for the link. + :param endpoint: The name of the view. + :param args: Extra arguments for :func:`~flask.url_for` + :param kwargs: Extra keyword arguments for :func:`~flask.url_for` + """ + def __init__(self, img_src, img_alt, endpoint, *args, **kwargs): + self.img_src = img_src + self.img_alt = img_alt + self.text = img_alt + self.endpoint = endpoint + self.url_for_args = args + self.url_for_kwargs = kwargs + + class Separator(NavigationItem): """Separator. diff --git a/flask_nav/renderers.py b/flask_nav/renderers.py index 39e3a1f..9efad46 100644 --- a/flask_nav/renderers.py +++ b/flask_nav/renderers.py @@ -63,6 +63,16 @@ def visit_View(self, node): title=node.text, **kwargs) + def visit_ViewImg(self, node): + item = tags.li() + a = tags.a(href=node.get_url(), title=node.text) + a.add(tags.img(src=node.img_src, alt=node.img_alt)) + item.add(a) + if node.active: + item['class'] = 'active' + + return item + def visit_Subgroup(self, node): group = tags.ul(_class='subgroup') title = tags.span(node.title)