Skip to content

Commit 0fa47ec

Browse files
committed
Update h function import in core
1 parent 54d4935 commit 0fa47ec

File tree

4 files changed

+177
-177
lines changed

4 files changed

+177
-177
lines changed

src/hyperpython/__init__.py

Lines changed: 131 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -1,141 +1,136 @@
11
"""
22
Core Hyperpython API
33
"""
4-
__version__ = "1.0.2"
4+
__version__ = "1.1.0"
55
__author__ = "Fábio Macêdo Mendes"
66

7-
# Ugly hack to make it possible to store __version__ directly on __init__.py
8-
try:
9-
from .core import Element, Text, Blob, Block, Json, Component
10-
from .html import html, render
11-
from .tags import (
12-
HTML5,
13-
h,
14-
body,
15-
head,
16-
meta,
17-
link,
18-
title,
19-
div,
20-
span,
21-
article,
22-
aside,
23-
details,
24-
footer,
25-
figcaption,
26-
figure,
27-
header,
28-
main,
29-
p,
30-
pre,
31-
section,
32-
embed,
33-
iframe,
34-
noscript,
35-
object_,
36-
script,
37-
style,
38-
button,
39-
fieldset,
40-
form,
41-
input_,
42-
keygen,
43-
label,
44-
legend,
45-
optgroup,
46-
option,
47-
select,
48-
textarea,
49-
h1,
50-
h2,
51-
h3,
52-
h4,
53-
h5,
54-
h6,
55-
dd,
56-
dl,
57-
dt,
58-
ul,
59-
li,
60-
ol,
61-
area,
62-
audio,
63-
canvas,
64-
img,
65-
picture,
66-
track,
67-
video,
68-
source,
69-
a,
70-
menu,
71-
menuitem,
72-
nav,
73-
abbr,
74-
blockquote,
75-
code,
76-
caption,
77-
col,
78-
colgroup,
79-
table,
80-
tbody,
81-
td,
82-
tfoot,
83-
th,
84-
thead,
85-
tr,
86-
b,
87-
em,
88-
del_,
89-
i,
90-
ins,
91-
mark,
92-
q,
93-
s,
94-
small,
95-
strong,
96-
sub,
97-
sup,
98-
u,
99-
br,
100-
hr,
101-
wbr,
102-
bdi,
103-
bdo,
104-
rp,
105-
rt,
106-
ruby,
107-
address,
108-
dialog,
109-
base,
110-
cite,
111-
datalist,
112-
dfn,
113-
kbd,
114-
map_,
115-
meter,
116-
param,
117-
progress,
118-
samp,
119-
summary,
120-
time,
121-
var,
122-
output,
123-
acronym,
124-
applet,
125-
big,
126-
basefont,
127-
center,
128-
dir_,
129-
font,
130-
frame,
131-
frameset,
132-
noframes,
133-
strike,
134-
tt,
135-
)
136-
from .utils import escape, unescape, safe, sanitize
137-
from .fragment import fragment, FragmentNotFound
138-
from .helpers import classes
139-
except ImportError as exc:
140-
print("Caught exception:", exc)
141-
print("This is expected during installation.")
7+
from .core import Element, Text, Blob, Block, Json, Component
8+
from .fragment import fragment, FragmentNotFound
9+
from .helpers import classes
10+
from .html import html, render
11+
from .tags import (
12+
HTML5,
13+
h,
14+
body,
15+
head,
16+
meta,
17+
link,
18+
title,
19+
div,
20+
span,
21+
article,
22+
aside,
23+
details,
24+
footer,
25+
figcaption,
26+
figure,
27+
header,
28+
main,
29+
p,
30+
pre,
31+
section,
32+
embed,
33+
iframe,
34+
noscript,
35+
object_,
36+
script,
37+
style,
38+
button,
39+
fieldset,
40+
form,
41+
input_,
42+
keygen,
43+
label,
44+
legend,
45+
optgroup,
46+
option,
47+
select,
48+
textarea,
49+
h1,
50+
h2,
51+
h3,
52+
h4,
53+
h5,
54+
h6,
55+
dd,
56+
dl,
57+
dt,
58+
ul,
59+
li,
60+
ol,
61+
area,
62+
audio,
63+
canvas,
64+
img,
65+
picture,
66+
track,
67+
video,
68+
source,
69+
a,
70+
menu,
71+
menuitem,
72+
nav,
73+
abbr,
74+
blockquote,
75+
code,
76+
caption,
77+
col,
78+
colgroup,
79+
table,
80+
tbody,
81+
td,
82+
tfoot,
83+
th,
84+
thead,
85+
tr,
86+
b,
87+
em,
88+
del_,
89+
i,
90+
ins,
91+
mark,
92+
q,
93+
s,
94+
small,
95+
strong,
96+
sub,
97+
sup,
98+
u,
99+
br,
100+
hr,
101+
wbr,
102+
bdi,
103+
bdo,
104+
rp,
105+
rt,
106+
ruby,
107+
address,
108+
dialog,
109+
base,
110+
cite,
111+
datalist,
112+
dfn,
113+
kbd,
114+
map_,
115+
meter,
116+
param,
117+
progress,
118+
samp,
119+
summary,
120+
time,
121+
var,
122+
output,
123+
acronym,
124+
applet,
125+
big,
126+
basefont,
127+
center,
128+
dir_,
129+
font,
130+
frame,
131+
frameset,
132+
noframes,
133+
strike,
134+
tt,
135+
)
136+
from .utils import escape, unescape, safe, sanitize

src/hyperpython/contrib/milligram.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ def cdn():
3030
# Forms and buttons
3131
#
3232
def button(
33-
text,
34-
*,
35-
href=None,
36-
submit=False,
37-
reset=False,
38-
form=False,
39-
outline=False,
40-
clear=False,
41-
**kwargs,
33+
text,
34+
*,
35+
href=None,
36+
submit=False,
37+
reset=False,
38+
form=False,
39+
outline=False,
40+
clear=False,
41+
**kwargs,
4242
):
4343
"""
4444
A styled button element.
@@ -128,14 +128,14 @@ def row(*children, padding=True, wrap=False, align=None, **kwargs):
128128

129129

130130
def column(
131-
*children,
132-
size=None,
133-
offset=None,
134-
top=False,
135-
bottom=False,
136-
center=None,
137-
align=None,
138-
**kwargs,
131+
*children,
132+
size=None,
133+
offset=None,
134+
top=False,
135+
bottom=False,
136+
center=None,
137+
align=None,
138+
**kwargs,
139139
):
140140
"""
141141
A single column inside a flexible row.

src/hyperpython/core.py

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,24 @@
1111
from .renderers import dump_attrs, render_pretty
1212
from .utils import escape as _escape
1313

14+
# https://www.w3.org/TR/html5/syntax.html#void-elements
15+
VOID_ELEMENTS = {
16+
"area",
17+
"base",
18+
"br",
19+
"col",
20+
"embed",
21+
"hr",
22+
"img",
23+
"input",
24+
"keygen",
25+
"link",
26+
"meta",
27+
"param",
28+
"source",
29+
"track",
30+
"wbr",
31+
}
1432
SEQUENCE_TYPES = (tuple, list, type(x for x in []), type(map(lambda: 0, [])))
1533
JUPYTER_NOTEBOOK_RENDER_HTML = True
1634
cte = lambda value: lambda *args: value
@@ -424,6 +442,7 @@ def as_attr(name, value):
424442
return name, value
425443
return name, value
426444

445+
427446
def as_child(value):
428447
"""
429448
Convert arbitrary object to a compatible Element object.
@@ -438,7 +457,7 @@ def as_child(value):
438457
elif isinstance(value, (int, float)):
439458
return Text(str(value))
440459
elif isinstance(value, Tag):
441-
return h(value.tag)
460+
return Element(value.tag, {}, [], value.tag in VOID_ELEMENTS)
442461
elif hasattr(value, "__html__"):
443462
return Blob(value.__html__())
444463
elif hasattr(value, "__hyperpython__"):
@@ -466,16 +485,21 @@ class Tag:
466485
Return an HTMLTag subclass for the given tag.
467486
"""
468487

469-
_h_function: callable = None
488+
_h_function: callable
470489

471490
def __init__(self, tag, help_text=None):
472491
self.tag = tag
473492
self.__doc__ = help_text
474493

475494
def __call__(self, *args, **kwargs):
476-
return self._h_function(self.tag, *args, **kwargs)
495+
try:
496+
h = self._h_function
497+
except AttributeError:
498+
from .tags import h
499+
Tag._h_function = h
500+
return h(self.tag, *args, **kwargs)
477501

478502
def __getitem__(self, item):
479503
return self._h_function(self.tag)[item]
480504

481-
from .tags import h
505+

0 commit comments

Comments
 (0)