Declarative Python DSL for building HTML documents with asynchronous rendering
Project description
Библиотека для декларативного формирования HTML-структуры на Python.
Текущая версия использует асинхронный рендер. Основной публичный API для получения HTML теперь await render().
Актуальная версия проекта: 0.2.0.
Установка
pip install git+https://github.com/opolonix/domica-html.git@v0.2.0
Для локальной разработки:
pip install -e .[dev]
Пример
import asyncio
from domica_html import html, div
async def main():
doc = html()
with doc:
div("hello world")
print(await doc.render())
asyncio.run(main())
output:
<html>
<div>
hello world
</div>
</html>
Реализация собственного компонента
import asyncio
from domica_html import html, div, inc, node_container, script, line
from contextvars import ContextVar
from collections import defaultdict
from typing import Type
external_tags: ContextVar[dict[Type, list["external_container"]]] = ContextVar("external_tags", default=defaultdict(list))
class external_container(node_container):
def __init__(self, *, anchor=False):
super().__init__(anchor=anchor)
if not anchor:
tags = external_tags.get()
tags[self.__class__].append(self)
async def render(self):
tags = external_tags.get()
for child in tags[self.__class__]:
if child is self: continue
self.add_child(child)
with inc(indent=inc.indent-1):
return await super().render()
class global_script(external_container): ...
async def main():
doc = html()
with doc:
with div():
div("Hello world with some script", onclick="hello_on_click")
with global_script():
line("const hello_on_click = () => {")
line(inc.char, "alert('hello!');")
line("}")
with script():
global_script(anchor=True)
print(await doc.render())
asyncio.run(main())
output:
<html>
<div>
<div onclick="hello_on_click">
Hello world with some script
</div>
</div>
<script>
const hello_on_click = () => {
alert('hello!');
}
</script>
</html>
Релизы
0.2.0: асинхронный рендер черезawait render()0.1.5: финальная стабильная синхронная версия ветки0.1.x
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file domica_html-0.2.0.tar.gz.
File metadata
- Download URL: domica_html-0.2.0.tar.gz
- Upload date:
- Size: 9.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aaadfe77fd0e834d6e6d043f6da82ca666fd6177b6c8e8a5b9c6c64ebdff70e7
|
|
| MD5 |
41ee928d84830855c61ad6d71b9f93cf
|
|
| BLAKE2b-256 |
624c049e2372c62b77af3f953a6bb06482f6554d3daabfd902cc3d5ea49f9f2d
|
Provenance
The following attestation bundles were made for domica_html-0.2.0.tar.gz:
Publisher:
publish.yml on opolonix/domica-html
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
domica_html-0.2.0.tar.gz -
Subject digest:
aaadfe77fd0e834d6e6d043f6da82ca666fd6177b6c8e8a5b9c6c64ebdff70e7 - Sigstore transparency entry: 1109418701
- Sigstore integration time:
-
Permalink:
opolonix/domica-html@07f0db069703e35167806c9f5da4b37173a9eaa2 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/opolonix
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@07f0db069703e35167806c9f5da4b37173a9eaa2 -
Trigger Event:
push
-
Statement type:
File details
Details for the file domica_html-0.2.0-py3-none-any.whl.
File metadata
- Download URL: domica_html-0.2.0-py3-none-any.whl
- Upload date:
- Size: 8.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b6f83cbf5446ca4459206b1d11db9ff3219e4d3ef97b3bb8b021d20504bcbae3
|
|
| MD5 |
e4459bb92d624bc683e9c5ad778c41cd
|
|
| BLAKE2b-256 |
090fec237f1812fbbcaa4cb58bb33711607a45ae491c228543696fa0dad0e602
|
Provenance
The following attestation bundles were made for domica_html-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on opolonix/domica-html
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
domica_html-0.2.0-py3-none-any.whl -
Subject digest:
b6f83cbf5446ca4459206b1d11db9ff3219e4d3ef97b3bb8b021d20504bcbae3 - Sigstore transparency entry: 1109418708
- Sigstore integration time:
-
Permalink:
opolonix/domica-html@07f0db069703e35167806c9f5da4b37173a9eaa2 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/opolonix
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@07f0db069703e35167806c9f5da4b37173a9eaa2 -
Trigger Event:
push
-
Statement type: