Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions fasthtml/jupyter.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def stop(self):
from html import escape

# %% ../nbs/api/06_jupyter.ipynb #89b8984b
def HTMX(path="/", host='localhost', app=None, port=8000, height="auto", link=False, iframe=True):
def HTMX(path="/", host='localhost', app=None, port=8000, height="auto", link=False, iframe=True, client=None):
"An iframe which displays the HTMX application in a notebook."
if isinstance(height, int): height = f"{height}px"
scr = """{
Expand All @@ -137,7 +137,8 @@ def HTMX(path="/", host='localhost', app=None, port=8000, height="auto", link=Fa
route = f'/{unqid()}'
res = path
app.get(route)(lambda: res)
page = TestClient(app).get(route).text
cli = client if client is not None else TestClient(app)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the change: can now use an existing client if provided

page = cli.get(route).text
src = f'srcdoc="{escape(page)}"'
if iframe:
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> """)
Expand Down
5 changes: 3 additions & 2 deletions nbs/api/06_jupyter.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@
"outputs": [],
"source": [
"#| export\n",
"def HTMX(path=\"/\", host='localhost', app=None, port=8000, height=\"auto\", link=False, iframe=True):\n",
"def HTMX(path=\"/\", host='localhost', app=None, port=8000, height=\"auto\", link=False, iframe=True, client=None):\n",
" \"An iframe which displays the HTMX application in a notebook.\"\n",
" if isinstance(height, int): height = f\"{height}px\"\n",
" scr = \"\"\"{\n",
Expand All @@ -744,7 +744,8 @@
" route = f'/{unqid()}'\n",
" res = path\n",
" app.get(route)(lambda: res)\n",
" page = TestClient(app).get(route).text\n",
" cli = client if client is not None else TestClient(app)\n",
" page = cli.get(route).text\n",
" src = f'srcdoc=\"{escape(page)}\"'\n",
" if iframe:\n",
" 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> \"\"\")"
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ include = ["fasthtml"]
[tool.nbdev]
jupyter_hooks = true
custom_sidebar = false
lib_path = "fasthtml"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise nbdev-export creates a python_fasthtml directory based on name = "python-fasthtml".