Django Template Analyzer - Extract template nodes from a Django template
Project description
.. image:: https://travis-ci.org/edoburu/django-template-analyzer.png?branch=master
:target: http://travis-ci.org/edoburu/django-template-analyzer
:alt: build-status
Introduction
============
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
===========
::
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!
:target: http://travis-ci.org/edoburu/django-template-analyzer
:alt: build-status
Introduction
============
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
===========
::
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.5.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 814a86b553319a3356fdc7650f63fd55d3112fd601c47e913b8c7dc826cd24be |
|
MD5 | 675520aa799e0e33d8b18b745cdb756c |
|
BLAKE2b-256 | f871853221c2e8efe1891e37a3b3ca5e4d9aa335bec8df42c6a157bb4a7fa6d2 |
Close
Hashes for django_template_analyzer-1.5-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ef66c6001bfe88ed9030480491f4c929e20ed064faecf1a495e93f72e2ae19c9 |
|
MD5 | e63098b4afe15e1dfb7f61ecb6429f75 |
|
BLAKE2b-256 | 32d786c54630cf58ad3afcda51d4e519c96d110cf946afff2144b97d7099384e |