cleanup
This commit is contained in:
parent
61fac50e20
commit
74980d2c1b
@ -1,4 +1,4 @@
|
||||
<!doctype html><html>
|
||||
<!DOCTYPE html><html>
|
||||
<head>
|
||||
<style>
|
||||
.user_styles_UserMadeSheet_Anchor {
|
||||
@ -14,7 +14,7 @@
|
||||
<body>
|
||||
<div>
|
||||
<h1>
|
||||
Welcome!
|
||||
Welcome, seth!
|
||||
</h1>
|
||||
<a href="www.site.com" class="user_styles_UserMadeSheet_Anchor">
|
||||
<img src="image.png"/>
|
||||
|
41
pyx.py
41
pyx.py
@ -1,4 +1,4 @@
|
||||
from typing import Any, List, Tuple, Union, Optional
|
||||
from typing import List, Tuple, Union, Optional
|
||||
from css import Chainer, Writer
|
||||
from dataclasses import dataclass
|
||||
|
||||
@ -35,39 +35,46 @@ class Leaf():
|
||||
def __call__(self, css:Optional[TAGGED] = None, id:Optional[str] = None):
|
||||
return self.props(css, id, {})
|
||||
|
||||
@classmethod
|
||||
def template(cls, name:str, attrs:Optional[str] = None):
|
||||
return f'<{name}{attrs or ""}/>'
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f'<{self.name}{self.attrs or ""}/>'
|
||||
return __class__.template(self.name, self.attrs)
|
||||
|
||||
class Branch(Leaf):
|
||||
name:str = ""
|
||||
|
||||
def __init__(self, name:Optional[str] = None):
|
||||
if name:
|
||||
self.name = name
|
||||
def __init__(self, name:str):
|
||||
self.name = name
|
||||
self.attrs = None
|
||||
|
||||
@classmethod
|
||||
def template(cls, name:str, attrs:Optional[str] = None, children:Optional[str] = None):
|
||||
return f'<{name}{attrs or ""}>\n{children}\n</{name}>'
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f'<{self.name}{self.attrs or ""}></{self.name}>'
|
||||
return self.__class__.template(self.name, self.attrs)
|
||||
|
||||
def __getitem__(self, key:Union[Renderable, Tuple[Renderable, ...]]) -> Renderable:
|
||||
if isinstance(key, tuple):
|
||||
children = f'\n'.join(str(k) for k in key)
|
||||
else:
|
||||
children = str(key)
|
||||
return f'<{self.name}{self.attrs or ""}>\n{children}\n</{self.name}>'
|
||||
children = f'\n'.join(str(k) for k in key) if isinstance(key, tuple) else str(key)
|
||||
return self.__class__.template(self.name, self.attrs, children)
|
||||
|
||||
class IMGTag(Leaf):
|
||||
name = "img"
|
||||
def __call__(self, css:Optional[TAGGED] = None, id:Optional[str] = None, src:Optional[str] = None):
|
||||
return self.props(css, id, {"src":src})
|
||||
|
||||
class ATag(Branch):
|
||||
name = "a"
|
||||
def __call__(self, css:Optional[TAGGED] = None, id:Optional[str] = None, href:Optional[str] = None, target:Optional[str] = None):
|
||||
return self.props(css, id, {"href":href, "target":target})
|
||||
|
||||
class HTMLTag(Branch):
|
||||
@classmethod
|
||||
def template(cls, name:str, attrs:Optional[str] = None, children:Optional[str] = None):
|
||||
return f'<!DOCTYPE html><{name}{attrs or ""}>\n{children}\n</{name}>'
|
||||
|
||||
IMG = IMGTag()
|
||||
A = ATag()
|
||||
|
||||
IMG = IMGTag("img")
|
||||
A = ATag("a")
|
||||
BR = Leaf("br")
|
||||
HR = Leaf("hr")
|
||||
DIV = Branch("div")
|
||||
@ -80,7 +87,7 @@ H3 = Branch("h3")
|
||||
H4 = Branch("h4")
|
||||
SECTION = Branch("section")
|
||||
MAIN = Branch("main")
|
||||
HTML = Branch("html")
|
||||
HTML = HTMLTag("html")
|
||||
HEAD = Branch("head")
|
||||
BODY = Branch("body")
|
||||
STYLE = Branch("style")
|
||||
|
12
route.py
Normal file
12
route.py
Normal file
@ -0,0 +1,12 @@
|
||||
from pyx import HTML, HEAD, BODY, STYLE, Capture
|
||||
from user_template import ViewFunction
|
||||
|
||||
output = Capture(ViewFunction(name="seth"))
|
||||
|
||||
with open("example.html", "w") as file:
|
||||
file.write(f'{HTML[
|
||||
HEAD[
|
||||
STYLE[ output.css ]
|
||||
],
|
||||
BODY[ output.html ]
|
||||
]}')
|
20
scratch.py
Normal file
20
scratch.py
Normal file
@ -0,0 +1,20 @@
|
||||
|
||||
from typing import Callable, TypeVar, ParamSpec, Optional
|
||||
|
||||
P = ParamSpec('P') # captures the parameter types
|
||||
R = TypeVar('R') # original return type
|
||||
NewR = TypeVar('NewR') # new return type
|
||||
|
||||
def transform_return_type(func: Callable[P, R]) -> Callable[P, str]:
|
||||
def wrapper(*args: P.args, **kwargs: P.kwargs) -> str:
|
||||
# You'd do something meaningful here
|
||||
result = func(*args, **kwargs)
|
||||
return str(result) # Just an example transformation
|
||||
return wrapper
|
||||
|
||||
@transform_return_type
|
||||
def idk(test:Optional[str] = None)->int:
|
||||
return 7
|
||||
|
||||
|
||||
test = idk(test="hey")
|
@ -1,11 +1,9 @@
|
||||
from pyx import DIV, H1, P, IMG, A, HTML, HEAD, BODY, STYLE, Capture
|
||||
from pyx import DIV, H1, P, IMG, A
|
||||
from user_styles import UserMadeSheet
|
||||
|
||||
|
||||
output = Capture(
|
||||
DIV
|
||||
[
|
||||
H1["Welcome!"],
|
||||
def ViewFunction(name:str):
|
||||
return DIV[
|
||||
H1[f'Welcome, {name}!'],
|
||||
A(css=(UserMadeSheet.Anchor), href="www.site.com")
|
||||
[
|
||||
IMG(src="image.png")
|
||||
@ -21,12 +19,3 @@ output = Capture(
|
||||
deserunt mollit anim id est laborum."""
|
||||
]
|
||||
]
|
||||
)
|
||||
|
||||
with open("example.html", "w") as file:
|
||||
file.write(f'<!doctype html>{HTML[
|
||||
HEAD[
|
||||
STYLE[ output.css ]
|
||||
],
|
||||
BODY[ output.html ]
|
||||
]}')
|
||||
|
Loading…
Reference in New Issue
Block a user