[Python-modules-commits] [python-django-navtag] 01/03: importing python-django-navtag_2.1.1.orig.tar.gz

Michael Fladischer fladi at moszumanska.debian.org
Sat Jul 9 13:54:05 UTC 2016


This is an automated email from the git hooks/post-receive script.

fladi pushed a commit to branch master
in repository python-django-navtag.

commit d719686ed643d8d1a8c58df7cc6f611b642b87d5
Author: Michael Fladischer <FladischerMichael at fladi.at>
Date:   Fri Jul 8 20:53:38 2016 +0200

    importing python-django-navtag_2.1.1.orig.tar.gz
---
 LICENSE                                            |  25 +++
 MANIFEST.in                                        |   4 +
 PKG-INFO                                           |  21 +++
 README.rst                                         |  88 ++++++++++
 django_navtag.egg-info/PKG-INFO                    |  21 +++
 django_navtag.egg-info/SOURCES.txt                 |  29 ++++
 django_navtag.egg-info/dependency_links.txt        |   1 +
 django_navtag.egg-info/top_level.txt               |   1 +
 django_navtag/__init__.py                          |   0
 django_navtag/models.py                            |   0
 django_navtag/templates/navtag_tests/base.txt      |   7 +
 django_navtag/templates/navtag_tests/contact.txt   |   7 +
 .../templates/navtag_tests/context/home.txt        |  11 ++
 .../templates/navtag_tests/home-unset.txt          |   7 +
 django_navtag/templates/navtag_tests/home.txt      |   7 +
 .../templates/navtag_tests/submenu/apple.txt       |   7 +
 .../templates/navtag_tests/submenu/banana.txt      |   7 +
 .../templates/navtag_tests/submenu/base.txt        |   6 +
 .../templates/navtag_tests/submenu/base_fruit.txt  |   7 +
 .../templates/navtag_tests/submenu/home.txt        |   7 +
 django_navtag/templates/navtag_tests/text/base.txt |  10 ++
 .../templates/navtag_tests/text/contact.txt        |   7 +
 django_navtag/templates/navtag_tests/text/home.txt |   7 +
 django_navtag/templatetags/__init__.py             |   0
 django_navtag/templatetags/navtag.py               | 183 +++++++++++++++++++++
 django_navtag/test_settings.py                     |  14 ++
 django_navtag/tests/__init__.py                    |   1 +
 django_navtag/tests/navtag.py                      | 149 +++++++++++++++++
 setup.cfg                                          |   5 +
 setup.py                                           |  44 +++++
 tox.ini                                            |  65 ++++++++
 31 files changed, 748 insertions(+)

diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..72816ff
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,25 @@
+Copyright (c) 2013, Chris Beaven
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+    * Redistributions of source code must retain the above copyright notice,
+      this list of conditions and the following disclaimer.
+    * Redistributions in binary form must reproduce the above copyright notice,
+      this list of conditions and the following disclaimer in the documentation
+      and/or other materials provided with the distribution.
+    * Neither the name easy-thumbnails nor the names of its contributors may be
+      used to endorse or promote products derived from this software without
+      specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/MANIFEST.in b/MANIFEST.in
new file mode 100644
index 0000000..941778d
--- /dev/null
+++ b/MANIFEST.in
@@ -0,0 +1,4 @@
+include LICENSE
+include README.rst
+include tox.ini
+graft django_navtag/templates
diff --git a/PKG-INFO b/PKG-INFO
new file mode 100644
index 0000000..25b0dd9
--- /dev/null
+++ b/PKG-INFO
@@ -0,0 +1,21 @@
+Metadata-Version: 1.1
+Name: django-navtag
+Version: 2.1.1
+Summary: A simple Django navigation template tag
+Home-page: http://github.com/SmileyChris/django-navtag
+Author: Chris Beaven
+Author-email: smileychris at gmail.com
+License: UNKNOWN
+Description: UNKNOWN
+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: Framework :: Django
+Classifier: Programming Language :: Python :: 2.6
+Classifier: Programming Language :: Python :: 2.7
+Classifier: Programming Language :: Python :: 3.3
+Classifier: Programming Language :: Python :: 3.4
diff --git a/README.rst b/README.rst
new file mode 100644
index 0000000..2db6807
--- /dev/null
+++ b/README.rst
@@ -0,0 +1,88 @@
+``{% nav %}`` tag
+=================
+
+A simple Django template tag to handle navigation item selection.
+
+.. image:: https://secure.travis-ci.org/SmileyChris/django-navtag.png?branch=master
+   :target: http://travis-ci.org/SmileyChris/django-navtag
+
+Example
+-------
+
+Add the app to your ``INSTALLED_APPS`` setting::
+
+	INSTALLED_APPS = (
+		# ...
+		'django_navtag',
+	)
+
+Give your base template a navigation block something like this::
+
+    {% load navtag %}
+
+    {% block nav %}
+    {% nav text ' class="selected"' %}
+    <ul class="nav">
+        <li{{ nav.home }}><a href="/">Home</a></li>
+        <li{{ nav.about }}><a href="/about/">About</a></li>
+    </ul>
+    {% endblock %}
+
+In your templates, extend the base and set the navigation location::
+
+	{% 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::
+
+    {% 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] %}``::
+
+	{% 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::
+
+    {% nav text "active" %}
+    <ul>
+    <li class="{{ nav.home }}">Home</li>
+    <li class="{{ nav.contact }}">Contact</li>
+    </ul>
+
+Alternately, you can use boolean comparison of the context variable rather than
+text value::
+
+    <section{% if nav.home %} class="wide"{% endif %}>
+
+If using a different context variable name, use the format
+``{% nav text [content] for [var_name] %}``.
diff --git a/django_navtag.egg-info/PKG-INFO b/django_navtag.egg-info/PKG-INFO
new file mode 100644
index 0000000..25b0dd9
--- /dev/null
+++ b/django_navtag.egg-info/PKG-INFO
@@ -0,0 +1,21 @@
+Metadata-Version: 1.1
+Name: django-navtag
+Version: 2.1.1
+Summary: A simple Django navigation template tag
+Home-page: http://github.com/SmileyChris/django-navtag
+Author: Chris Beaven
+Author-email: smileychris at gmail.com
+License: UNKNOWN
+Description: UNKNOWN
+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: Framework :: Django
+Classifier: Programming Language :: Python :: 2.6
+Classifier: Programming Language :: Python :: 2.7
+Classifier: Programming Language :: Python :: 3.3
+Classifier: Programming Language :: Python :: 3.4
diff --git a/django_navtag.egg-info/SOURCES.txt b/django_navtag.egg-info/SOURCES.txt
new file mode 100644
index 0000000..01f464a
--- /dev/null
+++ b/django_navtag.egg-info/SOURCES.txt
@@ -0,0 +1,29 @@
+LICENSE
+MANIFEST.in
+README.rst
+setup.py
+tox.ini
+django_navtag/__init__.py
+django_navtag/models.py
+django_navtag/test_settings.py
+django_navtag.egg-info/PKG-INFO
+django_navtag.egg-info/SOURCES.txt
+django_navtag.egg-info/dependency_links.txt
+django_navtag.egg-info/top_level.txt
+django_navtag/templates/navtag_tests/base.txt
+django_navtag/templates/navtag_tests/contact.txt
+django_navtag/templates/navtag_tests/home-unset.txt
+django_navtag/templates/navtag_tests/home.txt
+django_navtag/templates/navtag_tests/context/home.txt
+django_navtag/templates/navtag_tests/submenu/apple.txt
+django_navtag/templates/navtag_tests/submenu/banana.txt
+django_navtag/templates/navtag_tests/submenu/base.txt
+django_navtag/templates/navtag_tests/submenu/base_fruit.txt
+django_navtag/templates/navtag_tests/submenu/home.txt
+django_navtag/templates/navtag_tests/text/base.txt
+django_navtag/templates/navtag_tests/text/contact.txt
+django_navtag/templates/navtag_tests/text/home.txt
+django_navtag/templatetags/__init__.py
+django_navtag/templatetags/navtag.py
+django_navtag/tests/__init__.py
+django_navtag/tests/navtag.py
\ No newline at end of file
diff --git a/django_navtag.egg-info/dependency_links.txt b/django_navtag.egg-info/dependency_links.txt
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/django_navtag.egg-info/dependency_links.txt
@@ -0,0 +1 @@
+
diff --git a/django_navtag.egg-info/top_level.txt b/django_navtag.egg-info/top_level.txt
new file mode 100644
index 0000000..11da048
--- /dev/null
+++ b/django_navtag.egg-info/top_level.txt
@@ -0,0 +1 @@
+django_navtag
diff --git a/django_navtag/__init__.py b/django_navtag/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/django_navtag/models.py b/django_navtag/models.py
new file mode 100644
index 0000000..e69de29
diff --git a/django_navtag/templates/navtag_tests/base.txt b/django_navtag/templates/navtag_tests/base.txt
new file mode 100644
index 0000000..88611f4
--- /dev/null
+++ b/django_navtag/templates/navtag_tests/base.txt
@@ -0,0 +1,7 @@
+{% block nav %}
+- Home {% if nav.home %}(active){% endif %}
+- Contact {% if nav.contact %}(active){% endif %}
+{% endblock %}
+
+{% block main %}
+{% endblock %}
diff --git a/django_navtag/templates/navtag_tests/contact.txt b/django_navtag/templates/navtag_tests/contact.txt
new file mode 100644
index 0000000..e44530b
--- /dev/null
+++ b/django_navtag/templates/navtag_tests/contact.txt
@@ -0,0 +1,7 @@
+{% extends "navtag_tests/base.txt" %}
+{% load navtag %}
+
+{% block nav %}
+{% nav "contact" %}
+{{ block.super }}
+{% endblock %}
\ No newline at end of file
diff --git a/django_navtag/templates/navtag_tests/context/home.txt b/django_navtag/templates/navtag_tests/context/home.txt
new file mode 100644
index 0000000..a575ae5
--- /dev/null
+++ b/django_navtag/templates/navtag_tests/context/home.txt
@@ -0,0 +1,11 @@
+{% extends "navtag_tests/base.txt" %}
+{% load navtag %}
+
+{% block nav %}
+{% nav "home" %}
+{{ block.super }}
+{% endblock %}
+
+{% block main %}
+{% if nav.home %}HOME{% else %}huh?{% endif %}
+{% endblock %}
\ No newline at end of file
diff --git a/django_navtag/templates/navtag_tests/home-unset.txt b/django_navtag/templates/navtag_tests/home-unset.txt
new file mode 100644
index 0000000..959f90c
--- /dev/null
+++ b/django_navtag/templates/navtag_tests/home-unset.txt
@@ -0,0 +1,7 @@
+{% extends "navtag_tests/home.txt" %}
+{% load navtag %}
+
+{% block nav %}
+{% nav "" %}
+{{ block.super }}
+{% endblock %}
\ No newline at end of file
diff --git a/django_navtag/templates/navtag_tests/home.txt b/django_navtag/templates/navtag_tests/home.txt
new file mode 100644
index 0000000..19b0cd8
--- /dev/null
+++ b/django_navtag/templates/navtag_tests/home.txt
@@ -0,0 +1,7 @@
+{% extends "navtag_tests/base.txt" %}
+{% load navtag %}
+
+{% block nav %}
+{% nav "home" %}
+{{ block.super }}
+{% endblock %}
\ No newline at end of file
diff --git a/django_navtag/templates/navtag_tests/submenu/apple.txt b/django_navtag/templates/navtag_tests/submenu/apple.txt
new file mode 100644
index 0000000..454dfeb
--- /dev/null
+++ b/django_navtag/templates/navtag_tests/submenu/apple.txt
@@ -0,0 +1,7 @@
+{% extends "navtag_tests/submenu/base_fruit.txt" %}
+{% load navtag %}
+
+{% block nav %}
+{% nav "fruit.apple" %}
+{{ block.super }}
+{% endblock %}
\ No newline at end of file
diff --git a/django_navtag/templates/navtag_tests/submenu/banana.txt b/django_navtag/templates/navtag_tests/submenu/banana.txt
new file mode 100644
index 0000000..2aa9c17
--- /dev/null
+++ b/django_navtag/templates/navtag_tests/submenu/banana.txt
@@ -0,0 +1,7 @@
+{% extends "navtag_tests/submenu/base_fruit.txt" %}
+{% load navtag %}
+
+{% block nav %}
+{% nav "fruit.banana" %}
+{{ block.super }}
+{% endblock %}
\ No newline at end of file
diff --git a/django_navtag/templates/navtag_tests/submenu/base.txt b/django_navtag/templates/navtag_tests/submenu/base.txt
new file mode 100644
index 0000000..30eff71
--- /dev/null
+++ b/django_navtag/templates/navtag_tests/submenu/base.txt
@@ -0,0 +1,6 @@
+{% 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 %}
diff --git a/django_navtag/templates/navtag_tests/submenu/base_fruit.txt b/django_navtag/templates/navtag_tests/submenu/base_fruit.txt
new file mode 100644
index 0000000..43be68f
--- /dev/null
+++ b/django_navtag/templates/navtag_tests/submenu/base_fruit.txt
@@ -0,0 +1,7 @@
+{% extends "navtag_tests/submenu/base.txt" %}
+{% load navtag %}
+
+{% block nav %}
+{% nav "fruit" %}
+{{ block.super }}
+{% endblock %}
\ No newline at end of file
diff --git a/django_navtag/templates/navtag_tests/submenu/home.txt b/django_navtag/templates/navtag_tests/submenu/home.txt
new file mode 100644
index 0000000..0067f64
--- /dev/null
+++ b/django_navtag/templates/navtag_tests/submenu/home.txt
@@ -0,0 +1,7 @@
+{% extends "navtag_tests/submenu/base.txt" %}
+{% load navtag %}
+
+{% block nav %}
+{% nav "home" %}
+{{ block.super }}
+{% endblock %}
\ No newline at end of file
diff --git a/django_navtag/templates/navtag_tests/text/base.txt b/django_navtag/templates/navtag_tests/text/base.txt
new file mode 100644
index 0000000..f590fa0
--- /dev/null
+++ b/django_navtag/templates/navtag_tests/text/base.txt
@@ -0,0 +1,10 @@
+{% load navtag %}
+
+{% block nav %}
+{% nav text " [is active]" %}
+- Home{{ nav.home }}
+- Contact{{ nav.contact }}
+{% endblock %}
+
+{% block main %}
+{% endblock %}
diff --git a/django_navtag/templates/navtag_tests/text/contact.txt b/django_navtag/templates/navtag_tests/text/contact.txt
new file mode 100644
index 0000000..64f1c98
--- /dev/null
+++ b/django_navtag/templates/navtag_tests/text/contact.txt
@@ -0,0 +1,7 @@
+{% extends "navtag_tests/text/base.txt" %}
+{% load navtag %}
+
+{% block nav %}
+{% nav "contact" %}
+{{ block.super }}
+{% endblock %}
\ No newline at end of file
diff --git a/django_navtag/templates/navtag_tests/text/home.txt b/django_navtag/templates/navtag_tests/text/home.txt
new file mode 100644
index 0000000..e211061
--- /dev/null
+++ b/django_navtag/templates/navtag_tests/text/home.txt
@@ -0,0 +1,7 @@
+{% extends "navtag_tests/text/base.txt" %}
+{% load navtag %}
+
+{% block nav %}
+{% nav "home" %}
+{{ block.super }}
+{% endblock %}
\ No newline at end of file
diff --git a/django_navtag/templatetags/__init__.py b/django_navtag/templatetags/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/django_navtag/templatetags/navtag.py b/django_navtag/templatetags/navtag.py
new file mode 100644
index 0000000..3b64e17
--- /dev/null
+++ b/django_navtag/templatetags/navtag.py
@@ -0,0 +1,183 @@
+from django import template
+from django.utils import six, safestring
+from django.utils.encoding import smart_str, python_2_unicode_compatible
+
+
+register = template.Library()
+
+
+ at python_2_unicode_compatible
+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 safestring.mark_safe(six.text_type(self._text))
+
+    def __nonzero__(self):
+        return bool(self._tree)
+
+    # Python 3 equivalent.
+    __bool__ = __nonzero__
+
+    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 "<Nav node>"
+
+
+ at register.tag
+def nav(parser, token):
+    """
+    Handles navigation item selection.
+
+    Example usage::
+
+        {# Set the context so {{ nav.home }} (or {{ mynav.home }}) is True #}
+        {% nav "home" %} or {% nav "home" for mynav %}
+
+    The most basic (and common) use of the tag is to call ``{% nav [item] %}``,
+    where ``[item]`` is the item you want to check is selected.
+
+    By default, this tag creates a ``nav`` context variable. To use an
+    alternate context variable name, call ``{% nav [item] for [var_name] %}``.
+
+    Your HTML navigation template should look something like::
+
+        {% block nav %}
+        <ul class="nav">
+            <li{% if nav.home %} class="selected"{% endif %}>
+                <a href="/">Home</a>
+            </li>
+            <li{% if nav.about %} class="selected"{% endif %}>
+                <a href="/about/">About</a>
+            </li>
+        </ul>
+        {% endblock %}
+
+    To override this in a child template, you'd do::
+
+        {% include "base.html" %}
+        {% load nav %}
+
+        {% block nav %}
+        {% nav "about" %}
+        {{ block.super }}
+        {% endblock %}
+
+    This works for multiple levels of template inheritance, due to the fact
+    that the tag only does anything if the ``nav`` context variable does not
+    exist. So only the first ``{% nav %}`` call found will ever be processed.
+
+    As a shortcut, you can use a ``text`` argument and then just reference the
+    variable rather than query it with an ``{% if %}`` tag::
+
+        {% nav text ' class="active"' %}
+        <ul class="nav">
+            <li{{ nav.home }}><a href="/">Home</a></li>
+            <li{{ nav.about }}><a href="/about/">About</a></li>
+        </ul>
+
+    To create a sub-menu you can check against, simply dot-separate the item::
+
+        {% nav "about_menu.info" %}
+
+    This will be pass for both ``{% if nav.about_menu %}`` and
+    ``{% if nav.about_menu.info %}``.
+    """
+    bits = token.split_contents()
+
+    ok = True
+    keys = {'for': False, 'text': True}
+    node_kwargs = {}
+    while len(bits) > 2:
+        value = bits.pop()
+        key = bits.pop()
+        if key not in keys:
+            ok = False
+            break
+        compile_filter = keys.pop(key)
+        if compile_filter:
+            value = parser.compile_filter(value)
+        node_kwargs['var_{0}'.format(key)] = value
+
+    if len(bits) > 1:
+        # Text argument doesn't expect an item.
+        ok = 'text' not in node_kwargs
+        item = parser.compile_filter(bits[1])
+    else:
+        item = None
+
+    if not ok:
+        raise template.TemplateSyntaxError(
+            'Unexpected format for %s tag' % bits[0])
+
+    return NavNode(item, **node_kwargs)
diff --git a/django_navtag/test_settings.py b/django_navtag/test_settings.py
new file mode 100644
index 0000000..ffb7762
--- /dev/null
+++ b/django_navtag/test_settings.py
@@ -0,0 +1,14 @@
+DATABASE_ENGINE = 'sqlite3'
+
+DATABASES = {
+    'default': {
+        'ENGINE': 'django.db.backends.sqlite3',
+        'NAME': ':memory:',
+    }
+}
+
+INSTALLED_APPS = [
+    'django_navtag',
+]
+
+SECRET_KEY = 'testing'
diff --git a/django_navtag/tests/__init__.py b/django_navtag/tests/__init__.py
new file mode 100644
index 0000000..1580249
--- /dev/null
+++ b/django_navtag/tests/__init__.py
@@ -0,0 +1 @@
+from .navtag import NavTagTest
diff --git a/django_navtag/tests/navtag.py b/django_navtag/tests/navtag.py
new file mode 100644
index 0000000..e1112eb
--- /dev/null
+++ b/django_navtag/tests/navtag.py
@@ -0,0 +1,149 @@
+from django import template
+from django.test import TestCase
+from django.template.loader import render_to_string
+
+from django_navtag.templatetags.navtag import NavNode
+
+BASIC_TEMPLATE = '''
+{% load navtag %}
+{% nav "banana" %}
+{% if nav.apple %}Apple{% endif %}
+{% if nav.banana %}Banana{% endif %}
+'''
+
+FOR_TEMPLATE = '''
+{% load navtag %}
+{% nav "banana" for othernav %}
+{% if othernav.apple %}Apple{% endif %}
+{% if othernav.banana %}Banana{% endif %}
+'''
+
+
+class NavTagTest(TestCase):
+
+    def test_basic(self):
+        t = template.Template(BASIC_TEMPLATE)
+        content = t.render(template.Context()).strip()
+        self.assertNotIn('Apple', content)
+        self.assertIn('Banana', content)
+
+    def test_for(self):
+        t = template.Template(FOR_TEMPLATE)
+        content = t.render(template.Context()).strip()
+        self.assertNotIn('Apple', content)
+        self.assertIn('Banana', content)
+
+    def test_basic_extends(self):
+        content = render_to_string('navtag_tests/home.txt').strip()
+        self.assertIn('- Home (active)', content)
+        self.assertNotIn('- Contact (active)', content)
+
+        content = render_to_string('navtag_tests/contact.txt').strip()
+        self.assertNotIn('- Home (active)', content)
+        self.assertIn('- Contact (active)', content)
+
+    def test_unset(self):
+        content = render_to_string('navtag_tests/home.txt').strip()
+        self.assertIn('- Home (active)', content)
+        self.assertNotIn('- Contact (active)', content)
+
+        content = render_to_string('navtag_tests/home-unset.txt').strip()
+        self.assertNotIn('- Home (active)', content)
+        self.assertNotIn('- Contact (active)', content)
+
+    def test_heirarchical(self):
+        content = render_to_string('navtag_tests/submenu/home.txt').strip()
+        self.assertIn('- Home (active)', content)
+        self.assertNotIn('- Fruit (active)', content)
+        self.assertNotIn('  - Apple (active)', content)
+        self.assertNotIn('  - Banana (active)', content)
+
+        content = render_to_string(
+            'navtag_tests/submenu/base_fruit.txt').strip()
+        self.assertNotIn('- Home (active)', content)
+        self.assertIn('- Fruit (active)', content)
+        self.assertNotIn('  - Apple (active)', content)
+        self.assertNotIn('  - Banana (active)', content)
+
+        content = render_to_string('navtag_tests/submenu/apple.txt').strip()
+        self.assertNotIn('- Home (active)', content)
+        self.assertIn('- Fruit (active)', content)
+        self.assertIn('  - Apple (active)', content)
+        self.assertNotIn('  - Banana (active)', content)
+
+        content = render_to_string('navtag_tests/submenu/banana.txt').strip()
+        self.assertNotIn('- Home (active)', content)
+        self.assertIn('- Fruit (active)', content)
+        self.assertNotIn('  - Apple (active)', content)
+        self.assertIn('  - Banana (active)', content)
+
+    def test_top_context(self):
+        content = render_to_string('navtag_tests/context/home.txt').strip()
+        self.assertIn('- Home (active)', content)
+        self.assertIn('HOME', content)
+
+    def test_repr(self):
+        node = NavNode()
+        self.assertEqual(repr(node), "<Nav node>")
+
+    def test_invalid_args(self):
+        self.assertRaises(
+            template.TemplateSyntaxError, template.Template,
+            '''{% load navtag %}{% nav 'test' unexpected %}''')
+
+    def test_backwards_compatible_empty_tag(self):
+        content = template.Template(
+            '{% load navtag %}{% nav %}').render(template.Context())
+        self.assertEqual(content, '')
+
+        content = template.Template(
+            '{% load navtag %}{% nav for sidenav %}').render(template.Context())
+        self.assertEqual(content, '')
+
+    def test_yell_if_context_variable_changed(self):
+        t = template.Template('{% load navtag %}{% nav "test" %}{{ nav }}')
+        c = template.Context({'nav': 'anything'})
+        c.update({'nav': 'test'})
+        self.assertRaises(
+            template.TemplateSyntaxError,
+            t.render, c)
+
+    def test_nav_text(self):
+        content = (
+            template.Template('{% load navtag %}{% nav text "THIS" %}')
+            .render(template.Context()))
+        self.assertEqual(content, '')
+
+    def test_nav_text_none(self):
+        content = render_to_string('navtag_tests/text/base.txt').strip()
+        self.assertEqual(content, '- Home\n- Contact')
+
+    def test_nav_text_set(self):
+        content = render_to_string('navtag_tests/text/home.txt').strip()
+        self.assertIn('Home [is active]', content)
+        self.assertNotIn('Contact [is active]', content)
+
+        content = render_to_string('navtag_tests/text/contact.txt').strip()
+        self.assertNotIn('Home [is active]', content)
+        self.assertIn('Contact [is active]', content)
+
+    def test_nav_default_text(self):
+        content = (
+            template.Template(
+                '{% load navtag %}{% nav "fruit" %}{{ nav.fruit }}')
+            .render(template.Context(autoescape=False))).strip()
+        self.assertEqual(content, "True")
+
+        content = (
+            template.Template(
+                '{% load navtag %}{% nav "fruit.banana" %}{{ nav.fruit }}')
+            .render(template.Context(autoescape=False))).strip()
+        self.assertEqual(content, "{'banana': True}")
+
+    def test_escaping(self):
+        content = (
+            template.Template(
+                '''{% load navtag %}{% nav text ' class="active"' %}'''
+                '<p{{ nav }}>{{ name }}</p>')
+            .render(template.Context({'name': "Mc'D"}))).strip()
+        self.assertEqual(content, '''<p class="active">Mc'D</p>''')
diff --git a/setup.cfg b/setup.cfg
new file mode 100644
index 0000000..861a9f5
--- /dev/null
+++ b/setup.cfg
@@ -0,0 +1,5 @@
+[egg_info]
+tag_build = 
+tag_date = 0
+tag_svn_revision = 0
+
diff --git a/setup.py b/setup.py
new file mode 100644
index 0000000..73166c6
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,44 @@
+import sys
+
+from setuptools import setup, find_packages
+from setuptools.command.test import test as TestCommand
+
+
+class Tox(TestCommand):
+
+    def finalize_options(self):
+        TestCommand.finalize_options(self)
+        self.test_args = []
+        self.test_suite = True
+
+    def run_tests(self):
+        import tox
+        errno = tox.cmdline(self.test_args)
+        sys.exit(errno)
+
+
+setup(
+    name='django-navtag',
+    version='2.1.1',
+    description=("A simple Django navigation template tag"),
+    author='Chris Beaven',
+    author_email='smileychris at gmail.com',
+    url='http://github.com/SmileyChris/django-navtag',
+    packages=find_packages(),
+    include_package_data=True,
+    tests_require=['tox'],
+    cmdclass={'test': Tox},
+    classifiers=[
+        'Development Status :: 5 - Production/Stable',
+        'Environment :: Web Environment',
+        'Intended Audience :: Developers',
+        'License :: OSI Approved :: MIT License',
+        'Operating System :: OS Independent',
+        'Programming Language :: Python',
+        'Framework :: Django',
+        'Programming Language :: Python :: 2.6',
+        'Programming Language :: Python :: 2.7',
+        'Programming Language :: Python :: 3.3',
+        'Programming Language :: Python :: 3.4',
+    ]
+)
diff --git a/tox.ini b/tox.ini
new file mode 100644
index 0000000..c5c0f88
--- /dev/null
+++ b/tox.ini
@@ -0,0 +1,65 @@
+[tox]
+distribute = False
+envlist =
+    readme,
+    1.4.X,
+    1.5.X,
+    1.6.X,
+    py33-1.6.X,
+    py34-1.6.X,
+    master
+
+[testenv]
+downloadcache = {toxworkdir}/_download/
+commands =
+    {envbindir}/python {envbindir}/django-admin.py test {posargs:django_navtag}
+setenv =
+    DJANGO_SETTINGS_MODULE = django_navtag.test_settings
+
+[testenv:readme]
+deps =
+    docutils
+whitelist_externals = mkdir
+commands =
+    mkdir -p {envtmpdir}
+    rst2html.py --exit-status=2 README.rst {envtmpdir}/readme.html
+
+[testenv:1.4.X]
+basepython = python2.6
+deps =
+    Django<1.5
+
+[testenv:1.5.X]
+basepython = python2.7
+deps =
+    Django<1.6
+
+[testenv:1.6.X]
+basepython = python2.7
+deps =
+    Django<1.7
+commands =
+    {envbindir}/python {envbindir}/django-admin.py test {posargs:django_navtag.tests}
+
+[testenv:py33-1.6.X]
+basepython = python3.3
+deps =
+    Django<1.7
+commands =
+    {envbindir}/python {envbindir}/django-admin.py test {posargs:django_navtag.tests}
+
+[testenv:py34-1.6.X]
+basepython = python3.4
+deps =
+    Django<1.7
+commands =
+    {envbindir}/python {envbindir}/django-admin.py test {posargs:django_navtag.tests}
+
+[testenv:master]
+basepython = python2.7
+changedir = {envsitepackagesdir}/django_navtag
+deps =
+    https://github.com/django/django/zipball/master
+    coverage
+commands =
+    coverage run --source="." {envbindir}/django-admin.py test {posargs:django_navtag.tests} && coverage report -m

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-django-navtag.git



More information about the Python-modules-commits mailing list