Skip to main content

Build reusable styled HTML components with python.

Project description

Bricka

Build reusable styled HTML components with python.

Installation

pip install bricka

Usage

Creating a basic HTML document.

from bricka.elements import *

with Html(lang="en") as doc:
  with Head():
    Meta(charset="UTF-8")
    Meta(name="viewport", content="width=device-width, initial-scale=1.0") 
    Link(rel="stylesheet", href=f"style.css")
    Title("Document", class_="title")    

  with Body():
    P("My first document with Bricka")  

print(doc.render())  
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="style.css">
    <title class="title">Document</title>
  </head>
  <body>
    <p>My first document with Bricka</p>
  </body>
</html>

Creating a styled table

from bricka.elements import *
from bricka.style import Style

headers = ["Fruit", "Color"]

fruits = [
  ["Banana", "Yellow"],
  ["Orange", "Orange"],
  ["Apricot", "Orange"],
  ["Apple", "Green"],
  ["Lemon", "Yellow"]
]

style: Style = {
  "table": {
    "border": ("1px", "solid", "black"),
    "border-collapse": "collapse",      
  },
  "th": {
    "font-weight": "600",
    "background-color": "aqua",
  },
  "td": {
    "border": ("1px", "solid", "black"),
    "padding-x": "0.75rem",
  },
  "tr": {
    ":hover": {
      "background-color": "fuchsia"
    }
  },
}

with Table(css=style["table"]) as table:
  with Thead():
    with Tr():
      Th("#", css=[style["th"], style["td"]])
      for header in headers:
        Th(header, css=[style["th"], style["td"]])

  with Tbody():
    for i, fruit in enumerate(fruits):
      with Tr(css=style["tr"]):
        Td(i+1, css=style["td"])
        Td(fruit[0], css=style["td"])
        Td(fruit[1], css=style["td"])

print(table.render())
print(table.render_css())

Generated HTML.

<table class="fe6697e7 ff18cedd ">
  <thead>
    <tr>
      <th class="f1acb709 f10a659d fe6697e7 fa3a81d2 fd93d40d ">#</th>
      <th class="f1acb709 f10a659d fe6697e7 fa3a81d2 fd93d40d ">Fruit</th>
      <th class="f1acb709 f10a659d fe6697e7 fa3a81d2 fd93d40d ">Color</th>
    </tr>
  </thead>
  <tbody>
    <tr class="feec5036 ">
      <td class="fe6697e7 fa3a81d2 fd93d40d ">1</td>
      <td class="fe6697e7 fa3a81d2 fd93d40d ">Banana</td>
      <td class="fe6697e7 fa3a81d2 fd93d40d ">Yellow</td>
    </tr>
    <tr class="feec5036 ">
      <td class="fe6697e7 fa3a81d2 fd93d40d ">2</td>
      <td class="fe6697e7 fa3a81d2 fd93d40d ">Orange</td>
      <td class="fe6697e7 fa3a81d2 fd93d40d ">Orange</td>
    </tr>
    <tr class="feec5036 ">
      <td class="fe6697e7 fa3a81d2 fd93d40d ">3</td>
      <td class="fe6697e7 fa3a81d2 fd93d40d ">Apricot</td>
      <td class="fe6697e7 fa3a81d2 fd93d40d ">Orange</td>
    </tr>
    <tr class="feec5036 ">
      <td class="fe6697e7 fa3a81d2 fd93d40d ">4</td>
      <td class="fe6697e7 fa3a81d2 fd93d40d ">Apple</td>
      <td class="fe6697e7 fa3a81d2 fd93d40d ">Green</td>
    </tr>
    <tr class="feec5036 ">
      <td class="fe6697e7 fa3a81d2 fd93d40d ">5</td>
      <td class="fe6697e7 fa3a81d2 fd93d40d ">Lemon</td>
      <td class="fe6697e7 fa3a81d2 fd93d40d ">Yellow</td>
    </tr>
  </tbody>
</table>

Generated CSS.

.fe6697e7 { border: 1px solid black; }
.ff18cedd { border-collapse: collapse; }
.f1acb709 { font-weight: 600; }
.f10a659d { background-color: aqua; }
.fa3a81d2 { padding-left: 0.75rem; }
.fd93d40d { padding-right: 0.75rem; }
.feec5036:hover { background-color: fuchsia; }

Features

Below are the main features of Bricka:

  • Create complex element hierarchies using context managers
  • Append elements with the right and left shift operators
  • Create element siblings with the plus operator
  • Context-aware escaping
  • Support for standard HTML elements
  • Support for standard HTML attributes
  • Code autocompletion for HTML attributes
  • Components styling with pure python
  • Create styles using ready CSS constraints
  • Atomic CSS generation
  • Code autocompletion for CSS properties and constraints
  • Comprehensive unit tests

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bricka-0.3.1.tar.gz (33.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bricka-0.3.1-py3-none-any.whl (33.6 kB view details)

Uploaded Python 3

File details

Details for the file bricka-0.3.1.tar.gz.

File metadata

  • Download URL: bricka-0.3.1.tar.gz
  • Upload date:
  • Size: 33.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for bricka-0.3.1.tar.gz
Algorithm Hash digest
SHA256 90cc7b5f8e560b6d32e85e003c664e24aab70eec3158b24de13ec3d6c1a935db
MD5 28966833592b1e34c6721731dd325b4d
BLAKE2b-256 a67dfc9d71df6797505763139fd01e393e727421dc291327a196b6baf3cf8025

See more details on using hashes here.

File details

Details for the file bricka-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: bricka-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 33.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for bricka-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d5192b4e4bad8bf7d904577d513781bf3158aae8c4f5f757fb61991d39477c72
MD5 c529e8364aca5e1cf9703848d8fa50ed
BLAKE2b-256 4b88e9019227e51b458102f0c0924c140fd35ffd7a9ed2518c10095d731b8f6b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page