backet syntax!

This commit is contained in:
Seth Trowbridge 2025-08-14 15:42:02 -04:00
parent 838ce7acb3
commit 25fe93efe5

View File

@ -6,6 +6,18 @@ class StrArgsToStr(Protocol):
ClassArg = str|List[str]|Tuple[str, ...]|None
class ProxyDict(dict):
name:str
attrs:str
def __init__(self, name:str, attrs:str):
self.name = name
self.attrs = attrs
def __getitem__(self, key:str|Tuple[str, ...]):
return f'<{self.name}{self.attrs}>{"".join(key) if isinstance(key, tuple) else key}</{self.name}>'
def MakeAttrs(classes:ClassArg, id:str|None, attributes: dict[str, str | None]) -> str:
if classes:
@ -20,10 +32,8 @@ def MakeAttrs(classes:ClassArg, id:str|None, attributes: dict[str, str | None])
attrList.append(f'{key}="{value}"')
return " ".join(attrList)
def ElWrapped(name: str, classes:ClassArg = None, id:str|None = None, attrs: dict[str, str | None] = {}, children:ClassArg = ()) -> StrArgsToStr:
def Wrapped(*children:str):
return f'<{name}{MakeAttrs(classes, id, attrs)}>{" ".join(children)}</{name}>'
return Wrapped
def ElWrapped(name: str, classes:ClassArg = None, id:str|None = None, attrs: dict[str, str | None] = {}, children:ClassArg = ()) -> ProxyDict:
return ProxyDict(name, MakeAttrs(classes, id, attrs))
def ElInline(name: str, classes:ClassArg = None, id:str|None = None, attrs: dict[str, str | None] = {}) -> str:
return f'<{name} {MakeAttrs(classes, id, attrs)}/>'
@ -38,7 +48,7 @@ def SimpleInline(name:str):
return ElInline(name, classes, id)
return proxy
def A(classes:ClassArg = None, id:str|None = None, href:str|None = None, target:str|None = None) -> StrArgsToStr:
def A(classes:ClassArg = None, id:str|None = None, href:str|None = None, target:str|None = None):
return ElWrapped("a", classes, id, {"href":href, "target":id})
def IMG(classes:ClassArg = None, id:str|None = None, src:str|None = None):
@ -53,7 +63,7 @@ SPAN = SimpleWrapped("span")
print(
DIV(classes="outer")
(
A(classes="CTA Orange", href="www.link")("click")
)
[
A(classes="CTA Orange", href="www.link")["click"]
]
)