{ "info": { "author": "James Pic", "author_email": "jamespic@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 1 - Planning", "Environment :: Web Environment", "Framework :: Django", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 3", "Topic :: Internet :: WWW/HTTP", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "Welcome to phtml !\n~~~~~~~~~~~~~~~~~~\n\nphtml is a silly python library to generate HTML in Python like you would with a template, but refactor-oriented with a Pythonic React-like pattern based on nested components.\n\nComponent base\n==============\n\nThe base component class is Node:\n\n.. code-block:: python\n\n from phtml import Node\n\n form_layout = Node(\n 'form', # node.tag\n { # node.attrs\n 'class': 'foo', # node.attrs['class']\n 'method': 'POST', # node.attrs['method']\n },\n [ # node.children\n '{{ form.as_p() }}', # node.children[0]\n Node('input', {'type': 'submit'}, selfclose=True),\n ],\n )\n\nCasting form_layout to string will return the following:\n\n.. code-block:: django\n\n
\n {{ form.as_p() }}\n \n
\n\n\nRendering\n=========\n\nWhile calling ``phtml.jinja.render(form_layout, form=YourForm())`` will\nreturn the phtml output processed with form in the context and produce the\nfinal result.\n\nThe whole purpose is refactoring HTML generating logic into Python components:\n\n.. code-block:: python\n\n from phtml import Form, Submit\n\n form_layout = Form(\n {'class': 'foo'},\n ['{{ form.as_p() }}', Submit())],\n )\n\nImporting on the fly\n====================\n\n.. code-block:: python\n\n from phtml import Node\n\n form_layout = Node.factory(\n 'phtml.Form', {'class': 'foo'},\n ['{{ form.as_p() }}', Node('phtml.Submit')],\n )\n\nJinja and Materialize for the poor\n==================================\n\nSuppose you want to make a nice layout for the login form, please don't repeat\nboring and verbose code like this because somewhere in the world a cat would\nprobably die because of a side effect in an alternate reality or something:\n\n.. code-block:: python\n\n from phtml import Form, Div\n\n your_layout = Form(\n Div({'class': 'row'}, [\n Div({'class': 'col m6 s12'}, ['{{ form[\"username\"] }}']),\n Div({'class': 'col m6 s12'}, ['{{ form[\"password\"] }}']),\n ]),\n )\n\nRefactored components for the rich\n==================================\n\nInstead make a beautiful layout with reusable components:\n\n.. code-block:: python\n\n from phtml.django.mdc import Form, Row, Col, Input\n\n class YourLoginForm(forms.LoginForm):\n _phtml = Form(\n Row(\n Col(m=6, s=12, Input('username')),\n Col(m=6, s=12, Input('password')),\n )\n )\n\n.. note:: For the documentation of the constructor of each component, please\n fill in their docstrings under their signature in Python code, UTSL !\n\nSilly and Stupid context based rendering\n========================================\n\nYou could render as such in jinja (or in Python without the curly braces):\n``{{ form._phtml.jinja(form) }}``, since all rendering logic should already be\nin phtml.\n\nThank you\n=========\n\nThanks a lot for reading. Hope this will serve as a useful example for anybody\non a mission to \"refactor HTML in Python\".\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/yourlabs/phtml", "keywords": "html", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "phtml", "package_url": "https://pypi.org/project/phtml/", "platform": "", "project_url": "https://pypi.org/project/phtml/", "project_urls": { "Homepage": "https://github.com/yourlabs/phtml" }, "release_url": "https://pypi.org/project/phtml/0.0.1/", "requires_dist": null, "requires_python": "", "summary": "Refactor HTML in Python", "version": "0.0.1" }, "last_serial": 4046374, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "d52afd2ef22cc25e65235f1fad528757", "sha256": "c8503b1ecdf4a67fd31ba7f43d7b6de18ce7c249ca279aefa0dab2a9342f61e8" }, "downloads": -1, "filename": "phtml-0.0.1.tar.gz", "has_sig": true, "md5_digest": "d52afd2ef22cc25e65235f1fad528757", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4017, "upload_time": "2018-07-10T07:16:24", "url": "https://files.pythonhosted.org/packages/c8/2f/9c2ff4317d3f0bd773273aba4e0f96036f66b85212038882ee17df39253e/phtml-0.0.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "d52afd2ef22cc25e65235f1fad528757", "sha256": "c8503b1ecdf4a67fd31ba7f43d7b6de18ce7c249ca279aefa0dab2a9342f61e8" }, "downloads": -1, "filename": "phtml-0.0.1.tar.gz", "has_sig": true, "md5_digest": "d52afd2ef22cc25e65235f1fad528757", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4017, "upload_time": "2018-07-10T07:16:24", "url": "https://files.pythonhosted.org/packages/c8/2f/9c2ff4317d3f0bd773273aba4e0f96036f66b85212038882ee17df39253e/phtml-0.0.1.tar.gz" } ] }