Skip to content

Commit 0ec6cc4

Browse files
committed
Monsterfied session 1
1 parent 3d8b074 commit 0ec6cc4

10 files changed

+59
-147
lines changed

app.py

+39-17
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,56 @@
1-
from fh_bootstrap import *
21
from itertools import chain
3-
from markdown import markdown
4-
5-
md_exts='codehilite', 'smarty', 'extra', 'sane_lists'
6-
def Markdown(s, exts=md_exts, **kw): return Div(NotStr(markdown(s, extensions=exts)), **kw)
2+
from fasthtml.common import *
3+
from functools import partial
4+
from monsterui.all import *
5+
from fasthtml.components import Uk_theme_switcher
6+
_A = partial(A, target='_blank')
7+
def Markdown(s, **kw): return Div(render_md(s, class_map_mods={'ul':'uk-list uk-list-bullet space-y-2 mb-6 ml-6 text-lg'}), **kw)
78

89
ghurl = 'https://github.com/AnswerDotAI/fasthtml'
910
fhurl = 'https://fastht.ml'
1011
docs = 'https://docs.fastht.ml'
1112

12-
def BstPage(selidx, title, *c):
13+
def BstPage(selidx, title, h2s, *c):
1314
navitems = [('About', '/'), ('Vision', '/vision'), ('Foundations', '/foundation'),
1415
('Technology', '/tech'), ('Components', '/components'), ('Limits', '#', {'disabled':True})]
1516
logo = 'assets/logo.svg'
16-
ra_items = (A('Docs', href=docs, cls="nav-link"),
17-
Icon('fab fa-github', dark=False, sz='lg', href=ghurl, cls='ms-2 px-2'))
18-
ftlinks = [A(k, href=v, cls='nav-link px-2 text-muted')
19-
for k,v in dict(Home='/', Docs=docs, Company='https://www.answer.ai').items()]
17+
_NavBarP = partial(P, cls=TextT.lg)
2018
return (
2119
Title(title),
22-
Script('initTOC()'),
2320
Container(
24-
Navbar('nav', selidx, items=navitems, ra_items=ra_items, cls='navbar-light bg-secondary rounded-lg',
25-
image=f'/{logo}', hdr_href=fhurl, placement=PlacementT.Default, expand=SizeT.Md, toggle_left=False),
26-
Toc(Container(H1(title, cls='pb-2 pt-1'), *c, cls='mt-3')),
27-
BstFooter('© 2024 onwards AnswerDotAI, Inc', File(logo), img_href=fhurl, cs=ftlinks),
28-
typ=ContainerT.Xl, cls='mt-3', data_bs_spy='scroll', data_bs_target='#toc'))
21+
# NavBar
22+
NavBarContainer(
23+
NavBarLSide(
24+
NavBarNav(
25+
Li(A(Img(src=logo), href=fhurl)),
26+
*[Li(A(_NavBarP(k), href=v), cls='uk-active' if selidx==i else '') for i, (k,v) in enumerate(navitems[:-1])],
27+
Li(A(_NavBarP('Limits', href='#'), disabled=True, uk_tooltip='No limits!')))),
28+
NavBarRSide(
29+
NavBarNav(
30+
Li(A(_NavBarP("Theme"))),DropDownNavContainer(Div(Uk_theme_switcher(), cls='p-6 uk-drop-close'), cls='w-96'),
31+
Li(_A(_NavBarP('Docs'), href=docs)),
32+
Li(_A(_NavBarP(UkIcon('github')), href=ghurl)))),
33+
cls='bg-green-400/70 rounded-lg rounded-tl-3xl shadow-md p-2 px-4'),
34+
# Main Content
35+
Container(
36+
Grid(
37+
Div(NavContainer(*[Li(A(h2, href=f'#sec{i+1}')) for i,h2 in enumerate(h2s)],
38+
sticky=True, uk_scrollspy_nav=True), cls='hidden md:block col-span-1'),
39+
Div(H1(title, cls='mb-12'), *c, cls='col-span-12 md:col-span-5'),
40+
cols=6)),
41+
# Footer
42+
DividerLine(),
43+
Grid(
44+
P("© 2024 onwards AnswerDotAI, Inc", cls=TextPresets.muted_lg),
45+
DivCentered(A(Img(src=logo, height=24), href=fhurl)),
46+
DivRAligned(A("Home"),
47+
_A("Docs",href='https://docs.fastht.ml/'),
48+
_A("Company", href='https://www.answer.ai/'), cls=TextPresets.muted_lg+'space-x-4'),
49+
),
50+
cls='py-8 mb-4' + ContainerT.xl))
2951

3052
def Sections(h2s, texts):
3153
colors = 'yellow', 'pink', 'teal', 'blue'
32-
div_cls = 'py-2 px-3 mt-4 bg-light-{} rounded-tl-lg'
54+
div_cls = 'py-2 px-3 mt-4 mb-2 bg-{}-400/70 shadow-md rounded-lg rounded-tl-3xl' #bg-{}-100
3355
return chain([Div(H2(h2, id=f'sec{i+1}', cls=div_cls.format(colors[i%4])), Div(txt, cls='px-2'))
3456
for i,(h2,txt) in enumerate(zip(h2s, texts))])

assets/hl-styles.css

-74
This file was deleted.

assets/styles.css

-34
This file was deleted.

components.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ def page():
44
h2s = 'Why', 'How', 'The future'
55
txts = [Markdown(s1), Markdown(s2), Markdown(s3)]
66
secs = Sections(h2s, txts)
7-
return BstPage(4, "Python HTML components", *secs)
7+
return BstPage(4, "Python HTML components", h2s, *secs)
88

99
s1 = """
1010
FastHTML embeds HTML generation inside Python code. The idea of embedding an HTML generator inside a programming language is not new. It is a particularly popular approach in functional languages, and includes libraries like: Elm-html (Elm), hiccl (Common Lisp), hiccup (Clojure), Falco.Markup (F#), Lucid (Haskell), and dream-html (OCaml). But the idea has now gone far beyond the functional programming world--- JSX, an embedded HTML generator for React, is one of the most popular approaches for creating web apps today.

foundations.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from app import *
22

33
def page():
4-
secs = Sections(('ASGI', 'HTMX', 'HTTP', 'HTML/CSS/JS'),
5-
map(Markdown, [s1, s2, s3, s4]))
6-
return BstPage(2, 'The foundations of FastHTML', *secs)
4+
h2s = 'ASGI', 'HTMX', 'HTTP', 'HTML/CSS/JS'
5+
secs = Sections(h2s, map(Markdown, [s1, s2, s3, s4]))
6+
return BstPage(2, 'The foundations of FastHTML', h2s, *secs)
77

88
s1 = """
99
FastHTML brings together and builds on top of two well-established, astonishingly flexible, performant technology frameworks: *ASGI* (implemented in Uvicorn and Starlette), and *HTMX*.
@@ -63,7 +63,7 @@ def page():
6363
s4 = """
6464
In the previous section, the server responded with the body "`hello`". But in practice, web server responses today generally are either HTML or JSON. With FastHTML (as we'll see in the [HTMX technology section](/tech#sec2)), our responses are nearly always HTML. Here's an example of a basic HTML page with a header and a body containing a paragraph (`<p>` tag).
6565
66-
```
66+
```html
6767
<html>
6868
<head><title>Example</title></head>
6969
<body><p>Hello World!</p></body>

main.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
from fh_bootstrap import *
21
import vision, overview, foundations, tech, components
2+
from fasthtml.common import *
3+
from monsterui.all import *
34

45
hdrs = (
5-
Link(href='/assets/hl-styles.css', rel='stylesheet'),
6-
Link(href='/assets/styles.css', rel='stylesheet'),
6+
*Theme.blue.headers(highlightjs=True),
7+
Script(src="https://cdn.jsdelivr.net/gh/highlightjs/[email protected]/build/languages/html.min.js"),
78
*Socials(title='About FastHTML', description='Learn the foundations of FastHTML', site_name='about.fastht.ml',
8-
twitter_site='@answerdotai', image=f'/assets/og-sq.png', url='')
9+
twitter_site='@answerdotai', image=f'/assets/og-sq.png', url=''),
910
)
1011

11-
app,rt = fast_app(pico=False, hdrs=bst_hdrs+hdrs, live=False)
12+
app,rt = fast_app(pico=False, hdrs=hdrs, live=False)
1213

1314
app.get('/')(overview.page)
1415
app.get('/components')(components.page)

overview.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
def page():
44
caption = "'Real' web development shouldn't be this hard..."
5-
fig = Image('/assets/webdev.jpg', alt='Web dev', caption=caption, left=False)
5+
fig = Figure(DivCentered(Img(src='/assets/webdev.jpg', alt='Web dev'), Caption(caption, cls=TextT.lg+'pt-4')), cls='float-right w-1/2 m-4')
66
h2s = 'Getting started', 'Background', 'Current Status'
77
txts = [Markdown(s1), Div(fig, Markdown(s2)), Markdown(s3)]
88
secs = Sections(h2s, txts)
9-
return BstPage(0, 'About FastHTML', *secs)
9+
return BstPage(0, 'About FastHTML', h2s, *secs)
1010

1111
s1 = """
1212
FastHTML is a new way to create modern interactive web apps. It scales down to a 6-line python file, and scales up to complex production apps. Auth, DBs, caching, styling, etc are all built-in, and replaceable and extensible. 1-click deploy is available to Railway, Vercel, Huggingface, and more---or deploy to any Python server or VPS, including Azure, GCP, and AWS.

requirements.txt

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
1-
python-fasthtml>=0.1.11
2-
pygments
3-
markdown
4-
fh-bootstrap>=0.0.3
5-
1+
python-fasthtml
2+
monsterui

tech.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ def page():
44
h2s = 'Python', 'HTMX', 'Uvicorn', 'Starlette', 'SQLite'
55
txts = [Markdown(s1), Markdown(s2), Markdown(s3), Markdown(s4), Markdown(s5)]
66
secs = Sections(h2s, txts)
7-
return BstPage(3, "FastHTML's tech stack", *secs)
7+
return BstPage(3, "FastHTML's tech stack", h2s, *secs)
88

99
s1 = """
1010
Many of the largest software systems in the world are built using Python, such as much of the code for YouTube, Instagram, Dropbox, and many others. In 2019, Dropbox announced that python was their "most widely used language both for backend services and the desktop client app", with 4 million lines of code.
@@ -21,7 +21,7 @@ def page():
2121
2222
An alternative "hypermedia-based" approach, used by [HTMX](https://htmx.org/), simplifies things greatly by just returning HTML. FastHTML is designed to create hypermedia applications. Nearly all of the complexity of client-server programming vanishes when using this approach. When going to a page directly, the server will respond with a standard HTML web page:
2323
24-
```
24+
```html
2525
<html>
2626
<head><title>FastHTML Page</title></head>
2727
<body>
@@ -39,7 +39,7 @@ def get(): return Div(P('Hello World!'), hx_get="/change")
3939
4040
When clicking on this link, the server will respond with an "*HTML partial*"---that is, just a snippet of HTML which will be inserted into the existing page:
4141
42-
```
42+
```html
4343
<p>Nice to be here!</p>
4444
```
4545

vision.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
def page():
44
caption = "A minimal FastHTML app really is minimal."
5-
fig = Image('assets/hello.png', alt='Web dev', caption=caption, left=False, retina=True)
5+
fig = Figure(DivCentered(Img(src='assets/hello.png', alt='Web dev', cls='h-60'), Caption(caption, cls=TextT.lg+'pt-2')), cls='float-right m-2')
66
h2s = 'No compromise', 'Scaling down', 'Scaling up'
77
txts = [Markdown(s1), Div(fig, Markdown(s2)), Markdown(s3)]
88
secs = Sections(h2s, txts)
9-
return BstPage(1, 'The FastHTML Vision', *secs)
9+
return BstPage(1, 'The FastHTML Vision', h2s, *secs)
1010

1111
s1 = """FastHTML is a general-purpose full-stack web programming system, in the same vein as Django, NextJS, and Ruby on Rails. The vision is to make it the easiest way to create quick prototypes, and **also** the easiest way to create scalable, powerful, rich applications.
1212

0 commit comments

Comments
 (0)