{ "info": { "author": "Autumn Valenta", "author_email": "tvalenta@pivotalenergysolutions.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Environment :: Web Environment", "Framework :: Django", "License :: OSI Approved :: Apache Software License", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Topic :: Internet :: WWW/HTTP", "Topic :: Internet :: WWW/HTTP :: Dynamic Content", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "django-easytag\n==============\n\nA templatetag utility to greatly simplify the design of block-style tags\n\nEasyTag is a ``template.Node`` subclass that adds some automatic mechanisms which greatly simplify the common block-style tasks.\n\n\nYou can add methods to your subclass to handle any custom intermediate tag separators (think the ``for``/``empty``, ``if``/``else``).\n\n## Basic options\n\n### ``name``\n_**Required**_\n\nThe name of the tag as it should be registered with your templatetags library. See [Registering with the tag library](#registering-with-the-tag-library) below to see how to make use of this ``name`` attribute without having to repeat yourself.\n\n### ``end_tag``\n_boolean or str_\n\nIf ``end_tag`` is True, this tag will automatically parse to a matching ``{% end{name} %}`` tag. If ``end_tag`` is a string, it will be taken as-is for the end-block tag. It won't add the \"end\" prefix either, so pick a smart name!\n\n### ``intermediate_tags``\n_list of strings_\n\n``intermediate_tags`` is a list of strings that acts as a declaration of all possible intermediate tag names that can show up in the body of your main tag. For example, if you use ``intermediate_tags = [\"unless\"]``, you could write something like this in your templates:\n\n```html\n{% my_tag %}\n some content\n{% unless %}\n secondary content\n{% endmytag %}\n```\n\nBy default, both of these sections are parsed and rendered, but they are handed off to separate methods on your tag class for processing, allowing you to dynamically decide if or how to render the sibling branches.\n\nYou can have any number of intermediate tags, and they can appear in any order. If you would like to enforce a particular order, you'll need to add some logic to the specific handlers to verify that some other tag came first.\n\n## Setting up handlers for wrapped content\n\nThe beginning tag and intermediate tags will attempt to send their influenced template regions to methods on your tag class. These methods are effectively renderers; you should return the rendered content, whether or not you are modifying anything.\n\nThe simplest case is a pass-through tag:\n\n```python\nclass MyTag(EasyTag):\n name = \"my_tag\"\n\n def my_tag(self, context, nodelist):\n return nodelist.render(context)\n```\n\nYour ``my_tag`` tag should declare a method on itself named the same thing. This is the handler that the wrapped content is sent to. The ``context`` and ``nodelist`` parameters are required.\n\n_Note: In Django parlance, a \"nodelist\" is a collection of template pieces that all know how to render themselves, including chunks of plain text._\n\nIf you have intermediate tags defined note how the definition of \"wrapped content\" changes:\n\n```html\n\n{% my_tag %}\n some content\n{% unless %}\n secondary content\n{% endmytag %}\n```\n\nThe main ``my_tag`` method only receives everything up until the next intermediate block, and the intermediate block receives everything until the _next_ intermediate block or the end tag, and so on.\n\n## Sending parameters\n\nExactly like the built-in django [``simple_tag``](https://docs.djangoproject.com/en/dev/howto/custom-template-tags/#django.template.Library.simple_tag), EasyTag enables automatic forwarding of parameters sent to the tag to a method on your tag.\n\nYour tag's method requires ``context`` and ``nodelist``, but you can add any number of normal function arguments to its signature. This includes arguments with default values, ``*args`` and ``**kwargs`` for catch-alls. The proper errors will be raised if arguments are missing or unexpected.\n\nExample:\n\n```python\n# Handler inside of the MyTag class\ndef my_tag(self, context, nodelist, myflag=False):\n content = nodelist.render(context)\n if myflag is True:\n content = \"