Skip to content

Commit 7c77e75

Browse files
authored
Merge pull request #824 from AnswerDotAI/htmxcli
add optional client arg to HTMX for persistent tests
2 parents 3c0d0c4 + bb3d672 commit 7c77e75

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

fasthtml/jupyter.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def stop(self):
118118
from html import escape
119119

120120
# %% ../nbs/api/06_jupyter.ipynb #89b8984b
121-
def HTMX(path="/", host='localhost', app=None, port=8000, height="auto", link=False, iframe=True):
121+
def HTMX(path="/", host='localhost', app=None, port=8000, height="auto", link=False, iframe=True, client=None):
122122
"An iframe which displays the HTMX application in a notebook."
123123
if isinstance(height, int): height = f"{height}px"
124124
scr = """{
@@ -137,7 +137,8 @@ def HTMX(path="/", host='localhost', app=None, port=8000, height="auto", link=Fa
137137
route = f'/{unqid()}'
138138
res = path
139139
app.get(route)(lambda: res)
140-
page = TestClient(app).get(route).text
140+
cli = client if client is not None else TestClient(app)
141+
page = cli.get(route).text
141142
src = f'srcdoc="{escape(page)}"'
142143
if iframe:
143144
return HTML(f'<iframe {src} style="width: 100%; height: {height}; border: none;" onload="{scr}" ' + """allow="accelerometer; autoplay; camera; clipboard-read; clipboard-write; display-capture; encrypted-media; fullscreen; gamepad; geolocation; gyroscope; hid; identity-credentials-get; idle-detection; magnetometer; microphone; midi; payment; picture-in-picture; publickey-credentials-get; screen-wake-lock; serial; usb; web-share; xr-spatial-tracking"></iframe> """)

nbs/api/06_jupyter.ipynb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@
725725
"outputs": [],
726726
"source": [
727727
"#| export\n",
728-
"def HTMX(path=\"/\", host='localhost', app=None, port=8000, height=\"auto\", link=False, iframe=True):\n",
728+
"def HTMX(path=\"/\", host='localhost', app=None, port=8000, height=\"auto\", link=False, iframe=True, client=None):\n",
729729
" \"An iframe which displays the HTMX application in a notebook.\"\n",
730730
" if isinstance(height, int): height = f\"{height}px\"\n",
731731
" scr = \"\"\"{\n",
@@ -744,7 +744,8 @@
744744
" route = f'/{unqid()}'\n",
745745
" res = path\n",
746746
" app.get(route)(lambda: res)\n",
747-
" page = TestClient(app).get(route).text\n",
747+
" cli = client if client is not None else TestClient(app)\n",
748+
" page = cli.get(route).text\n",
748749
" src = f'srcdoc=\"{escape(page)}\"'\n",
749750
" if iframe:\n",
750751
" return HTML(f'<iframe {src} style=\"width: 100%; height: {height}; border: none;\" onload=\"{scr}\" ' + \"\"\"allow=\"accelerometer; autoplay; camera; clipboard-read; clipboard-write; display-capture; encrypted-media; fullscreen; gamepad; geolocation; gyroscope; hid; identity-credentials-get; idle-detection; magnetometer; microphone; midi; payment; picture-in-picture; publickey-credentials-get; screen-wake-lock; serial; usb; web-share; xr-spatial-tracking\"></iframe> \"\"\")"

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,4 @@ include = ["fasthtml"]
3838
[tool.nbdev]
3939
jupyter_hooks = true
4040
custom_sidebar = false
41+
lib_path = "fasthtml"

0 commit comments

Comments
 (0)