{ "info": { "author": "Thomas Binetruy", "author_email": "tbinetruy@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": "* Description\nVery basic Python functions to generate HTML in a compasable way.\n\n* Usage\n\nVery much inspired from React.\n\nA component is any function that returns the result of a ~create_element~ call. This function that the element name,\n\nLet us first define a Text component. We will create a text element without any attributes:\n\n#+begin_src python :session\nfrom chp import create_element, create_prop, render_element\n\ndef Text(t):\n return create_element(\"span\", [], t)\n\nt = Text(\"YourLabs\")\nrender_element(t)\n# outputs => \"YourLabs\"\n#+end_src\n\n#+RESULTS:\n: YourLabs\n\nLet's now use this component to display text inside of a link:\n\n\n#+begin_src python :session\ndef Link(href, children):\n href = create_prop(\"href\", href)\n return create_element(\"a\", [href], children)\n\nl = Link(\"yourlabs.org\", [Text(\"YourLabs\")])\nrender_element(l)\n# outputs => \"YourLabs\"\n#+end_src\n\n#+RESULTS:\n: YourLabs\n\nLet us now define a Menu component that will create links inside of a nav element based on some input. Let's also rename out ~create_element~ and ~create_prop~ functions to ~ce~ and ~cp~ respectively\n\n#+begin_src python :session\nce = create_element\ncp = create_prop\n\ndef Menu(links=[]):\n c = [] # menu children links array\n for l in links:\n el = Link(l[\"href\"], [Text(l[\"text\"])])\n c.append(el)\n\n return ce(\"nav\", [cp(\"class\", \"menu\")], c)\n\nlinks = [\n {\n \"href\": \"yourlabs.org\",\n \"text\": \"YourLabs\",\n },\n {\n \"href\": \"novamedia.nyc\",\n \"text\": \"NovaMedia\",\n },\n]\n\nm = Menu(links)\nrender_element(m)\n# outputs => \n#+end_src\n\n#+RESULTS:\n\nPretty printed, this final output is:\n#+begin_src html\n\n#+end_src\n\nFeel free to check out the app.py and components.py files to see how a full page can be built easily using this method. The app.py file writes the html output to another file called output.html.\n\n* Trying it\n#+begin_src bash\ngit clone git@github.com:tbinetruy/CHIP.git\ncd CHIP\n\npython app.py # write html to output.html file\nfirefox output.html\n#+end_src\n\n* Examples\n\nTo run the example project:\n- pip install --user --editable path/to/chp[dev]\n- yarn install; yarn start\n- chp-django runserver\n- py.test path/to/chp\n\n#+begin_src python\nimport chp\n\ndef FormSchema(is_checked):\n return chp.Form([\n chp.Row([\n chp.Input('username'),\n chp.CheckboxField(is_checked),\n ])\n ])\n\nclass PostForm(forms.ModelForm):\n def render(self):\n is_checked = 'checked' # self.checked\n return mark_safe(FormSchema(is_checked).render_element(Form))\n\n#+end_src\n\n~phtml~ becomes a string containing the following html code:\n\n#+begin_src html\n
\n
\n \n
\n
\n \n
\n \n
\n
\n
\n
\n {% for error in form.non_field_errors %}\n {{ error }}\n {% endfor %}\n
\n
\n#+end_src\n\n* TODOS\n- Testing of the pyreact.py file. Some of the high level results were copy pasted into tests.org\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/tbinetruy/CHIP", "keywords": "html", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "chp", "package_url": "https://pypi.org/project/chp/", "platform": "", "project_url": "https://pypi.org/project/chp/", "project_urls": { "Homepage": "https://github.com/tbinetruy/CHIP" }, "release_url": "https://pypi.org/project/chp/0.0.1/", "requires_dist": null, "requires_python": "", "summary": "Composable HTML in Python", "version": "0.0.1" }, "last_serial": 4340290, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "28f43f3bfe37152a2516cc1ba61a3be9", "sha256": "451a2136c1dfcf26c724faf7e81bf5e537fb79bc1d89a6725cfb244ca4b88a2f" }, "downloads": -1, "filename": "chp-0.0.1.tar.gz", "has_sig": true, "md5_digest": "28f43f3bfe37152a2516cc1ba61a3be9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6605, "upload_time": "2018-07-30T22:41:40", "url": "https://files.pythonhosted.org/packages/21/ab/1d58cafab2cd019fb95fe79185c9d1d612552f77870aa7aa643d0a48cfcf/chp-0.0.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "28f43f3bfe37152a2516cc1ba61a3be9", "sha256": "451a2136c1dfcf26c724faf7e81bf5e537fb79bc1d89a6725cfb244ca4b88a2f" }, "downloads": -1, "filename": "chp-0.0.1.tar.gz", "has_sig": true, "md5_digest": "28f43f3bfe37152a2516cc1ba61a3be9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6605, "upload_time": "2018-07-30T22:41:40", "url": "https://files.pythonhosted.org/packages/21/ab/1d58cafab2cd019fb95fe79185c9d1d612552f77870aa7aa643d0a48cfcf/chp-0.0.1.tar.gz" } ] }