Skip to content

Commit fdee9e8

Browse files
committed
fixes #456
1 parent 2df1760 commit fdee9e8

File tree

5 files changed

+90
-141
lines changed

5 files changed

+90
-141
lines changed

fasthtml/_modidx.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,7 @@
107107
'fasthtml.core.uri': ('api/core.html#uri', 'fasthtml/core.py')},
108108
'fasthtml.fastapp': { 'fasthtml.fastapp._app_factory': ('api/fastapp.html#_app_factory', 'fasthtml/fastapp.py'),
109109
'fasthtml.fastapp._get_tbl': ('api/fastapp.html#_get_tbl', 'fasthtml/fastapp.py'),
110-
'fasthtml.fastapp.fast_app': ('api/fastapp.html#fast_app', 'fasthtml/fastapp.py'),
111-
'fasthtml.fastapp.jupy_app': ('api/fastapp.html#jupy_app', 'fasthtml/fastapp.py')},
110+
'fasthtml.fastapp.fast_app': ('api/fastapp.html#fast_app', 'fasthtml/fastapp.py')},
112111
'fasthtml.ft': {},
113112
'fasthtml.js': { 'fasthtml.js.HighlightJS': ('api/js.html#highlightjs', 'fasthtml/js.py'),
114113
'fasthtml.js.KatexMarkdownJS': ('api/js.html#katexmarkdownjs', 'fasthtml/js.py'),
@@ -123,6 +122,7 @@
123122
'fasthtml.jupyter.JupyUvi.start': ('api/jupyter.html#jupyuvi.start', 'fasthtml/jupyter.py'),
124123
'fasthtml.jupyter.JupyUvi.stop': ('api/jupyter.html#jupyuvi.stop', 'fasthtml/jupyter.py'),
125124
'fasthtml.jupyter.is_port_free': ('api/jupyter.html#is_port_free', 'fasthtml/jupyter.py'),
125+
'fasthtml.jupyter.jupy_app': ('api/jupyter.html#jupy_app', 'fasthtml/jupyter.py'),
126126
'fasthtml.jupyter.nb_serve': ('api/jupyter.html#nb_serve', 'fasthtml/jupyter.py'),
127127
'fasthtml.jupyter.nb_serve_async': ('api/jupyter.html#nb_serve_async', 'fasthtml/jupyter.py'),
128128
'fasthtml.jupyter.wait_port_free': ('api/jupyter.html#wait_port_free', 'fasthtml/jupyter.py')},

fasthtml/fastapp.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@
1212
from .pico import *
1313
from .starlette import *
1414
from .live_reload import FastHTMLWithLiveReload
15-
from .jupyter import _iframe_scr, cors_allow
1615

1716
# %% auto 0
18-
__all__ = ['fast_app', 'jupy_app']
17+
__all__ = ['fast_app']
1918

2019
# %% ../nbs/api/10_fastapp.ipynb
2120
def _get_tbl(dt, nm, schema):
@@ -92,10 +91,3 @@ def fast_app(
9291
dbtbls = [_get_tbl(db.t, k, v) for k,v in tbls.items()]
9392
if len(dbtbls)==1: dbtbls=dbtbls[0]
9493
return app,app.route,*dbtbls
95-
96-
# %% ../nbs/api/10_fastapp.ipynb
97-
def jupy_app(pico=False, hdrs=None, middleware=None, **kwargs):
98-
"Same as `fast_app` but for Jupyter notebooks"
99-
hdrs = listify(hdrs)+[_iframe_scr]
100-
middleware = listify(middleware)+[cors_allow]
101-
return fast_app(pico=pico, hdrs=hdrs, middleware=middleware, **kwargs)

fasthtml/jupyter.py

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/api/06_jupyter.ipynb.
22

33
# %% auto 0
4-
__all__ = ['cors_allow', 'nb_serve', 'nb_serve_async', 'is_port_free', 'wait_port_free', 'JupyUvi', 'FastJupy', 'HTMX']
4+
__all__ = ['cors_allow', 'nb_serve', 'nb_serve_async', 'is_port_free', 'wait_port_free', 'JupyUvi', 'FastJupy', 'HTMX',
5+
'jupy_app']
56

67
# %% ../nbs/api/06_jupyter.ipynb
78
import asyncio, socket, time, uvicorn
89
from threading import Thread
910
from fastcore.utils import *
10-
from .core import *
11-
from .components import *
12-
from .xtend import *
11+
from .common import *
1312
from IPython.display import HTML,Markdown,IFrame
1413
from starlette.middleware.cors import CORSMiddleware
1514
from starlette.middleware import Middleware
@@ -96,29 +95,11 @@ def HTMX(host='localhost', port=8000):
9695
window.addEventListener('message', function(e) {
9796
if (e.data.height) frame.style.height = (e.data.height+1) + 'px';
9897
}, false);
99-
}" allow="accelerometer;
100-
autoplay;
101-
camera;
102-
clipboard-read;
103-
clipboard-write;
104-
display-capture;
105-
encrypted-media;
106-
fullscreen;
107-
gamepad;
108-
geolocation;
109-
gyroscope;
110-
hid;
111-
identity-credentials-get;
112-
idle-detection;
113-
magnetometer;
114-
microphone;
115-
midi;
116-
payment;
117-
picture-in-picture;
118-
publickey-credentials-get;
119-
screen-wake-lock;
120-
serial;
121-
usb;
122-
web-share;
123-
xr-spatial-tracking
124-
"></iframe> """)
98+
}" 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> """)
99+
100+
# %% ../nbs/api/06_jupyter.ipynb
101+
def jupy_app(pico=False, hdrs=None, middleware=None, **kwargs):
102+
"Same as `fast_app` but for Jupyter notebooks"
103+
hdrs = listify(hdrs)+[_iframe_scr]
104+
middleware = listify(middleware)+[cors_allow]
105+
return fast_app(pico=pico, hdrs=hdrs, middleware=middleware, **kwargs)

nbs/api/06_jupyter.ipynb

Lines changed: 75 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@
3131
"import asyncio, socket, time, uvicorn\n",
3232
"from threading import Thread\n",
3333
"from fastcore.utils import *\n",
34-
"from fasthtml.core import *\n",
35-
"from fasthtml.components import *\n",
36-
"from fasthtml.xtend import *\n",
34+
"from fasthtml.common import *\n",
3735
"from IPython.display import HTML,Markdown,IFrame\n",
3836
"from starlette.middleware.cors import CORSMiddleware\n",
3937
"from starlette.middleware import Middleware\n",
@@ -301,32 +299,7 @@
301299
" window.addEventListener('message', function(e) {\n",
302300
" if (e.data.height) frame.style.height = (e.data.height+1) + 'px';\n",
303301
" }, false);\n",
304-
" }\" allow=\"accelerometer;\n",
305-
"autoplay;\n",
306-
"camera;\n",
307-
"clipboard-read;\n",
308-
"clipboard-write;\n",
309-
"display-capture;\n",
310-
"encrypted-media;\n",
311-
"fullscreen;\n",
312-
"gamepad;\n",
313-
"geolocation;\n",
314-
"gyroscope;\n",
315-
"hid;\n",
316-
"identity-credentials-get;\n",
317-
"idle-detection;\n",
318-
"magnetometer;\n",
319-
"microphone;\n",
320-
"midi;\n",
321-
"payment;\n",
322-
"picture-in-picture;\n",
323-
"publickey-credentials-get;\n",
324-
"screen-wake-lock;\n",
325-
"serial;\n",
326-
"usb;\n",
327-
"web-share;\n",
328-
"xr-spatial-tracking\n",
329-
"\"></iframe> \"\"\")"
302+
" }\" 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> \"\"\")"
330303
]
331304
},
332305
{
@@ -368,6 +341,79 @@
368341
"server.stop()"
369342
]
370343
},
344+
{
345+
"cell_type": "markdown",
346+
"id": "1ef8dfe3",
347+
"metadata": {},
348+
"source": [
349+
"## jupy_app"
350+
]
351+
},
352+
{
353+
"cell_type": "code",
354+
"execution_count": null,
355+
"id": "377f5ac6",
356+
"metadata": {},
357+
"outputs": [],
358+
"source": [
359+
"#| export\n",
360+
"def jupy_app(pico=False, hdrs=None, middleware=None, **kwargs):\n",
361+
" \"Same as `fast_app` but for Jupyter notebooks\"\n",
362+
" hdrs = listify(hdrs)+[_iframe_scr]\n",
363+
" middleware = listify(middleware)+[cors_allow]\n",
364+
" return fast_app(pico=pico, hdrs=hdrs, middleware=middleware, **kwargs)"
365+
]
366+
},
367+
{
368+
"cell_type": "code",
369+
"execution_count": null,
370+
"id": "2b40a967",
371+
"metadata": {},
372+
"outputs": [],
373+
"source": [
374+
"app,rt = jupy_app()\n",
375+
"server = JupyUvi(app)"
376+
]
377+
},
378+
{
379+
"cell_type": "code",
380+
"execution_count": null,
381+
"id": "9f3f28ab",
382+
"metadata": {},
383+
"outputs": [],
384+
"source": [
385+
"@rt\n",
386+
"def index():\n",
387+
" return Div(\n",
388+
" P(A('Click me', hx_get=update, hx_target='#result')),\n",
389+
" P(A('No me!', hx_get=update, hx_target='#result')),\n",
390+
" Div(id='result'))\n",
391+
"\n",
392+
"@rt\n",
393+
"def update(): return Div(P('Hi!'),P('Rachel!'))"
394+
]
395+
},
396+
{
397+
"cell_type": "code",
398+
"execution_count": null,
399+
"id": "9a8da293",
400+
"metadata": {},
401+
"outputs": [],
402+
"source": [
403+
"# Run the notebook locally to see the HTMX iframe in action\n",
404+
"# HTMX()"
405+
]
406+
},
407+
{
408+
"cell_type": "code",
409+
"execution_count": null,
410+
"id": "f11274ba",
411+
"metadata": {},
412+
"outputs": [],
413+
"source": [
414+
"server.stop()"
415+
]
416+
},
371417
{
372418
"cell_type": "markdown",
373419
"id": "474e14b4",

nbs/api/10_fastapp.ipynb

Lines changed: 1 addition & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,7 @@
5050
"from fasthtml.basics import *\n",
5151
"from fasthtml.pico import *\n",
5252
"from fasthtml.starlette import *\n",
53-
"from fasthtml.live_reload import FastHTMLWithLiveReload\n",
54-
"from fasthtml.jupyter import _iframe_scr, cors_allow"
55-
]
56-
},
57-
{
58-
"cell_type": "code",
59-
"execution_count": null,
60-
"metadata": {},
61-
"outputs": [],
62-
"source": [
63-
"from fasthtml.jupyter import JupyUvi,HTMX"
53+
"from fasthtml.live_reload import FastHTMLWithLiveReload"
6454
]
6555
},
6656
{
@@ -160,66 +150,6 @@
160150
" return app,app.route,*dbtbls"
161151
]
162152
},
163-
{
164-
"cell_type": "code",
165-
"execution_count": null,
166-
"metadata": {},
167-
"outputs": [],
168-
"source": [
169-
"#| export\n",
170-
"def jupy_app(pico=False, hdrs=None, middleware=None, **kwargs):\n",
171-
" \"Same as `fast_app` but for Jupyter notebooks\"\n",
172-
" hdrs = listify(hdrs)+[_iframe_scr]\n",
173-
" middleware = listify(middleware)+[cors_allow]\n",
174-
" return fast_app(pico=pico, hdrs=hdrs, middleware=middleware, **kwargs)"
175-
]
176-
},
177-
{
178-
"cell_type": "code",
179-
"execution_count": null,
180-
"metadata": {},
181-
"outputs": [],
182-
"source": [
183-
"app,rt = jupy_app()\n",
184-
"server = JupyUvi(app)"
185-
]
186-
},
187-
{
188-
"cell_type": "code",
189-
"execution_count": null,
190-
"metadata": {},
191-
"outputs": [],
192-
"source": [
193-
"@rt\n",
194-
"def index():\n",
195-
" return Div(\n",
196-
" P(A('Click me', hx_get=update, hx_target='#result')),\n",
197-
" P(A('No me!', hx_get=update, hx_target='#result')),\n",
198-
" Div(id='result'))\n",
199-
"\n",
200-
"@rt\n",
201-
"def update(): return Div(P('Hi!'),P('Rachel!'))"
202-
]
203-
},
204-
{
205-
"cell_type": "code",
206-
"execution_count": null,
207-
"metadata": {},
208-
"outputs": [],
209-
"source": [
210-
"# Run the notebook locally to see the HTMX iframe in action\n",
211-
"# HTMX()"
212-
]
213-
},
214-
{
215-
"cell_type": "code",
216-
"execution_count": null,
217-
"metadata": {},
218-
"outputs": [],
219-
"source": [
220-
"server.stop()"
221-
]
222-
},
223153
{
224154
"cell_type": "markdown",
225155
"metadata": {},

0 commit comments

Comments
 (0)