Skip to content

Commit

Permalink
Consider.
Browse files Browse the repository at this point in the history
  • Loading branch information
davepeck committed May 17, 2024
1 parent 72bad21 commit caf0e40
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions server/vb/components/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,21 @@ def __call__(self, *args: P.args, **kwargs: P.kwargs) -> t.Self:

def __str__(self) -> str:
"""Return the name of the function being wrapped."""
# CONSIDER: alternatively, require that all wrapped functions
# have a default value for the `children` argument, and invoke
# the function here?
# CONSIDER: alternatively, invoke the function here? If the function
# provides a default value for its arguments, it'll work; otherwise,
# it will blow up... which might be a good thing?
return f"with_children[{self._f.__name__}]"


@with_children
def card(children: h.Node, data_foo: str | None = None) -> h.Element:
"""Render a card with the given children."""
return h.div(".card", data_foo=data_foo)[children]


@with_children
def list_items(children: t.Iterable[str]) -> h.Node:
"""Render all children in list items."""
return [h.li[child] for child in children]


class Fragment:
"""A fragment of HTML that can be rendered as a string."""
"""
A fragment of HTML with no explicit parent element.
CONSIDER: this feels like it should perhaps be the base class from
which htpy.Element inherits? It's a container for children, without
an Element's tag/attributes. And htpy.Node should probably include
this as well.
"""

__slots__ = ("_children",)

Expand All @@ -68,6 +63,7 @@ def __str__(self) -> Markup:

def __iter__(self):
"""Iterate over the children of the fragment."""
# XXX I'm using a private method here, which is not ideal.
yield from _h_iter_children(self._children)


Expand Down

0 comments on commit caf0e40

Please sign in to comment.