{ "info": { "author": "David Cramer", "author_email": "dcramer@gmail.com", "bugtrack_url": null, "classifiers": [ "Framework :: Django", "Intended Audience :: Developers", "Intended Audience :: System Administrators", "Operating System :: OS Independent", "Topic :: Software Development" ], "description": "Coffin: Jinja2 adapter for Django\n---------------------------------\n\n\nSupported Django template functionality\n=======================================\n\nCoffin currently makes the following Django tags available in Jinja:\n\n- {% cache %} - has currently an incompatibility: The second argument\n (the fragment name) needs to be specified with surrounding quotes\n if it is supposed to be a literal string, according to Jinja2 syntax.\n It will otherwise be considered an identifer and resolved as a\n variable.\n\n- {% load %} - is actually a no-op in Coffin, since templatetag\n libraries are always loaded. See also \"Custom Filters and extensions\".\n\n- {% spaceless %}\n\n- {% url %} - additionally, a ``\"view\"|url()`` filter is also\n available.\n\n- {% with %}\n\n- {% csrf_token %}\n\nDjango filters that are ported in Coffin:\n\n- date\n- floatformat\n- pluralize (expects an optional second parameter rather than the\n comma syntax)\n- time\n- timesince\n- timeuntil\n- truncatewords\n- truncatewords_html\n\nNote that for the most part, you can simply use filters written for Django\ndirectly in Coffin. For example, ``django.contrib.markup`` \"just works\" (tm).\n\nThe template-related functionality of the following contrib modules has\nbeen ported in Coffin:\n\n- ``coffin.contrib.syndication``.\n\nJinja 2's ``i18n`` extension is hooked up with Django, and a custom version\nof makemessages supports string extraction from both Jinja2 and Django\ntemplates.\n\nAutoescape\n==========\n\nWhen using Auto Escape you will notice that marking something as a\nSafestrings with Django will not affect the rendering in Jinja 2. To fix this\nyou can monkeypatch Django to produce Jinja 2 compatible Safestrings::\n\n '''Monkeypatch Django to mimic Jinja2 behaviour'''\n from django.utils import safestring\n if not hasattr(safestring, '__html__'):\n safestring.SafeString.__html__ = lambda self: str(self)\n safestring.SafeUnicode.__html__ = lambda self: unicode(self)\n\nRendering\n=========\n\nChange the TEMPLATE_LOADERS settings to contain only the following loader::\n\n TEMPLATE_LOADERS = (\n 'coffin.template.loaders.Loader',\n )\n\nAnd move all previously defined template loaders to the\nJINJA2_TEMPLATE_LOADERS setting directive::\n\n JINJA2_TEMPLATE_LOADERS = (\n 'django.template.loaders.app_directories.Loader',\n 'django.template.loaders.filesystem.Loader',\n )\n\nFrom now on, all of your views, generic views and error pages will be handled\nand rendered by Jinja2.\n\nUsing the django rendering engine\n=================================\n\nIf your project uses some applications which needs to original django\ntemplating engine to correctly render their templates, you can add their names\nto a JINJA2_DISABLED_TEMPLATES setting and coffin will render the templates using\nthe django templating engine.\n\nIf you use the built-in admin app, you have then to add the following setting::\n\n JINJA2_DISABLED_TEMPLATES = (\n 'admin',\n )\n\nEach entry in the JINJA2_DISABLED_TEMPLATES iterable is treated as a regex\npattern and every template is tested against them to check if it has to be\nrendered using Jinja+Coffin or with the built-in templating engine.\n\nYou can define the settings as shown in the following example::\n\n JINJA2_DISABLED_TEMPLATES = (\n r'[^/]+\\.html', # All generic templates\n r'myapp/(registration|photos|calendar)/', # The three apps in the myapp package\n r'auth/', # All auth templates\n r'(cms|menu|admin|admin_doc)/', # The templates of these 4 apps\n )\n\n\n404 and 500 handlers\n====================\n\nTo have your HTTP 404 and 500 template rendered using Jinja, replace the\nline::\n\n from django.conf.urls.defaults import *\n\nin your ``urls.py`` (it should be there by default), with::\n\n from coffin.conf.urls.defaults import *\n\n\nCustom filters and extensions\n=============================\n\nCoffin uses the same templatetag library approach as Django, meaning\nyour app has a ``templatetags`` directory, and each of it's modules\nrepresents a \"template library\", providing new filters and tags.\n\nA custom ``Library`` class in ``coffin.template.Library`` can be used\nto register Jinja-specific components.\n\nCoffin can automatically make your existing Django filters usable in\nJinja, but not your custom tags - you need to rewrite those as Jinja\nextensions manually.\n\nExample for a Jinja-enabled template library::\n\n from coffin import template\n register = template.Library()\n\n register.filter('plenk', plenk) # Filter for both Django and Jinja\n register.tag('foo', do_foo) # Django version of the tag\n register.tag(FooExtension) # Jinja version of the tag\n register.object(my_function_name) # A global function/object\n register.test(my_test_name) # A test function\n\nYou may also define additional extensions, filters, tests and globals via your ``settings.py``::\n\n JINJA2_FILTERS = (\n 'path.to.myfilter',\n )\n JINJA2_TESTS = {\n 'test_name': 'path.to.mytest',\n }\n JINJA2_EXTENSIONS = (\n 'jinja2.ext.do',\n )\n\n\nOther things of note\n====================\n\nWhen porting Django functionality, Coffin currently tries to avoid\nDjango's silent-errors approach, instead opting to be explicit. Django was\ndiscussing the same thing before it's 1.0 release (*), but was constrained\nby backwards-compatibility concerns. However, if you are converting your\ntemplates anyway, it might be a good opportunity for this change.\n\n(*) http://groups.google.com/group/django-developers/browse_thread/thread/f323338045ac2e5e\n\n``coffin.template.loader`` is a port of ``django.template.loader`` and\ncomes with a Jinja2-enabled version of ``get_template()``.\n\n``coffin.template.Template`` is a Jinja2-Template that supports the\nDjango render interface (being passed an instance of Context), and uses\nCoffin's global Jinja2 environment.\n\n``coffin.interop`` exposes functionality to manually convert Django\nfilters to Jinja2 and vice-versa. This is also what Coffin's ``Library``\nobject uses.\n\nA Jinja2-enabled version of ``add_to_builtins`` can be found in the\n``django.template`` namespace.\n\nYou may specify additional arguments to send to the ``Environment`` via ``JINJA2_ENVIRONMENT_OPTIONS``::\n\n from jinja2 import StrictUndefined\n JINJA2_ENVIRONMENT_OPTIONS = {\n 'autoescape': False,\n 'undefined': StrictUndefined,\n }\n\nThings not supported by Coffin\n==============================\n\nThese is an incomplete list things that Coffin does not yet and possibly\nnever will, requiring manual changes on your part:\n\n- The ``slice`` filter works differently in Jinja2 and Django.\n Replace it with Jinja's slice syntax: ``x[0:1]``.\n\n- Jinja2's ``default`` filter by itself only tests the variable for\n **existance**. To match Django's behaviour, you need to pass ``True``\n as the second argument, so that it will also provide the default\n value for things that are defined but evalute to ``False``\n\n- Jinja2's loop variable is called ``loop``, but Django's ``forloop``.\n\n- Implementing an equivalent to Django's cycle-tag might be difficult,\n see also Django tickets #5908 and #7501. Jinja's own facilities\n are the ``forloop.cycle()`` function and the global function\n ``cycler``.\n\n- The ``add`` filter might not be worth being implemented. ``{{ x+y }}``\n is a pretty basic feature of Jinja2, and could almost be lumped\n together with the other Django->Jinja2 syntax changes.\n\n- Django-type safe strings passed through the context are not converted\n and therefore not recognized by Jinja2. For example, a notable place\n were this would occur is the HTML generation of Django Forms.\n\n- The {% autoescape %} tag is immensily difficult to port and currently\n not supported.\n\n- Literal strings from within a template are not automatically\n considered \"safe\" by Jinja2, different from Django. According to\n Armin Ronacher, this is a design limitation that will not be changed,\n due to many Python builtin functions and methods, whichyou are free\n to use in Jinja2, expecting raw, untainted strings and thus not being\n able to work with Jinja2's ``Markup`` string.\n\n\nRunning the tests\n====================\n\nUse the nose framework:\n\n http://somethingaboutorange.com/mrl/projects/nose/\n\n", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/coffin/coffin", "keywords": null, "license": "UNKNOWN", "maintainer": null, "maintainer_email": null, "name": "Coffin-GaretJax", "package_url": "https://pypi.org/project/Coffin-GaretJax/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/Coffin-GaretJax/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://github.com/coffin/coffin" }, "release_url": "https://pypi.org/project/Coffin-GaretJax/0.3.8.dev/", "requires_dist": null, "requires_python": null, "summary": "Jinja2 adapter for Django, modified version", "version": "0.3.8.dev" }, "last_serial": 809308, "releases": { "0.3.8.dev": [ { "comment_text": "", "digests": { "md5": "2f9a9aede5faa698707d3294d6935468", "sha256": "33b08667ecb567b0a824363ac9b9fe267e4f476c1d9971a28f6224d6408ba0d5" }, "downloads": -1, "filename": "Coffin-GaretJax-0.3.8.dev.tar.gz", "has_sig": false, "md5_digest": "2f9a9aede5faa698707d3294d6935468", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 33832, "upload_time": "2013-07-05T22:21:07", "url": "https://files.pythonhosted.org/packages/a2/d5/bbbf1dadb1f460122ec54b201b375a24e65d5897b6f70099d8ce7fb66b54/Coffin-GaretJax-0.3.8.dev.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "2f9a9aede5faa698707d3294d6935468", "sha256": "33b08667ecb567b0a824363ac9b9fe267e4f476c1d9971a28f6224d6408ba0d5" }, "downloads": -1, "filename": "Coffin-GaretJax-0.3.8.dev.tar.gz", "has_sig": false, "md5_digest": "2f9a9aede5faa698707d3294d6935468", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 33832, "upload_time": "2013-07-05T22:21:07", "url": "https://files.pythonhosted.org/packages/a2/d5/bbbf1dadb1f460122ec54b201b375a24e65d5897b6f70099d8ce7fb66b54/Coffin-GaretJax-0.3.8.dev.tar.gz" } ] }