{ "info": { "author": "Roman Rader", "author_email": "antigluk@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Environment :: Web Environment", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5" ], "description": "aio_pybars\n========\n\nQuick Start\n------------------\n\n0. Install::\n\n pip install aio_pybars\n\nOR via setup.py::\n\n python setup.py install\n\n1. Configure your app::\n\n from aio_pybars import FSTemplateLoader\n loop.run_until_complete(aio_pybars.setup(app,\n templates_dir=config['TEMPLATES_DIR'],\n Loader=FSTemplateLoader))\n\n2. Use templates in the view::\n\n async def index(request):\n context = {\"var\": \"value\"}\n return AIOBarsResponse(request, 'template_name', context)\n\nIt will render the `template_name.hbs` template with variables in the `context` to the aiohttp response.\n\nHelpers and partials\n------------------------------------\n\nPartial is the nested template that should be included in the specific place.\nIf the following code occurs in the template::\n\n {{> \"sidebar\"}}\n\npybars3 will search the _partial_ named `sidebar` in the dictionary. How to add your own partial see below.\n\nHelper is the callable that can be called from the template. Syntactically it looks same as the variable, but can\nget the arguments::\n\n \n\nwould call the `asset` callable with \"favicon.ico\" argument and put the results in the rendered template.\n\n*To use your own partials and helpers* implement your subclass of templates loader::\n\n class AppFSTemplateLoader(FSTemplateLoader):\n def __init__(self, app, base_dir):\n super().__init__(app, base_dir)\n\n def get_partials(self):\n \"\"\"\n Load all files in the partials/ subdirectory of templates dir.\n Method should return the dictionary {'partial_name': , ...}\n \"\"\"\n partials = super().get_partials()\n base_partials = os.path.join(self.app.config['TEMPLATES_DIR'], 'partials')\n for name in os.listdir(base_partials):\n filename = os.path.splitext(name)[0]\n template_source = open(os.path.join(base_partials, name), 'r', encoding='utf8').read()\n template = self.compiler.compile(template_source)\n partials[filename] = template\n return partials\n\n def get_helpers(self):\n \"\"\"\n Define your own set of helpers.\n Method should return the dictionary {'helper_name': , ...}\n \"\"\"\n helpers = super().get_helpers()\n helpers.update({\"asset\": _asset})\n return helpers\n\n\n def _asset(options, val, *args, **kwargs):\n return \"/static/{}\".format(val)\n\nand pass it as Loader argument to the setup::\n\n loop.run_until_complete(aio_pybars.setup(app,\n templates_dir=config['TEMPLATES_DIR'],\n Loader=AppFSTemplateLoader))\n\nRecursive rendering of templates\n--------------------------\n\nThe aio_pybars enables templates to be recursive. If the first line of the template contains::\n\n {{!< base_template}}\n\nall the rendered template will be passed as variable `body` to the base template.\n\nFor example:\n\nbase.hbs::\n\n \n \n \n Template\n \n \n {{body}}\n \n\ntest.hbs::\n\n {{!< base}}\n Hello, {{name}}.\n\nThen result of the `render(loader, 'test', {'name': 'Roma'})` will be::\n\n \n \n \n Template\n \n \n Hello, Roma\n ", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/rrader/aio_pybars", "keywords": null, "license": "BSD", "maintainer": null, "maintainer_email": null, "name": "aio_pybars", "package_url": "https://pypi.org/project/aio_pybars/", "platform": "POSIX", "project_url": "https://pypi.org/project/aio_pybars/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/rrader/aio_pybars" }, "release_url": "https://pypi.org/project/aio_pybars/0.1.0/", "requires_dist": null, "requires_python": null, "summary": "pybars3 (handlebars) templates rendering for aiohttp.", "version": "0.1.0" }, "last_serial": 2071971, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "0d38ac946c8d5011b3d93b4ddfe2da76", "sha256": "e0850762a9f30e713ea79a5dc9c080d8a33bd1d14fe9ebf0dd869595c0e48c9b" }, "downloads": -1, "filename": "aio_pybars-0.1.0.tar.gz", "has_sig": false, "md5_digest": "0d38ac946c8d5011b3d93b4ddfe2da76", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3621, "upload_time": "2016-04-19T16:45:34", "url": "https://files.pythonhosted.org/packages/14/ef/e62432c5b998b0151629b53a0b8e6f3f71220fb960d8826c1dedb09b4bb7/aio_pybars-0.1.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "0d38ac946c8d5011b3d93b4ddfe2da76", "sha256": "e0850762a9f30e713ea79a5dc9c080d8a33bd1d14fe9ebf0dd869595c0e48c9b" }, "downloads": -1, "filename": "aio_pybars-0.1.0.tar.gz", "has_sig": false, "md5_digest": "0d38ac946c8d5011b3d93b4ddfe2da76", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3621, "upload_time": "2016-04-19T16:45:34", "url": "https://files.pythonhosted.org/packages/14/ef/e62432c5b998b0151629b53a0b8e6f3f71220fb960d8826c1dedb09b4bb7/aio_pybars-0.1.0.tar.gz" } ] }