{ "info": { "author": "Graham Bell", "author_email": "graham.s.bell@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Environment :: Web Environment", "Intended Audience :: Developers", "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "OrderBlocks Extension for Jinja2\n================================\n\nIntroduction\n------------\n\nThis is an extension for the `Jinja2 `_\ntemplate engine which allows you to select and reorder inheritance blocks.\n\n\nExample 1: Ordering Specified by Child Template\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nIn this example, a website might wish to publish a number of articles.\nEach article shows some basic information about the article, the main\nstory itself and perhaps some images.\nThis could be done with a template `\"article.html\"` which\ninherits from the website's main `\"layout.html\"` template and\noverrides the `content` block to contain three new blocks:\n`introduction`, `story` and `images`::\n\n {% extends 'layout.html' %}\n\n {% block content %}\n {% orderblocks article_order %}\n {% block introduction %}\n \n {% endblock %}\n\n {% block story %}\n

Article story goes here …

\n {% endblock %}\n\n {% block images %}\n

\n \n

\n {% endblock %}\n {% endorderblocks %}\n {% endblock %}\n\nNote that the blocks are enclosed in the `orderblocks` tag.\nThis takes one argument, specifying the order in which to show the\ncontained blocks.\n(Any non-block contents are ignored.)\nIn this case this argument is given by the `article_order` parameter.\nWhen this is undefined, as it is here, (or None) the blocks are shown in their\noriginal ordering.\n\nHowever there might also be some special kinds of articles, such as\nan image feature article.\nHere the images should appear in a special display before the story text.\nThe template for this kind of article can inherit from the `\"article.html\"`\ntemplate but specify a value for the `article_order` parameter::\n\n {% extends 'article.html' %}\n\n {% set article_order = ('introduction', 'images', 'story') %}\n\n {% block images %}\n \n {{ super() }}\n {% endblock %}\n\nExample 2: Dynamically-specified Ordering\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nThe block ordering parameter can of course also be specified by\na template context parameter.\nHere a page allows the user to specify which sections\nthey wish to see, and their ordering, via a request argument::\n\n from flask import Flask, render_template, request\n\n app = Flask(__name__)\n\n app.jinja_options['extensions'].append(\n 'jinja2_orderblocks.OrderBlocks')\n\n @app.route('/example/')\n def example_page():\n return render_template(\n 'example_template.html',\n article_order=request.args['order'].split(','))\n\nIt could be used with a template which included a number of sections,\nsuch as the following fragment::\n\n {% orderblocks article_order %}\n {% block x %}\n
\n

Section X

\n

\n
\n {% endblock %}\n\n {% block y %}\n
\n

Section Y

\n

\n
\n {% endblock %}\n\n {% block z %}\n
\n

Section Z

\n

\n
\n {% endblock %}\n {% endorderblocks %}\n\nThe sections could be requested in reverse order via\n`http://.../example/?order=z,y,x`\nor a single section could be requested using\n`http://.../example/?order=y`.\n\nNote on Implementation\n~~~~~~~~~~~~~~~~~~~~~~\n\nThis extension, as currently implemented, works by replacing the\n`orderblocks` tag with a for loop which iterates over the list of\nrequested block names, and includes blocks which match the requested\nnames.\nIn other words it converts a structure like this::\n\n {% orderblocks block_order %}\n {% block x %}\n

X

\n {% endblock %}\n\n {% block y %}\n

Y

\n {% endblock %}\n {% endorderblocks %}\n\ninto a for loop of if blocks such as::\n\n {% for block_name in block_order %}\n {% if block_name == 'x' %}\n {% block x %}\n

X

\n {% endblock %}\n {% endif %}\n\n {% if block_name == 'y' %}\n {% block y %}\n

Y

\n {% endblock %}\n {% endif %}\n {% endfor %}\n\nInstallation\n------------\n\nThe extension can be installed using the ``setup.py`` script::\n\n python setup.py install\n\nBefore doing that, you might like to run the unit tests::\n\n PYTHONPATH=lib python -m unittest discover\n\nLicense\n-------\n\nThis program is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with this program. If not, see .", "description_content_type": null, "docs_url": null, "download_url": null, "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/grahambell/jinja2-orderblocks", "keywords": null, "license": "UNKNOWN", "maintainer": null, "maintainer_email": null, "name": "jinja2_orderblocks", "package_url": "https://pypi.org/project/jinja2_orderblocks/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/jinja2_orderblocks/", "project_urls": { "Homepage": "http://github.com/grahambell/jinja2-orderblocks" }, "release_url": "https://pypi.org/project/jinja2_orderblocks/0.1.0/", "requires_dist": null, "requires_python": null, "summary": "OrderBlocks Extension for Jinja2", "version": "0.1.0" }, "last_serial": 2431784, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "3e2597120e3a798245a5a132ebb3a87e", "sha256": "f836038fe1b4e2057029a220ab77d3ec53484d222de5ebd97890bd85ed9e3041" }, "downloads": -1, "filename": "jinja2_orderblocks-0.1.0.tar.gz", "has_sig": false, "md5_digest": "3e2597120e3a798245a5a132ebb3a87e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 16924, "upload_time": "2016-10-30T18:03:52", "url": "https://files.pythonhosted.org/packages/5e/b3/321dd62092b39ce17987a8ccc006b845b2776911ade66719825e5de44a89/jinja2_orderblocks-0.1.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "3e2597120e3a798245a5a132ebb3a87e", "sha256": "f836038fe1b4e2057029a220ab77d3ec53484d222de5ebd97890bd85ed9e3041" }, "downloads": -1, "filename": "jinja2_orderblocks-0.1.0.tar.gz", "has_sig": false, "md5_digest": "3e2597120e3a798245a5a132ebb3a87e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 16924, "upload_time": "2016-10-30T18:03:52", "url": "https://files.pythonhosted.org/packages/5e/b3/321dd62092b39ce17987a8ccc006b845b2776911ade66719825e5de44a89/jinja2_orderblocks-0.1.0.tar.gz" } ] }