An intuitive, high performance HTML rendering framework
Project description
htmldoom
An intuitive, high performance HTML rendering framework
Usage
A basic tag
>>> from htmldoom import render, elements as e >>> >>> print(render( ... e.textarea("required", class_="input")("text") ... )) <textarea required class="input">text</textarea>
A fast dynamic elements rendering mechanism
Choose whichever syntax suits you:
Syntax 1
>>> from htmldoom import renders, elements as e >>> >>> @renders( ... e.p()("{x}"), ... e.p()("another {x}"), ... ) ... def render_paras(data: dict) -> dict: ... return {"x": data["x"]} >>> >>> render_paras({"x": "awesome paragraph"}) <p>awesome paragraph</p><p>another awesome paragraph</p>
Syntax 2
>>> from htmldoom import renders, elements as e >>> >>> render_paras = renders( ... e.p()("{x}"), ... e.p()("another {x}"), ... )(lambda data: {"x": data["x"]}) >>> >>> render_paras({"x": "awesome paragraph"}) <p>awesome paragraph</p><p>another awesome paragraph</p>
NOTE: This mechanism compiles the template when the file loads and reuse it.
renders( -- compile-time code -- )( -- runtime code -- )
The more execution you move from runtime to compile-time, the faster it gets.
If you properly use this mechanism and refractor your dynamic pages into smaller components, it might surpass the performance of traditional template rendering engines.
WARNING: It performs a "{rendered_elements}".format(**returned_data)
. So be careful about where you put which code.
A functional style foreach loop with a switch case
>>> from htmldoom import elements as e >>> from htmldoom import functions as fn >>> >>> tuple(fn.foreach(["good", "bad", "evil"])( ... lambda x: fn.switch({ ... x == "good": lambda: e.span(style="color: green")(f"this is {x}"), ... x == "bad": lambda: e.span(style="color: yellow")(f"this is {x}"), ... x == "evil": lambda: e.span(style="color: red")(f"this is {x}"), ... fn.Case.DEFAULT: lambda: fn.Error.throw(ValueError(x)), ... }) ... )) (b'<span style="color: green">this is good</span>', b'<span style="color: yellow">this is bad</span>', b'<span style="color: red">this is evil</span>')
Q/A
What is the goal here?
The primary goal is to make writing dynamic HTML pages cleaner, easier, safer and intuitive in Python.
What about performance?
Although performance is not the primary goal here, it should not be a roadblock. htmldoom is copying the syntax and some of the rendering properties of elm, an existing fast and purely functional programming language that specializes in rendering HTML in virtual doms. Elm does all the optimisation internally, which I believe can be implemented in Python to a great extent.
Is there any benchmark?
Plugins and ecosystem
- moodlmth: Convert raw HTML pages into python source code
- pyramid_htmldoom: htmldoom rendering library plugin for Pyramid
Contributing
Check out the contributing guidelines.
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
File details
Details for the file htmldoom-0.6.3.tar.gz
.
File metadata
- Download URL: htmldoom-0.6.3.tar.gz
- Upload date:
- Size: 9.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 49f1f470fefc239ed71e5604233c6b3ef4fdb1262c1af2980e3cfdf056e92cf7 |
|
MD5 | 8fe4c34b49035f1b1052582827406d72 |
|
BLAKE2b-256 | fa53f3b81640460216af70a1b018d616fe9b949bf3a1343f4568f305a79f5502 |
File details
Details for the file htmldoom-0.6.3-py3-none-any.whl
.
File metadata
- Download URL: htmldoom-0.6.3-py3-none-any.whl
- Upload date:
- Size: 11.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d72b2f3b0e29987cd32be25c00b3ee0fd407b07dd16717cf2fd649625b79fd47 |
|
MD5 | a110857f6db5042d47eef876e960bdd5 |
|
BLAKE2b-256 | 7b61f3156f2469810f61f23877ab12ffe5a6035b12e964e659fded7e11dc2930 |