django-template-analyzer


Namedjango-template-analyzer JSON
Version 2.1 PyPI version JSON
download
home_pagehttps://github.com/edoburu/django-template-analyzer
SummaryDjango Template Analyzer - Extract template nodes from a Django template
upload_time2023-10-16 11:33:24
maintainer
docs_urlNone
authorDiederik van der Boor & Django CMS developers
requires_python
licenseBSD License
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            django-template-analyzer
========================

.. image:: https://github.com/edoburu/django-template-analyzer/actions/workflows/tests.yaml/badge.svg?branch=master
    :target: https://github.com/edoburu/django-template-analyzer/actions/workflows/tests.yaml
.. image:: https://img.shields.io/pypi/v/django-template-analyzer.svg
    :target: https://pypi.python.org/pypi/django-template-analyzer/
.. image:: https://img.shields.io/badge/wheel-yes-green.svg
    :target: https://pypi.python.org/pypi/django-template-analyzer/
.. image:: https://img.shields.io/codecov/c/github/edoburu/django-template-analyzer/master.svg
    :target: https://codecov.io/github/edoburu/django-template-analyzer?branch=master

The ``template_analyzer`` package offers an API to analyze the Django template structure.
It can be used to find nodes of a particular type, e.g. to do automatic detection of placeholder tags.

Supported features
==================

The scanner finds tags in various situations, including:

* Extend nodes
* Include nodes
* Overwritten blocks with new definitions
* Blocks with or without ``{{ block.super }}``
* Reorganized blocks
* Ignoring nodes outside blocks in extending templates
* Handling multiple levels of super includes

The returned nodes are provided in a natural ordering,
as they would be expected to appear in the outputted page.

While Django offers a ``template.nodelist.get_nodes_of_type()`` function,
this function does not produce the same results.


API example
===========

.. code-block:: python

    from django.template.loader import get_template
    from mycms.templatetags.placeholdertags import Placeholder
    from template_analyzer.djangoanalyzer import get_node_instances

    # Load a Django template
    template = get_template("mycms/default-page.html")

    # Find all tags in the template:
    placeholders = get_node_instances(template, Placeholder)

    # Read information from the template tag themselves:
    # (this is an example, accessing a custom method on the Placeholder object)
    placeholder_names = [p.get_name() for p in placeholders]

Installation
============

First install the module, preferably in a virtual environment. It can be installed from PyPI::

    pip install django-template-analyzer

Or the current folder can be installed::

    pip install .

Credits
=======

* This package is based on the work of
  `Django CMS <http://www.django-cms.org>`_. 
* Many thanks to the contributors of ``cms/utils/placeholder.py`` / ``cms/utils/plugins.py`` in Django CMS!

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/edoburu/django-template-analyzer",
    "name": "django-template-analyzer",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Diederik van der Boor & Django CMS developers",
    "author_email": "opensource@edoburu.nl",
    "download_url": "https://files.pythonhosted.org/packages/2e/6a/3b16854a12743c0896b9837eb338537a6dbc47b01c897f8410814c08cfdc/django-template-analyzer-2.1.tar.gz",
    "platform": "OS Independent",
    "description": "django-template-analyzer\n========================\n\n.. image:: https://github.com/edoburu/django-template-analyzer/actions/workflows/tests.yaml/badge.svg?branch=master\n    :target: https://github.com/edoburu/django-template-analyzer/actions/workflows/tests.yaml\n.. image:: https://img.shields.io/pypi/v/django-template-analyzer.svg\n    :target: https://pypi.python.org/pypi/django-template-analyzer/\n.. image:: https://img.shields.io/badge/wheel-yes-green.svg\n    :target: https://pypi.python.org/pypi/django-template-analyzer/\n.. image:: https://img.shields.io/codecov/c/github/edoburu/django-template-analyzer/master.svg\n    :target: https://codecov.io/github/edoburu/django-template-analyzer?branch=master\n\nThe ``template_analyzer`` package offers an API to analyze the Django template structure.\nIt can be used to find nodes of a particular type, e.g. to do automatic detection of placeholder tags.\n\nSupported features\n==================\n\nThe scanner finds tags in various situations, including:\n\n* Extend nodes\n* Include nodes\n* Overwritten blocks with new definitions\n* Blocks with or without ``{{ block.super }}``\n* Reorganized blocks\n* Ignoring nodes outside blocks in extending templates\n* Handling multiple levels of super includes\n\nThe returned nodes are provided in a natural ordering,\nas they would be expected to appear in the outputted page.\n\nWhile Django offers a ``template.nodelist.get_nodes_of_type()`` function,\nthis function does not produce the same results.\n\n\nAPI example\n===========\n\n.. code-block:: python\n\n    from django.template.loader import get_template\n    from mycms.templatetags.placeholdertags import Placeholder\n    from template_analyzer.djangoanalyzer import get_node_instances\n\n    # Load a Django template\n    template = get_template(\"mycms/default-page.html\")\n\n    # Find all tags in the template:\n    placeholders = get_node_instances(template, Placeholder)\n\n    # Read information from the template tag themselves:\n    # (this is an example, accessing a custom method on the Placeholder object)\n    placeholder_names = [p.get_name() for p in placeholders]\n\nInstallation\n============\n\nFirst install the module, preferably in a virtual environment. It can be installed from PyPI::\n\n    pip install django-template-analyzer\n\nOr the current folder can be installed::\n\n    pip install .\n\nCredits\n=======\n\n* This package is based on the work of\n  `Django CMS <http://www.django-cms.org>`_. \n* Many thanks to the contributors of ``cms/utils/placeholder.py`` / ``cms/utils/plugins.py`` in Django CMS!\n",
    "bugtrack_url": null,
    "license": "BSD License",
    "summary": "Django Template Analyzer - Extract template nodes from a Django template",
    "version": "2.1",
    "project_urls": {
        "Download": "https://github.com/edoburu/django-template-analyzer/zipball/master",
        "Homepage": "https://github.com/edoburu/django-template-analyzer"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b194b6bc4929010486826b6c750b9a32bc87a7d6291c3a2b51d836c154ce74c1",
                "md5": "6325598aff30941ba4cf8e0e773acd36",
                "sha256": "f528ee9712c508bdec31f36a57a69c85a704b3df723454cc43786af908b758cb"
            },
            "downloads": -1,
            "filename": "django_template_analyzer-2.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6325598aff30941ba4cf8e0e773acd36",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 10907,
            "upload_time": "2023-10-16T11:33:23",
            "upload_time_iso_8601": "2023-10-16T11:33:23.402640Z",
            "url": "https://files.pythonhosted.org/packages/b1/94/b6bc4929010486826b6c750b9a32bc87a7d6291c3a2b51d836c154ce74c1/django_template_analyzer-2.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2e6a3b16854a12743c0896b9837eb338537a6dbc47b01c897f8410814c08cfdc",
                "md5": "ba9922185fc70286a65d9ae7bdb6885f",
                "sha256": "aacacf114a23f65b3f967319fb49284b413a9596652bc6594b63aba82db06b89"
            },
            "downloads": -1,
            "filename": "django-template-analyzer-2.1.tar.gz",
            "has_sig": false,
            "md5_digest": "ba9922185fc70286a65d9ae7bdb6885f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 9510,
            "upload_time": "2023-10-16T11:33:24",
            "upload_time_iso_8601": "2023-10-16T11:33:24.491691Z",
            "url": "https://files.pythonhosted.org/packages/2e/6a/3b16854a12743c0896b9837eb338537a6dbc47b01c897f8410814c08cfdc/django-template-analyzer-2.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-16 11:33:24",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "edoburu",
    "github_project": "django-template-analyzer",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "django-template-analyzer"
}
        
Elapsed time: 0.16907s