Skip to content

Commit

Permalink
more example htmy app simplification, refs #42
Browse files Browse the repository at this point in the history
  • Loading branch information
volfpeter committed Nov 26, 2024
1 parent 4970147 commit 2f28eb0
Showing 1 changed file with 5 additions and 16 deletions.
21 changes: 5 additions & 16 deletions examples/htmy-rendering/htmy_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from datetime import date

from fastapi import FastAPI
from htmy import Component, ComponentType, Context, html
from htmy import Component, Context, html
from pydantic import BaseModel

from fasthx.htmy import HTMY, ComponentHeader, CurrentRequest, RouteParams
Expand Down Expand Up @@ -89,10 +89,8 @@ def htmy(self, context: Context) -> Component:


@dataclass
class Page:
"""Base page layout."""

content: ComponentType
class IndexPage:
"""Index page with TailwindCSS styling."""

def htmy(self, context: Context) -> Component:
return (
Expand All @@ -109,8 +107,8 @@ def htmy(self, context: Context) -> Component:
html.script(src="https://unpkg.com/[email protected]"),
),
html.body(
# Page content
self.content,
# Page content: lazy-loaded user list.
html.div(hx_get="/users", hx_trigger="load", hx_swap="outerHTML"),
class_=(
"h-screen w-screen flex flex-col items-center justify-center "
" gap-4 bg-slate-800 text-white"
Expand All @@ -120,15 +118,6 @@ def htmy(self, context: Context) -> Component:
)


@dataclass
class IndexPage:
"""Index page."""

def htmy(self, context: Context) -> Component:
# Lazy load the user list.
return Page(html.div(hx_get="/users", hx_trigger="load", hx_swap="outerHTML"))


# -- Application

# Create the app instance.
Expand Down

0 comments on commit 2f28eb0

Please sign in to comment.