{ "info": { "author": "F\u00e1bio Mac\u00eado Mendes", "author_email": "fabiomacedomendes@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: GNU General Public License (GPL)", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Topic :: Software Development :: Libraries" ], "description": ".. image:: https://readthedocs.org/projects/bricks/badge/?version=latest\n :target: http://bricks.readthedocs.io/en/latest/?badge=latest\n :alt: Documentation Status\n.. image:: https://travis-ci.org/fabiommendes/django-bricks.svg?branch=master\n :target: https://travis-ci.org/fabiommendes/django-bricks\n :alt: Build status\n.. image:: https://codeclimate.com/github/fabiommendes/django-bricks/badges/gpa.svg\n :target: https://codeclimate.com/github/fabiommendes/django-bricks\n :alt: Code Climate\n.. image:: https://codecov.io/gh/fabiommendes/django-bricks/branch/master/graph/badge.svg\n :target: https://codecov.io/gh/fabiommendes/django-bricks\n :alt: Code coverage\n.. image:: https://www.quantifiedcode.com/api/v1/project/ee91ade50a344c87ac99638670c76580/badge.svg\n :target: https://www.quantifiedcode.com/app/project/ee91ade50a344c87ac99638670c76580\n :alt: Code issues\n\n\nDjango web components\n---------------------\n\nDjango-brick is a library that implements server-side web components for\nyour Django application. The goal is to reuse code by building simple pluggable\npieces. Think of Lego bricks for the web.\n\n.. image:: media/legos.jpg\n:alt: https://upload.wikimedia.org/wikipedia/commons/thumb/3/32/Lego_Color_Bricks.jpg/1024px-Lego_Color_Bricks.jpg\n\nClient-side programming has plenty responses for this task: React, Polymer,\nVue.js, X-tag etc. Django Bricks provides a server-side alternative that\ncan free you from writing some JavaScript and HTML ;).\n\n\nEnter the brick\n---------------\n\nA brick is a Python component with a a well defined interface to present itself\nfor the client. Usually this means that it can render itself as HTML5 (but\nsometimes we may need more complicated behaviors). Pehaps the most\nsimple brick that you can use is just a HTML5 tag. Django-bricks implement these\nbuilding blocks in the :mod:`bricks.html5` module. The most important action a\n:class:`bricks.Tag` brick can make is to render itself as HTML:\n\n>>> from bricks.html5 import p\n>>> elem = p(\"Hello World!\", class_='hello')\n\nThis can be converted to HTML by calling ``str()`` on the element:\n\n>>> print(str(elem))\n
Hello World!
\n\nPython and HTML have very different semantics. HTML's syntax gravitates\naround tag attributes + children nodes and does not have a very natural\ncounterpart in most programming languages. Of course we can build a tag in a\nimperative style, but the end result often feels awkward. We introduce a\nmini-language to declare HTML fragments in a more natural way:\n\n>>> from bricks.html5 import div, p, h1\n>>> fragment = \\\n... div(class_=\"alert-box\")[\n... h1('Hello Python'),\n... p('Now you can write HTML in Python!'),\n... ]\n\nBy default, bricks convert it to a very compact HTML; we insert no indentation\nand only a minimum whitespace. We can pretty print the fragment using the\n``.pretty`` method:\n\n>>> print(fragment.pretty())\nNow you can write HTML in Python!
\n