Releases: thomasborgen/hypermedia
5.3.3
Version 5.3.3
- Fixes bug with svg element dumping. (#48)[https://github.com//issues/48]
5.3.2
Version 5.3.2
- Fixes
style
attribute rendering.
5.3.1
Version 5.3.1
- Adds
lang
as an attribute to theHtml
element.
5.3.0 - SafeString - Bypass html escaping
Version 5.3.0
Feature
- Adds
SafeString
type as a wrapper around the normalstr
class. This can be used to tell hypermedia not tohtml.escape
the string in any element.
Div("this is always escaped")
Div(SafeString("This will not be escaped"))
- Hypermedia is now cachable - All calls to
.dump()
now returns aSafeString
. This means that caching a dumped element is now possible because we won't callhtml.escape
on it again.
@lru_cache()
def stylesheets() -> SafeString:
return ElementList(
Link(
rel="stylesheet",
href="/static/css/normalize.css",
type="text/css",
),
Link(
rel="stylesheet",
href="/static/css/simple.min.css",
type="text/css",
)
).dump()
def base():
"""
Once `stylesheets()` is called once, it will always use the cached String in subsequent
calls to `base()`
"""
return ElementList(
Doctype(),
Html(
Head(
Meta(charset="UTF-8"),
stylesheets(),
slot="head",
),
Body(...)
lan="en",
),
)
Script
andStyle
elements wraps input inSafeString
by default.
Script("This is wrapped in `SafeString` by default")
Style("This is wrapped in `SafeString` by default")
5.2.0 - Hyperscript
What's Changed
Version 5.2.0
Feature
- Can now use hyperscript with the
_
attribute that renders as:_='value'
by @thomasborgen in #35
Fix
- Fix missing Alias for the
for_
attribute. It now renders correctly asfor='value'
by @thomasborgen in #36
Full Changelog: 5.1.0...5.2.0
5.1.0
Version 5.1.0
Fix
- Calling
dump()
, more specificallyrender_attributes()
popped outclass_
andclasses
attributes from the element. So subsequent calls would be missing the attributes. This fixes that. PR
Full Changelog: 5.0.0...5.1.0
5.0.0
Version 5.0.0
Breaking
We need a way to handle html attributes like hx-on:click
or any_weird.format
. At the same time I want it to be easy to add attributes. I've decided to let all kwargs added normally like data_test
where no Alias
is defined will have its underscores replaced with hyphens. Any kwarg that has a $
prefix, will be outputted as is minus the $
. This kwarg can only have been added by spreading a dict into the constructor, so we can assume that it is done on purpose.
- Any attribute that does not have an Alias will have any underscores (
_
) changed to hyphens (-
). - Any attribute that is prefixed with
$
will be outputted as is without the first$
.
ie
# Is a specified attribute(typed) with an Alias:
Div(on_afterprint="test") # <div onafterprint='test'></div>
# Unspecified attribute without Alias:
Div(data_test="test") # <div data-test='test'></div>
# Spreaded without $ prefix gets its underscores changed to hyphens.
Div(**{"funky-format_test.value": True}) # <div funky-format-test.value></div>
# Spreaded with $ prefix
Div(**{"$funky-format_test.value": True}) # <div funky-format_test.value></div>
Div(**{"$funky-format_test.value": "name"}) # <div funky-format_test.value='name'></div>
Feature
classes
andclass_
attributes are now merged.
def test_class_and_classes_are_combined() -> None:
element = TestElement(class_="three", classes=["one", "two"])
assert element._render_attributes() == " class='one two three'"
4.1.0 Types and Autocompletion
Version 4.1.0
Feature
Added types for html elements and their attributes. The type system is taken from Ludic.. It is just so incredibly good. This gives us autocomplete support for everything.
- Types html elements and attributes.
Documentation
- Document how to add attributes with symbols like dash and period.
4.0.0
Breaking
Instead of having to use text
and composed_text
keywords you can now write text like this:
Div("My text", Bold("My bold text"), "Tail")
- Removes
text
argument. - Removes
composed_text
argument.
Features
- The direct
*args
are now is a list ofElement | str
. This is basically exactly howcomposed_text
worked, If we have a string child, we escape it, otherwise we call the child Elements.dump()
. This should be a lot smoother to work with and read.
3.0.0
Breaking
- Rename
htmx.py
tofastapi.py
. The decorators were only for fastAPI. If we support django or flask, then they should get their own versions. This change facilitates for that so we don't have to have a breaking change further down the line. - Don't expose
@htmx
and@full
decorators directly fromhypermedia
, but require them to be imported fromhypermedia.fastapi
.
Housekeeping
- Readme file: Add features section, improve examples
Full Changelog: 2.2.0...3.0.0