-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
77 lines (66 loc) · 2.37 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
from whitehouse.base import Component
from whitehouse.default import *
from whitehouse.utils import format_html
from whitehouse.custom import Template
from typing import List, Dict, Union
class MyComponent(Component):
def __init__(
self,
child1: Union[str, 'Component', List['Component']],
child2: Union[str, 'Component', List['Component']],
attributes: Dict[str, str] = {}
) -> None:
super().__init__([
div([
p("Hello, World 1!"),
child1
], {"class": "container"}),
div([
p("Hello, World 2!"),
child2
], {"class": "container"})
], attributes=attributes)
class IndexTemplate(Template):
def __init__(self, body_content: Component) -> None:
super().__init__(
html([
head([
title("Hello, World!"),
meta({"charset": "UTF-8", "name": "viewport", "content": "width=device-width, initial-scale=1.0"}),
]),
body([
body_content
])
])
)
if __name__ == "__main__":
component = html([
head([
title("Hello, World!"),
meta({"charset": "UTF-8", "name": "viewport", "content": "width=device-width, initial-scale=1.0"}),
link({"rel": "stylesheet", "href": "style.css"}),
script("", {"src": "script.js"})
]),
body([
MyComponent(
p("Hello, World 3!"),
p("Hello, World 4!"),
{"id": "custom-component1"}
),
MyComponent(
p("Hello, World 5!"),
p("Hello, World 6!"),
{"id": "custom-component2"}
),
script("console.log('Hello, World!');")
])
])
print(format_html(component)) # Output: "Hello, World!
print(format_html([
MyComponent(p("Hello, World 3!"), p("Hello, World 4!"), {"id": "custom-component1"}),
MyComponent(p("Hello, World 5!"), p("Hello, World 6!"), {"id": "custom-component2"})
])) # Output: "Hello, World!
index_template = IndexTemplate(
MyComponent(p("Hello, World 3!"), p("Hello, World 4!"), {"id": "custom-component1"})
)
print(format_html(index_template)) # Output: "Hello, World!