Django Template Analyzer - Extract template nodes from a Django template
Project description
django-template-analyzer
========================
.. image:: https://travis-ci.org/edoburu/django-template-analyzer.svg?branch=master
:target: http://travis-ci.org/edoburu/django-template-analyzer
.. 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/pypi/dm/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 .
.. include:: CHANGES.rst
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!
========================
.. image:: https://travis-ci.org/edoburu/django-template-analyzer.svg?branch=master
:target: http://travis-ci.org/edoburu/django-template-analyzer
.. 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/pypi/dm/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 .
.. include:: CHANGES.rst
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!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for django-template-analyzer-1.6.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 12b7cdcacf5b0dc7f54c459b02bd4ad35e61013f509e079b6ae486909c90e8ad |
|
MD5 | e6d3d9a4f98641c1f9be3a3d96d29a48 |
|
BLAKE2b-256 | 4c160e31fb3d46502624cd2d243951bf49bcd92ef5c40d148140cb1fe23d0fec |
Close
Hashes for django_template_analyzer-1.6.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 433029434e79bd0a98f1a35672c6be6d1a363c558fee9f569bc3fae90e51d990 |
|
MD5 | b66dbe19fef045af3e5467b2235eedb4 |
|
BLAKE2b-256 | 11b7a5fe4faeb95beb65882f5ea2c3869753de4e24871371fcb52eb8f5557672 |