Skip to content
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

fix: Documentation and styling of catalog components #41

Merged
merged 1 commit into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/components.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ The `ludic.attrs` module contains many attribute definition that you can reuse i

- `HtmlAttrs` - Global HTML attributes available in all elements
- The `class` and `for` attributes have the aliases `class_` and `for_`
- `EventAttrs` - Event HTML attributes like `onclick`, `onkey`, and so on.
- `EventAttrs` - Event HTML attributes like `on_click`, `on_key`, and so on.
- `HtmxAttrs` - All [HTMX attributes](https://htmx.org/reference/) available.
- All HTMX attributes have aliases with underscore, e.g. `hx_target`
- `GlobalAttrs` subclasses `HtmlAttrs`, `EventAttrs` and `HtmxAttrs`
Expand Down
2 changes: 1 addition & 1 deletion docs/htmx.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,6 @@ def data() -> div:
return div(
h2("Data"),
table(...),
button("Click Here", onclick=JavaScript("alert('test')")),
button("Click Here", on_click=JavaScript("alert('test')")),
)
```
2 changes: 1 addition & 1 deletion ludic/catalog/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class FormField(Component[TChildren, TAttrs]):
"label": {
"display": "block",
"font-weight": "bold",
"margin": f"{theme.sizes.xxxs} 0 {theme.sizes.xxs}",
"margin-block-end": theme.sizes.xxs,
},
"input": {
"inline-size": "100%",
Expand Down
11 changes: 1 addition & 10 deletions ludic/catalog/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import override

from ludic.attrs import GlobalAttrs
from ludic.html import dd, dl, dt, style
from ludic.html import dd, dl, dt
from ludic.types import Component, PrimitiveChildren

from .utils import attr_to_camel
Expand Down Expand Up @@ -55,15 +55,6 @@ class Pairs(Component[Key | Value, PairsAttrs]):
)
"""

classes = ["stack", "small"]
styles = style.use(
lambda theme: {
".stack.small > dt + dd": {
"margin-block-start": theme.sizes.xxxxs,
},
}
)

@override
def render(self) -> dl:
from_items: list[Key | Value] = []
Expand Down
10 changes: 5 additions & 5 deletions ludic/catalog/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ class Loading(Component[AnyChildren, NoAttrs]):
".lds-ellipsis": {
"display": "inline-block",
"position": "relative",
"width": "80px",
"height": "80px",
"width": theme.sizes.m * 5,
"height": theme.sizes.m,
"margin": theme.sizes.xl,
},
".lds-ellipsis div": {
"position": "absolute",
"top": "33px",
"width": "13px",
"height": "13px",
"width": theme.sizes.m,
"height": theme.sizes.m,
"border-radius": "50%",
"background": theme.colors.dark,
"animation-timing-function": "cubic-bezier(0, 1, 1, 0)",
Expand Down
8 changes: 4 additions & 4 deletions ludic/catalog/pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ class HtmlPage(ComponentStrict[Head, Body, NoAttrs]):
"dl": {
"margin-block": "0",
},
"dl dt": {
"margin-block-start": theme.sizes.xxs,
"dl dd + dt": {
"margin-block-start": theme.sizes.xs,
},
"dl dd": {
"margin-block-start": theme.sizes.xxxs,
"dl dt + dd": {
"margin-block-start": theme.sizes.xxxxs,
},
"dt": {
"font-weight": "bold",
Expand Down
13 changes: 8 additions & 5 deletions ludic/web/endpoints.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import inspect
from collections.abc import Callable
from typing import Any, ClassVar, Protocol, cast
from typing import Any, ClassVar, Protocol

from starlette.datastructures import URL
from starlette.endpoints import HTTPEndpoint as BaseEndpoint
Expand Down Expand Up @@ -51,6 +51,11 @@ class Endpoint(Component[NoChildren, TAttrs]):

route: ClassVar[Route]

@property
def request(self) -> Request | None:
"""The current request."""
return self.context.get("request")

def lazy_load(
self,
endpoint: type[RoutedProtocol],
Expand Down Expand Up @@ -79,9 +84,7 @@ def url_for(self, endpoint: type[RoutedProtocol] | str, **path_params: Any) -> U
Returns:
The URL.
"""
request = self.context.get("request")

if request is None or not isinstance(request, Request):
if self.request is None or not isinstance(self.request, Request):
raise RuntimeError(
f"{type(self).__name__} is not bound to a request, you can only use "
f"the {type(self).__name__}.url_for method in the context of a request."
Expand All @@ -102,4 +105,4 @@ def url_for(self, endpoint: type[RoutedProtocol] | str, **path_params: Any) -> U
if key in endpoint.route.param_convertors
}

return cast(URL, request.url_for(endpoint, **path_params))
return self.request.url_for(endpoint, **path_params)
2 changes: 1 addition & 1 deletion tests/test_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def test_pairs() -> None:
Value(42),
)
assert pairs.to_html() == (
'<dl class="stack small">'
'<dl>'
'<dt>Name</dt>'
'<dd>John</dd>'
'<dt>Age</dt>'
Expand Down