././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1618180308.9920402
django-navtag-3.0/ 0000755 0001750 0001750 00000000000 00000000000 013077 5 ustar 00chris chris ././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1618180308.0
django-navtag-3.0/LICENSE 0000644 0001750 0001750 00000002041 00000000000 014101 0 ustar 00chris chris Copyright (c) 2013, Chris Beaven
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1618180308.0
django-navtag-3.0/MANIFEST.in 0000644 0001750 0001750 00000000121 00000000000 014627 0 ustar 00chris chris include LICENSE
include README.rst
include tox.ini
graft django_navtag/templates
././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1618180308.9920402
django-navtag-3.0/PKG-INFO 0000644 0001750 0001750 00000011146 00000000000 014177 0 ustar 00chris chris Metadata-Version: 2.1
Name: django-navtag
Version: 3.0
Summary: A simple Django navigation template tag
Home-page: https://github.com/SmileyChris/django-navtag
Author: Chris Beaven
Author-email: smileychris@gmail.com
License: MIT
Description: ``{% nav %}`` tag
=================
.. image:: https://badge.fury.io/py/django-navtag.svg
:target: https://badge.fury.io/py/django-navtag
.. image:: https://travis-ci.org/SmileyChris/django-navtag.svg?branch=master
:target: http://travis-ci.org/SmileyChris/django-navtag
.. image:: https://codecov.io/gh/SmileyChris/django-navtag/branch/master/graph/badge.svg
:target: https://codecov.io/gh/SmileyChris/django-navtag
A simple Django template tag to handle navigation item selection.
.. contents::
:local:
:backlinks: none
Usage
-----
Add the app to your ``INSTALLED_APPS`` setting:
.. code:: python
INSTALLED_APPS = (
# ...
'django_navtag',
)
Give your base template a navigation block something like this:
.. code:: jinja
{% load navtag %}
{% block nav %}
{% nav text ' class="selected"' %}
{% endblock %}
In your templates, extend the base and set the navigation location:
.. code:: jinja
{% extends "base.html" %}
{% block nav %}
{% nav "home" %}
{{ block.super }}
{% endblock %}
.. note::
This works for multiple levels of template inheritance, due to the fact
that only the first ``{% nav %}`` call found will change the ``nav``
context variable.
Hierarchical navigation
-----------------------
To create a sub-menu you can check against, simply dot-separate the item:
.. code:: jinja
{% nav "about_menu.info" %}
This will be pass for both ``{% if nav.about_menu %}`` and
``{% if nav.about_menu.info %}``.
Using a different context variable
----------------------------------
By default, this tag creates a ``nav`` context variable. To use an alternate
context variable name, call ``{% nav [item] for [var_name] %}``:
.. code:: jinja
{% block nav %}
{% nav "home" for sidenav %}
{{ block.super }}
{% endblock %}
Setting the text output by the nav variable
-------------------------------------------
As shown in the initial example, you can set the text return value of the
``nav`` context variable. Use the format ``{% nav text [content] %}``. For
example:
.. code:: jinja
{% nav text "active" %}
Home
Contact
Alternately, you can use boolean comparison of the context variable rather than
text value:
.. code:: jinja
If using a different context variable name, use the format
``{% nav text [content] for [var_name] %}``.
Keywords: django,templates
Platform: UNKNOWN
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Web Environment
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Framework :: Django
Classifier: Framework :: Django :: 1.11
Classifier: Framework :: Django :: 2.2
Classifier: Framework :: Django :: 3.0
Classifier: Framework :: Django :: 3.1
Classifier: Framework :: Django :: 3.2
Provides-Extra: maintainer
Provides-Extra: dev
Provides-Extra: test
././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1618180308.0
django-navtag-3.0/README.rst 0000644 0001750 0001750 00000005161 00000000000 014571 0 ustar 00chris chris ``{% nav %}`` tag
=================
.. image:: https://badge.fury.io/py/django-navtag.svg
:target: https://badge.fury.io/py/django-navtag
.. image:: https://travis-ci.org/SmileyChris/django-navtag.svg?branch=master
:target: http://travis-ci.org/SmileyChris/django-navtag
.. image:: https://codecov.io/gh/SmileyChris/django-navtag/branch/master/graph/badge.svg
:target: https://codecov.io/gh/SmileyChris/django-navtag
A simple Django template tag to handle navigation item selection.
.. contents::
:local:
:backlinks: none
Usage
-----
Add the app to your ``INSTALLED_APPS`` setting:
.. code:: python
INSTALLED_APPS = (
# ...
'django_navtag',
)
Give your base template a navigation block something like this:
.. code:: jinja
{% load navtag %}
{% block nav %}
{% nav text ' class="selected"' %}
{% endblock %}
In your templates, extend the base and set the navigation location:
.. code:: jinja
{% extends "base.html" %}
{% block nav %}
{% nav "home" %}
{{ block.super }}
{% endblock %}
.. note::
This works for multiple levels of template inheritance, due to the fact
that only the first ``{% nav %}`` call found will change the ``nav``
context variable.
Hierarchical navigation
-----------------------
To create a sub-menu you can check against, simply dot-separate the item:
.. code:: jinja
{% nav "about_menu.info" %}
This will be pass for both ``{% if nav.about_menu %}`` and
``{% if nav.about_menu.info %}``.
Using a different context variable
----------------------------------
By default, this tag creates a ``nav`` context variable. To use an alternate
context variable name, call ``{% nav [item] for [var_name] %}``:
.. code:: jinja
{% block nav %}
{% nav "home" for sidenav %}
{{ block.super }}
{% endblock %}
Setting the text output by the nav variable
-------------------------------------------
As shown in the initial example, you can set the text return value of the
``nav`` context variable. Use the format ``{% nav text [content] %}``. For
example:
.. code:: jinja
{% nav text "active" %}
Home
Contact
Alternately, you can use boolean comparison of the context variable rather than
text value:
.. code:: jinja
If using a different context variable name, use the format
``{% nav text [content] for [var_name] %}``.
././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1618180308.9920402
django-navtag-3.0/django_navtag/ 0000755 0001750 0001750 00000000000 00000000000 015701 5 ustar 00chris chris ././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1618180308.0
django-navtag-3.0/django_navtag/__init__.py 0000644 0001750 0001750 00000000000 00000000000 020000 0 ustar 00chris chris ././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1618180308.0
django-navtag-3.0/django_navtag/models.py 0000644 0001750 0001750 00000000000 00000000000 017524 0 ustar 00chris chris ././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1618180308.9920402
django-navtag-3.0/django_navtag/templates/ 0000755 0001750 0001750 00000000000 00000000000 017677 5 ustar 00chris chris ././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1618180308.9920402
django-navtag-3.0/django_navtag/templates/navtag_tests/ 0000755 0001750 0001750 00000000000 00000000000 022401 5 ustar 00chris chris ././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1618180308.0
django-navtag-3.0/django_navtag/templates/navtag_tests/base.txt 0000644 0001750 0001750 00000000236 00000000000 024055 0 ustar 00chris chris {% block nav %}
- Home {% if nav.home %}(active){% endif %}
- Contact {% if nav.contact %}(active){% endif %}
{% endblock %}
{% block main %}
{% endblock %}
././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1618180308.0
django-navtag-3.0/django_navtag/templates/navtag_tests/contact.txt 0000644 0001750 0001750 00000000175 00000000000 024600 0 ustar 00chris chris {% extends "navtag_tests/base.txt" %}
{% load navtag %}
{% block nav %}
{% nav "contact" %}
{{ block.super }}
{% endblock %} ././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1618180308.9920402
django-navtag-3.0/django_navtag/templates/navtag_tests/context/ 0000755 0001750 0001750 00000000000 00000000000 024065 5 ustar 00chris chris ././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1618180308.0
django-navtag-3.0/django_navtag/templates/navtag_tests/context/home.txt 0000644 0001750 0001750 00000000312 00000000000 025552 0 ustar 00chris chris {% extends "navtag_tests/base.txt" %}
{% load navtag %}
{% block nav %}
{% nav "home" %}
{{ block.super }}
{% endblock %}
{% block main %}
{% if nav.home %}HOME{% else %}huh?{% endif %}
{% endblock %} ././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1618180308.0
django-navtag-3.0/django_navtag/templates/navtag_tests/home-unset.txt 0000644 0001750 0001750 00000000166 00000000000 025231 0 ustar 00chris chris {% extends "navtag_tests/home.txt" %}
{% load navtag %}
{% block nav %}
{% nav "" %}
{{ block.super }}
{% endblock %} ././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1618180308.0
django-navtag-3.0/django_navtag/templates/navtag_tests/home.txt 0000644 0001750 0001750 00000000172 00000000000 024072 0 ustar 00chris chris {% extends "navtag_tests/base.txt" %}
{% load navtag %}
{% block nav %}
{% nav "home" %}
{{ block.super }}
{% endblock %} ././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1618180308.9920402
django-navtag-3.0/django_navtag/templates/navtag_tests/submenu/ 0000755 0001750 0001750 00000000000 00000000000 024057 5 ustar 00chris chris ././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1618180308.0
django-navtag-3.0/django_navtag/templates/navtag_tests/submenu/apple.txt 0000644 0001750 0001750 00000000217 00000000000 025721 0 ustar 00chris chris {% extends "navtag_tests/submenu/base_fruit.txt" %}
{% load navtag %}
{% block nav %}
{% nav "fruit.apple" %}
{{ block.super }}
{% endblock %} ././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1618180308.0
django-navtag-3.0/django_navtag/templates/navtag_tests/submenu/banana.txt 0000644 0001750 0001750 00000000220 00000000000 026032 0 ustar 00chris chris {% extends "navtag_tests/submenu/base_fruit.txt" %}
{% load navtag %}
{% block nav %}
{% nav "fruit.banana" %}
{{ block.super }}
{% endblock %} ././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1618180308.0
django-navtag-3.0/django_navtag/templates/navtag_tests/submenu/base.txt 0000644 0001750 0001750 00000000347 00000000000 025536 0 ustar 00chris chris {% block nav %}
- Home {% if nav.home %}(active){% endif %}
- Fruit {% if nav.fruit %}(active){% endif %}
- Apple {% if nav.fruit.apple %}(active){% endif %}
- Banana {% if nav.fruit.banana %}(active){% endif %}
{% endblock %}
././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1618180308.0
django-navtag-3.0/django_navtag/templates/navtag_tests/submenu/base_fruit.txt 0000644 0001750 0001750 00000000203 00000000000 026736 0 ustar 00chris chris {% extends "navtag_tests/submenu/base.txt" %}
{% load navtag %}
{% block nav %}
{% nav "fruit" %}
{{ block.super }}
{% endblock %} ././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1618180308.0
django-navtag-3.0/django_navtag/templates/navtag_tests/submenu/home.txt 0000644 0001750 0001750 00000000202 00000000000 025542 0 ustar 00chris chris {% extends "navtag_tests/submenu/base.txt" %}
{% load navtag %}
{% block nav %}
{% nav "home" %}
{{ block.super }}
{% endblock %} ././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1618180308.9920402
django-navtag-3.0/django_navtag/templates/navtag_tests/text/ 0000755 0001750 0001750 00000000000 00000000000 023365 5 ustar 00chris chris ././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1618180308.0
django-navtag-3.0/django_navtag/templates/navtag_tests/text/base.txt 0000644 0001750 0001750 00000000241 00000000000 025035 0 ustar 00chris chris {% load navtag %}
{% block nav %}
{% nav text " [is active]" %}
- Home{{ nav.home }}
- Contact{{ nav.contact }}
{% endblock %}
{% block main %}
{% endblock %}
././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1618180308.0
django-navtag-3.0/django_navtag/templates/navtag_tests/text/contact.txt 0000644 0001750 0001750 00000000202 00000000000 025553 0 ustar 00chris chris {% extends "navtag_tests/text/base.txt" %}
{% load navtag %}
{% block nav %}
{% nav "contact" %}
{{ block.super }}
{% endblock %} ././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1618180308.0
django-navtag-3.0/django_navtag/templates/navtag_tests/text/home.txt 0000644 0001750 0001750 00000000177 00000000000 025063 0 ustar 00chris chris {% extends "navtag_tests/text/base.txt" %}
{% load navtag %}
{% block nav %}
{% nav "home" %}
{{ block.super }}
{% endblock %} ././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1618180308.9920402
django-navtag-3.0/django_navtag/templatetags/ 0000755 0001750 0001750 00000000000 00000000000 020373 5 ustar 00chris chris ././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1618180308.0
django-navtag-3.0/django_navtag/templatetags/__init__.py 0000644 0001750 0001750 00000000000 00000000000 022472 0 ustar 00chris chris ././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1618180308.0
django-navtag-3.0/django_navtag/templatetags/navtag.py 0000644 0001750 0001750 00000012062 00000000000 022226 0 ustar 00chris chris from django import template
from django.utils.encoding import smart_str
from django.utils.safestring import mark_safe
register = template.Library()
class Nav(object):
def __init__(self, tree=None, root=None):
self._root = root or self
self._tree = tree or {}
def __getitem__(self, key):
return Nav(self._tree[key], root=self._root)
def __str__(self):
return mark_safe(str(self._text))
def __bool__(self):
return bool(self._tree)
def _get_text(self):
if hasattr(self._root, "_text_value"):
return self._root._text_value
return self._tree
def _set_text(self, value):
self._root._text_value = value
_text = property(_get_text, _set_text)
def clear(self):
self._tree = {}
def update(self, *args, **kwargs):
self._tree.update(*args, **kwargs)
class NavNode(template.Node):
def __init__(self, item=None, var_for=None, var_text=None):
self.item = item
self.var_name = var_for or "nav"
self.text = var_text
def render(self, context):
first_context_stack = context.dicts[0]
nav = first_context_stack.get(self.var_name)
if nav is not context.get(self.var_name):
raise template.TemplateSyntaxError(
"'{0}' variable has been altered in current context".format(
self.var_name
)
)
if not isinstance(nav, Nav):
nav = Nav()
# Copy the stack to avoid leaking into other contexts.
new_first_context_stack = first_context_stack.copy()
new_first_context_stack[self.var_name] = nav
context.dicts[0] = new_first_context_stack
if self.text:
nav._text = self.text.resolve(context)
return ""
# If self.item was blank then there's nothing else to do here.
if not self.item:
return ""
if nav:
# If the nav variable is already set, don't do anything.
return ""
item = self.item.resolve(context)
item = item and smart_str(item)
value = True
if not item:
item = ""
for part in reversed(item.split(".")):
new_item = {}
new_item[part] = value
value = new_item
nav.clear()
nav.update(new_item)
return ""
def __repr__(self):
return "