Skip to content

Commit 67ceff5

Browse files
committed
fixes #706
1 parent 03e9bc8 commit 67ceff5

File tree

3 files changed

+53
-3
lines changed

3 files changed

+53
-3
lines changed

fasthtml/_modidx.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,8 @@
247247
'fasthtml.xtend.CheckboxX': ('api/xtend.html#checkboxx', 'fasthtml/xtend.py'),
248248
'fasthtml.xtend.Favicon': ('api/xtend.html#favicon', 'fasthtml/xtend.py'),
249249
'fasthtml.xtend.Form': ('api/xtend.html#form', 'fasthtml/xtend.py'),
250+
'fasthtml.xtend.Fragment': ('api/xtend.html#fragment', 'fasthtml/xtend.py'),
251+
'fasthtml.xtend.Fragment.__init__': ('api/xtend.html#fragment.__init__', 'fasthtml/xtend.py'),
250252
'fasthtml.xtend.Hidden': ('api/xtend.html#hidden', 'fasthtml/xtend.py'),
251253
'fasthtml.xtend.HtmxOn': ('api/xtend.html#htmxon', 'fasthtml/xtend.py'),
252254
'fasthtml.xtend.Nbsp': ('api/xtend.html#nbsp', 'fasthtml/xtend.py'),

fasthtml/xtend.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# %% auto 0
66
__all__ = ['sid_scr', 'A', 'AX', 'Form', 'Hidden', 'CheckboxX', 'Script', 'Style', 'double_braces', 'undouble_braces',
77
'loose_format', 'ScriptX', 'replace_css_vars', 'StyleX', 'Nbsp', 'Surreal', 'On', 'Prev', 'Now', 'AnyNow',
8-
'run_js', 'HtmxOn', 'jsd', 'Titled', 'Socials', 'YouTubeEmbed', 'Favicon', 'clear', 'with_sid']
8+
'run_js', 'HtmxOn', 'jsd', 'Fragment', 'Titled', 'Socials', 'YouTubeEmbed', 'Favicon', 'clear', 'with_sid']
99

1010
# %% ../nbs/api/02_xtend.ipynb
1111
from dataclasses import dataclass, asdict
@@ -178,6 +178,11 @@ def jsd(org, repo, root, path, prov='gh', typ='script', ver=None, esm=False, **k
178178
if esm: s += '/+esm'
179179
return Script(src=s, **kwargs) if typ=='script' else Link(rel='stylesheet', href=s, **kwargs) if typ=='css' else s
180180

181+
# %% ../nbs/api/02_xtend.ipynb
182+
class Fragment(FT):
183+
"An empty tag, used as a container"
184+
def __init__(self, *c): super().__init__('', c, {}, void_=True)
185+
181186
# %% ../nbs/api/02_xtend.ipynb
182187
@delegates(ft_hx, keep=True)
183188
def Titled(title:str="FastHTML app", *args, cls="container", **kwargs)->FT:

nbs/api/02_xtend.ipynb

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,8 @@
202202
"<IPython.core.display.HTML object>"
203203
]
204204
},
205-
"execution_count": null,
206205
"metadata": {},
207-
"output_type": "execute_result"
206+
"output_type": "display_data"
208207
}
209208
],
210209
"source": [
@@ -500,6 +499,40 @@
500499
"id": "5e6d3c46",
501500
"metadata": {},
502501
"outputs": [],
502+
"source": [
503+
"#| export\n",
504+
"class Fragment(FT):\n",
505+
" \"An empty tag, used as a container\"\n",
506+
" def __init__(self, *c): super().__init__('', c, {}, void_=True)"
507+
]
508+
},
509+
{
510+
"cell_type": "code",
511+
"execution_count": null,
512+
"id": "667a0f3f",
513+
"metadata": {},
514+
"outputs": [
515+
{
516+
"name": "stdout",
517+
"output_type": "stream",
518+
"text": [
519+
" <p>1st</p>\n",
520+
" <p>2nd</p>\n",
521+
"\n"
522+
]
523+
}
524+
],
525+
"source": [
526+
"fts = Fragment(P('1st'), P('2nd'))\n",
527+
"print(to_xml(fts))"
528+
]
529+
},
530+
{
531+
"cell_type": "code",
532+
"execution_count": null,
533+
"id": "cb0a89d7",
534+
"metadata": {},
535+
"outputs": [],
503536
"source": [
504537
"#| export\n",
505538
"@delegates(ft_hx, keep=True)\n",
@@ -508,6 +541,16 @@
508541
" return Title(title), Main(H1(title), *args, cls=cls, **kwargs)"
509542
]
510543
},
544+
{
545+
"cell_type": "code",
546+
"execution_count": null,
547+
"id": "037757de",
548+
"metadata": {},
549+
"outputs": [],
550+
"source": [
551+
"show(Titled('my page', P('para')))"
552+
]
553+
},
511554
{
512555
"cell_type": "code",
513556
"execution_count": null,

0 commit comments

Comments
 (0)