django-active-link


Namedjango-active-link JSON
Version 0.2.1 PyPI version JSON
download
home_pagehttps://github.com/valerymelou/django-active-link
SummaryThe best and simplest way to highlight active links in your Django app.
upload_time2024-06-08 11:07:31
maintainerFrederich Pedersen
docs_urlNone
authorValery Melou
requires_python<4.0,>=3.8
licenseBSD-3-Clause
keywords django active link django-active-link sidebar navbar
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            ==================
Django Active Link
==================

.. image:: https://badge.fury.io/py/django-active-link.svg
    :target: https://badge.fury.io/py/django-active-link

.. image:: https://pyup.io/repos/github/valerymelou/django-active-link/shield.svg
     :target: https://pyup.io/repos/github/valerymelou/django-active-link/
     :alt: Updates

.. image:: https://travis-ci.org/valerymelou/django-active-link.svg?branch=master
    :target: https://travis-ci.org/valerymelou/django-active-link

.. image:: https://codecov.io/gh/valerymelou/django-active-link/branch/master/graph/badge.svg
    :target: https://codecov.io/gh/valerymelou/django-active-link

The simplest way to highlight active links in your Django app.

Documentation
-------------

The full documentation is at https://django-active-link.readthedocs.io.

Quick start
-----------

Install Django Active Link::

    pip install django-active-link

Add it to your `INSTALLED_APPS`:

.. code-block:: python

    INSTALLED_APPS = (
        ...
        'active_link',
        ...
    )

To use the ``active_link`` template tag you need to load ``active_link_tags`` templatetags library:

.. code-block:: html

    {% load active_link_tags %}

To add an ``active`` CSS class to a link when the request path matches a given view just do something like this.

.. code-block:: html

    <a href="{% url 'view-name' %}" class="{% active_link 'view-name' %}">Menu item</a>

You can even add the active class when the request path matches multiple views. Just pass the view names separated by a double pipe (||) as first argument to the ``active_link`` tag.

.. code-block:: html

    <a href="{% url 'view-name' %}" class="{% active_link 'view-name || view-sub-name' %}">Menu Item</a>

You can also use a custom CSS class:

.. code-block:: html

    <a href="{% url 'view-name' %}" class="{% active_link 'view-name' 'custom-class' %}">Menu item</a>

or:

.. code-block:: html

    <a href="{% url 'view-name' %}" class="{% active_link 'view-name' css_class='custom-class' %}">Menu item</a>

You can also define an inactive custom css class, that is triggered when a link is deemed not active:

.. code-block:: html

    <a href="{% url 'view-name' %}" class="{% active_link 'view-name' 'custom-class' 'not-active' %}">Menu item</a>

or:

.. code-block:: html

    <a href="{% url 'view-name' %}" class="{% active_link 'view-name' css_class='custom-class' css_inactive_class='not-active' %}">Menu item</a>

By default ``active_link`` will not perform a strict match. If you want to add the ``active`` class only in case of a strict match pass the ``strict`` argument to the tag:

.. code-block:: html

    <a href="{% url 'view-name' %}" class="{% active_link strict=True %}">Menu item</a>

Replace ``view-name`` with the name of your view (including namespaces).

Settings
--------
You can override the default active class and strict mode with the settings ``ACTIVE_LINK_CSS_CLASS``, ``ACTIVE_LINK_CSS_INACTIVE_CLASS`` and ``ACTIVE_LINK_STRICT``.

============================== ==================================================== =============
Key                            Description                                          Default Value
============================== ==================================================== =============
ACTIVE_LINK_CSS_CLASS          Active class to use.                                 `active`
ACTIVE_LINK_CSS_INACTIVE_CLASS Inactive class to use.
ACTIVE_LINK_STRICT             Designates whether to perform a strict match or not. `False`
============================== ==================================================== =============

For more usage examples, please check the full documentation at https://django-active-link.readthedocs.io.

**IMPORTANT**: Django Active Link requires that the current request object is available in your template's context. This means you must be using a `RequestContext` when rendering your template, and `django.template.context_processors.request` must be in your `TEMPLATE_CONTEXT_PROCESSORS` setting. See https://docs.djangoproject.com/en/dev/ref/templates/api/#subclassing-context-requestcontext for more information.

TODO
----

* Write the documentation
* Clean repository for unneccesary files

Running Tests
-------------

Does the code actually work?

::

    source <YOURVIRTUALENV>/bin/activate
    (myenv) $ pip install poetry
    (myenv) $ poetry install --only test
    (myenv) $ poetry run tox

Credits
-------

Tools used in rendering this package:

*  Cookiecutter_
*  `cookiecutter-djangopackage`_

.. _Cookiecutter: https://github.com/audreyr/cookiecutter
.. _`cookiecutter-djangopackage`: https://github.com/pydanny/cookiecutter-djangopackage


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/valerymelou/django-active-link",
    "name": "django-active-link",
    "maintainer": "Frederich Pedersen",
    "docs_url": null,
    "requires_python": "<4.0,>=3.8",
    "maintainer_email": "frodo@hobbits.dk",
    "keywords": "django, active, link, django-active-link, sidebar, navbar",
    "author": "Valery Melou",
    "author_email": "valerymelou@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/8c/b0/ec788b777871ea857cbf97307c63a731597ed25cbb2276840ab764dd7c67/django_active_link-0.2.1.tar.gz",
    "platform": null,
    "description": "==================\nDjango Active Link\n==================\n\n.. image:: https://badge.fury.io/py/django-active-link.svg\n    :target: https://badge.fury.io/py/django-active-link\n\n.. image:: https://pyup.io/repos/github/valerymelou/django-active-link/shield.svg\n     :target: https://pyup.io/repos/github/valerymelou/django-active-link/\n     :alt: Updates\n\n.. image:: https://travis-ci.org/valerymelou/django-active-link.svg?branch=master\n    :target: https://travis-ci.org/valerymelou/django-active-link\n\n.. image:: https://codecov.io/gh/valerymelou/django-active-link/branch/master/graph/badge.svg\n    :target: https://codecov.io/gh/valerymelou/django-active-link\n\nThe simplest way to highlight active links in your Django app.\n\nDocumentation\n-------------\n\nThe full documentation is at https://django-active-link.readthedocs.io.\n\nQuick start\n-----------\n\nInstall Django Active Link::\n\n    pip install django-active-link\n\nAdd it to your `INSTALLED_APPS`:\n\n.. code-block:: python\n\n    INSTALLED_APPS = (\n        ...\n        'active_link',\n        ...\n    )\n\nTo use the ``active_link`` template tag you need to load ``active_link_tags`` templatetags library:\n\n.. code-block:: html\n\n    {% load active_link_tags %}\n\nTo add an ``active`` CSS class to a link when the request path matches a given view just do something like this.\n\n.. code-block:: html\n\n    <a href=\"{% url 'view-name' %}\" class=\"{% active_link 'view-name' %}\">Menu item</a>\n\nYou can even add the active class when the request path matches multiple views. Just pass the view names separated by a double pipe (||) as first argument to the ``active_link`` tag.\n\n.. code-block:: html\n\n    <a href=\"{% url 'view-name' %}\" class=\"{% active_link 'view-name || view-sub-name' %}\">Menu Item</a>\n\nYou can also use a custom CSS class:\n\n.. code-block:: html\n\n    <a href=\"{% url 'view-name' %}\" class=\"{% active_link 'view-name' 'custom-class' %}\">Menu item</a>\n\nor:\n\n.. code-block:: html\n\n    <a href=\"{% url 'view-name' %}\" class=\"{% active_link 'view-name' css_class='custom-class' %}\">Menu item</a>\n\nYou can also define an inactive custom css class, that is triggered when a link is deemed not active:\n\n.. code-block:: html\n\n    <a href=\"{% url 'view-name' %}\" class=\"{% active_link 'view-name' 'custom-class' 'not-active' %}\">Menu item</a>\n\nor:\n\n.. code-block:: html\n\n    <a href=\"{% url 'view-name' %}\" class=\"{% active_link 'view-name' css_class='custom-class' css_inactive_class='not-active' %}\">Menu item</a>\n\nBy default ``active_link`` will not perform a strict match. If you want to add the ``active`` class only in case of a strict match pass the ``strict`` argument to the tag:\n\n.. code-block:: html\n\n    <a href=\"{% url 'view-name' %}\" class=\"{% active_link strict=True %}\">Menu item</a>\n\nReplace ``view-name`` with the name of your view (including namespaces).\n\nSettings\n--------\nYou can override the default active class and strict mode with the settings ``ACTIVE_LINK_CSS_CLASS``, ``ACTIVE_LINK_CSS_INACTIVE_CLASS`` and ``ACTIVE_LINK_STRICT``.\n\n============================== ==================================================== =============\nKey                            Description                                          Default Value\n============================== ==================================================== =============\nACTIVE_LINK_CSS_CLASS          Active class to use.                                 `active`\nACTIVE_LINK_CSS_INACTIVE_CLASS Inactive class to use.\nACTIVE_LINK_STRICT             Designates whether to perform a strict match or not. `False`\n============================== ==================================================== =============\n\nFor more usage examples, please check the full documentation at https://django-active-link.readthedocs.io.\n\n**IMPORTANT**: Django Active Link requires that the current request object is available in your template's context. This means you must be using a `RequestContext` when rendering your template, and `django.template.context_processors.request` must be in your `TEMPLATE_CONTEXT_PROCESSORS` setting. See https://docs.djangoproject.com/en/dev/ref/templates/api/#subclassing-context-requestcontext for more information.\n\nTODO\n----\n\n* Write the documentation\n* Clean repository for unneccesary files\n\nRunning Tests\n-------------\n\nDoes the code actually work?\n\n::\n\n    source <YOURVIRTUALENV>/bin/activate\n    (myenv) $ pip install poetry\n    (myenv) $ poetry install --only test\n    (myenv) $ poetry run tox\n\nCredits\n-------\n\nTools used in rendering this package:\n\n*  Cookiecutter_\n*  `cookiecutter-djangopackage`_\n\n.. _Cookiecutter: https://github.com/audreyr/cookiecutter\n.. _`cookiecutter-djangopackage`: https://github.com/pydanny/cookiecutter-djangopackage\n\n",
    "bugtrack_url": null,
    "license": "BSD-3-Clause",
    "summary": "The best and simplest way to highlight active links in your Django app.",
    "version": "0.2.1",
    "project_urls": {
        "Bug Tracker": "https://github.com/valerymelou/django-active-link/issues",
        "Documentation": "https://django-active-link.readthedocs.io/",
        "Homepage": "https://github.com/valerymelou/django-active-link",
        "Repository": "https://github.com/valerymelou/django-active-link",
        "codecov": "https://codecov.io/gh/valerymelou/django-active-link"
    },
    "split_keywords": [
        "django",
        " active",
        " link",
        " django-active-link",
        " sidebar",
        " navbar"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "69dbe7bce131b6ff2fb9e7b11f8502f4cb1aa800ce0d61c5be85408ca92a4b75",
                "md5": "879d7bf7982398510d81ece01859e765",
                "sha256": "a9096497dd23dd0c5929872304f4ce26717e1904b82efa7592493328db5b6edf"
            },
            "downloads": -1,
            "filename": "django_active_link-0.2.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "879d7bf7982398510d81ece01859e765",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.8",
            "size": 5670,
            "upload_time": "2024-06-08T11:07:29",
            "upload_time_iso_8601": "2024-06-08T11:07:29.846862Z",
            "url": "https://files.pythonhosted.org/packages/69/db/e7bce131b6ff2fb9e7b11f8502f4cb1aa800ce0d61c5be85408ca92a4b75/django_active_link-0.2.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8cb0ec788b777871ea857cbf97307c63a731597ed25cbb2276840ab764dd7c67",
                "md5": "2fbd2c9aedf68e50af00a4ac6b11b7b7",
                "sha256": "70e1812fd08319bd814568e36a56ece1b72195dcc43bb5992d492867bbf2dc0e"
            },
            "downloads": -1,
            "filename": "django_active_link-0.2.1.tar.gz",
            "has_sig": false,
            "md5_digest": "2fbd2c9aedf68e50af00a4ac6b11b7b7",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.8",
            "size": 4577,
            "upload_time": "2024-06-08T11:07:31",
            "upload_time_iso_8601": "2024-06-08T11:07:31.590584Z",
            "url": "https://files.pythonhosted.org/packages/8c/b0/ec788b777871ea857cbf97307c63a731597ed25cbb2276840ab764dd7c67/django_active_link-0.2.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-08 11:07:31",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "valerymelou",
    "github_project": "django-active-link",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "tox": true,
    "lcname": "django-active-link"
}
        
Elapsed time: 0.25838s