This repository has been archived by the owner on Jul 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
232 additions
and
62 deletions.
There are no files selected for viewing
Empty file.
Empty file.
110 changes: 110 additions & 0 deletions
110
docs/src/documentation/app/group__docs/actions/dynamic__action_type/page.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
from typing import Annotated | ||
|
||
import flect.actions as a | ||
import flect.components as c | ||
from fastapi import Path, Request | ||
from flect import Meta, PageResponse | ||
from flect.routing import CLIENT_ROOT_ROUTER_PREFIX | ||
from flect.sitemap import Sitemap | ||
|
||
from documentation.app.group__docs.component import get_api_reference_section | ||
from documentation.app.group__docs.layout import get_docs_pager | ||
|
||
ACTION_DOCS_MAP = { | ||
"notify": [ | ||
c.Container( | ||
children=[ | ||
c.Heading( | ||
level=1, | ||
text="Notify", | ||
class_name="text-3xl mb-3", | ||
), | ||
c.Paragraph(text="The Notify action is used to show a notification with a title and a description."), | ||
] | ||
), | ||
c.Container( | ||
children=[ | ||
c.Heading( | ||
level=2, | ||
text="Try it out", | ||
class_name="text-2xl mb-6 border-b pb-2", | ||
), | ||
c.Button( | ||
on_click_action=a.Notify( | ||
title="Button clicked", | ||
description="The button was clicked", | ||
), | ||
children=[ | ||
c.Text( | ||
text="Click me", | ||
) | ||
], | ||
), | ||
] | ||
), | ||
get_api_reference_section(a.Notify), | ||
], | ||
"redirect": [ | ||
c.Container( | ||
children=[ | ||
c.Heading( | ||
level=1, | ||
text="Notify", | ||
class_name="text-3xl mb-3", | ||
), | ||
c.Paragraph(text="The Redirect action is used to navigate to a different URL."), | ||
] | ||
), | ||
c.Container( | ||
children=[ | ||
c.Heading( | ||
level=2, | ||
text="Try it out", | ||
class_name="text-2xl mb-6 border-b pb-2", | ||
), | ||
c.Button( | ||
on_click_action=a.Redirect(url="/actions/notify/"), | ||
children=[ | ||
c.Text( | ||
text="Click button will redirect to /actions/notify/", | ||
) | ||
], | ||
), | ||
] | ||
), | ||
get_api_reference_section(a.Redirect), | ||
], | ||
} | ||
|
||
|
||
async def sitemap(dynamic_url: str) -> list[Sitemap]: | ||
return [ | ||
Sitemap( | ||
url=dynamic_url.format(action_type=action_type), | ||
last_modified=None, | ||
change_frequency=None, | ||
priority=None, | ||
) | ||
for action_type in ACTION_DOCS_MAP | ||
] | ||
|
||
|
||
async def page( | ||
request: Request, | ||
action_type: Annotated[str, Path(..., description="The action type to render")], | ||
) -> PageResponse: | ||
component_elements = ACTION_DOCS_MAP.get(action_type, c.Text(text="Unknown action")) | ||
return PageResponse( | ||
meta=Meta( | ||
title=f"{action_type} action", | ||
description=f"{action_type} action", | ||
), | ||
element=c.Container( | ||
tag="div", | ||
class_name="flex gap-12 flex-col", | ||
children=[ | ||
*component_elements, | ||
get_docs_pager(current_link=request.url.path.replace(CLIENT_ROOT_ROUTER_PREFIX, "")), | ||
], | ||
), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from typing import Optional | ||
|
||
import flect.components as c | ||
from pydantic import BaseModel | ||
from pydantic_core import PydanticUndefined | ||
|
||
|
||
class APIReference(BaseModel): | ||
prop: str | ||
type: str | ||
default: Optional[str] | ||
description: Optional[str] | ||
|
||
|
||
def get_api_reference_section(component: c.AnyComponent) -> c.Container: | ||
props = [] | ||
for field, filed_info in component.model_fields.items(): | ||
if field in ["component_type", "action_type"]: | ||
continue | ||
if field == "children": | ||
filed_info.annotation = "flect.components.AnyComponents" | ||
filed_info.default = "[]" | ||
filed_info.description = "The children of the component." | ||
if filed_info.default == PydanticUndefined: | ||
filed_info.default = "-" | ||
props.append( | ||
APIReference( | ||
prop=field, | ||
type=str(filed_info.annotation), | ||
default=filed_info.default or "-", | ||
description=filed_info.description, | ||
) | ||
) | ||
return c.Container( | ||
tag="section", | ||
children=[ | ||
c.Heading( | ||
level=2, | ||
text="API Reference", | ||
class_name="text-2xl mb-6 border-b pb-2", | ||
), | ||
c.Table(datasets=props), | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[project] | ||
name = "flect" | ||
version = "0.1.6" | ||
version = "0.1.7" | ||
description = "Turning ideas into web app fast." | ||
authors = [ | ||
{name = "Chaoying", email = "[email protected]"}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.