-
-
Notifications
You must be signed in to change notification settings - Fork 96
Docs improvements #1162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Docs improvements #1162
Changes from 8 commits
0bfb7f2
7d1cad7
ec7d844
77ce69d
ab3989a
0c730eb
9f591d7
d2420b3
72d0558
26b08d7
901f13d
968bf25
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -73,7 +73,9 @@ app = air.Air() | |
| async def login(request: Request): | ||
| form = await request.form() | ||
| return air.layouts.mvpcss( | ||
| air.Section(air.Aside({"username": form.get("username")})) | ||
| air.Section( | ||
| air.Aside({"username": form.get("username")}), | ||
| ), | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I take it this reduces cognitive load / friction for new users? @MrValdez
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, as I read through the rest of the diff I could see it feels better with the spacing. |
||
| ) | ||
| ``` | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,24 +1,23 @@ | ||
| Routing | ||
| ## Routing | ||
|
|
||
| If you need to knit several Python modules with their own Air views into one, that's where Routing is used. They allow the near seamless combination of multiple Air apps into one. Larger sites are often built from multiple routers. | ||
| If you need to knit several Python modules with their own Air views into one, you will need to use Routing. This allow the near seamless combination of multiple Air apps into one. Larger sites are often built from multiple routers. | ||
|
|
||
| Let's imagine we have an e-commerce store with a shopping cart app. Use instantiate a `router` object using `air.AirRouter()` just as we would with `air.App()`: | ||
| For this example, let's imagine we have an e-commerce store with a shopping cart app with a `cart.py` and `main.py` file. | ||
|
|
||
| ```python | ||
| # cart.py | ||
| ```python title="cart.py" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whoa, didn't know about this, cool! |
||
| import air | ||
|
|
||
| router = air.AirRouter() | ||
|
|
||
|
|
||
| @router.page | ||
| def cart(): | ||
| def cart_page(): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great catch |
||
| return air.H1("I am a shopping cart") | ||
| ``` | ||
|
|
||
| Then in our main page we can load that and tie it into our main `app`. | ||
| Then in our main page we can load that and tie it into our `main.py` app. | ||
|
|
||
| ```python | ||
| ```python title="cart.py" | ||
| import air | ||
| from cart import router as cart_router | ||
|
|
||
|
|
@@ -31,21 +30,24 @@ def index(): | |
| return air.H1("Home page") | ||
| ``` | ||
|
|
||
| Note that the router allows sharing of sessions and other application states. | ||
| `AirRouter` allows the sharing of sessions and other application states between routes. | ||
|
|
||
| In addition, we can add links through the `.url()` method available on route functions, which generates URLs programmatically: | ||
| In addition, we can add links through the `.url()` method available on route functions: | ||
|
|
||
| ```python | ||
| ```python title="main.py" | ||
| import air | ||
| from cart import router as cart_router, cart | ||
| from cart import router as cart_router, cart_page | ||
|
|
||
| app = air.Air() | ||
| app.include_router(cart_router) | ||
|
|
||
|
|
||
| @app.page | ||
| def index(): | ||
| return air.Div(air.H1("Home page"), air.A("View cart", href=cart.url())) | ||
| return air.Div( | ||
| air.H1("Home page"), | ||
| air.A("View cart", href=cart_page.url()), | ||
| ) | ||
| ``` | ||
|
|
||
| ## Query Parameters | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -169,6 +169,20 @@ renders as | |
| </script> | ||
| ``` | ||
|
|
||
| ### Passing reserved words as kwargs | ||
|
|
||
| Alternately, we can pass reserved keywords as kwargs. | ||
|
|
||
| ```python | ||
| air.Label("Email", **{"class": "plain", "for": "email"}) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like it :) |
||
| ``` | ||
|
|
||
| Renders as: | ||
|
|
||
| ```html | ||
| <label class="plain" for="email">Email</label> | ||
| ``` | ||
|
|
||
| ### Attributes starting with special characters | ||
|
|
||
| To get around that in Python we can't begin function arguments with special characters, we lean into how **Air Tags** is kwargs friendly. | ||
|
audreyfeldroy marked this conversation as resolved.
Outdated
|
||
|
|
@@ -275,7 +289,11 @@ Subclasses are not the only way to create custom Air Tags. You can also use func | |
|
|
||
| ```python | ||
| def card(*content, header: str, footer: str): | ||
| return air.Article(air.Header(header), *content, air.Footer(footer)) | ||
| return air.Article( | ||
| air.Header(header), | ||
| *content, | ||
| air.Footer(footer), | ||
| ) | ||
| ``` | ||
|
|
||
| We can use this function to create a card: | ||
|
|
@@ -365,5 +383,12 @@ air.BaseTag.from_html_to_source(""" | |
| This generates: | ||
|
|
||
| ```python | ||
| air.Html(air.Body(air.Main(air.H1("Hello, World", class_="header")))) | ||
| air.Html( | ||
| air.Head(), | ||
| air.Body( | ||
| air.Main( | ||
| air.H1('Hello, World', class_='header'), | ||
| ), | ||
| ), | ||
| ) | ||
| ``` | ||
Uh oh!
There was an error while loading. Please reload this page.