Skip to content

Commit

Permalink
docs: substitution script
Browse files Browse the repository at this point in the history
  • Loading branch information
angrybayblade committed Mar 12, 2024
1 parent e77077b commit 6c7123a
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 40 deletions.
21 changes: 1 addition & 20 deletions docs/css.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ from ph7.html import body, div, head, html


class flex_center(CSSObject):
"""Flex center."""

display = "flex"
align_items = "center"
justify_content = "center"
Expand Down Expand Up @@ -104,16 +102,12 @@ from ph7 import CSSObject


class flex_center(CSSObject):
"""Flex center."""

display = "flex"
align_items = "center"
justify_content = "center"


class textbox(flex_center):
"""Text container."""

height = "100vh"
width = "100vw"

Expand Down Expand Up @@ -142,22 +136,16 @@ from ph7 import CSSObject


class flex_center(CSSObject):
"""Flex center."""

display = "flex"
align_items = "center"
justify_content = "center"


class textbox(flex_center):
"""Text container."""

height = "100vh"
width = "100vw"

class text(CSSObject):
"""Text styling."""

font_size = "12px"
font_weight = "500"
font_family = "Lucida Console, Monaco, monospace"
Expand Down Expand Up @@ -192,27 +180,20 @@ A pseudo class can be defined by adding `_` at the beginning of class name, for
<!-- {"type": "css", "file": "examples/css_pseudo_class.py", "class": "side-by-side"} -->
<div class='side-by-side'>
```python
from ph7 import CSSObject, include
from ph7.html import body, div, head, html
from ph7 import CSSObject


class item(CSSObject):
"""Flex center."""

height = "30px"
width = "100%"

margin_top = "5px"

class _nth_child(CSSObject):
"""Nth child."""

child = 1
margin_top = "0px"

class __before(CSSObject):
"""Before selector."""

content = '">"'


Expand Down
25 changes: 15 additions & 10 deletions docs/django.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ Define your stylesheet using [`CSSObject`](/css/#cssobject) and use [`Static Con
from ph7.css import CSSObject


class main(CSSObject):
class container(CSSObject):
display = "flex"
align_items = "center"
justify_content = "center"
Expand Down Expand Up @@ -167,7 +167,7 @@ template = html(
body(
div(
"Hello, World!",
class_name=stylesheet.main,
class_name=stylesheet.container,
)
),
)
Expand Down Expand Up @@ -240,13 +240,23 @@ Use the function in the view
<!-- {"type": "html", "file": "examples/django_app/javascript/templates/__init__.py", "input_only": true} -->
```python
from javascript.templates.script import fetchDog
from javascript.templates.styles import image, main
from javascript.templates.styles import container, image

from ph7.context import ctx
from ph7.html import body, button, div, head, html, img

ctx.static.view(__name__)


def _fetch():
return button(
"Click to fetch a dog",
on={
"click": fetchDog(),
},
)


template = html(
head(
ctx.static.include,
Expand All @@ -259,13 +269,8 @@ template = html(
alt="Click to fetch dog",
class_name=image,
),
button(
"Click to fetch a dog",
on={
"click": fetchDog(),
},
),
class_name=main,
_fetch,
class_name=container,
)
),
)
Expand Down
10 changes: 3 additions & 7 deletions docs/html.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,6 @@ nousers = div("Error, Users not found", class_name="error")


def render_users(context: t.Dict) -> HtmlNode:
"""Render users."""
if "number_of_users" not in context:
return nousers
return users(user(f"User {i}") for i in range(context["number_of_users"]))
Expand Down Expand Up @@ -309,7 +308,6 @@ nousers = div("Error, Users not found", class_name="error")


def render_users(number_of_users: t.Optional[int] = None) -> HtmlNode:
"""Render users."""
if number_of_users is None:
return nousers
return users(user(f"User {i}") for i in range(number_of_users))
Expand Down Expand Up @@ -370,12 +368,10 @@ nousers = div("Error, Users not found", class_name="error")

@lru_cache
def _render_users(n: int) -> HtmlNode:
"""Render users."""
return users(user(f"User {i}") for i in range(n))


def render_users(context: t.Dict) -> HtmlNode:
"""Render users."""
if "number_of_users" not in context:
return nousers
return _render_users(n=context["number_of_users"])
Expand All @@ -401,9 +397,9 @@ print(f"Third render: {time.perf_counter() - tick}")
```

```stdout
First render: 6.493273332999999
Second render: 0.4277449579999999
Third render: 0.3591492089999999
First render: 6.325592083
Second render: 0.3570236659999999
Third render: 0.3628813340000008
```
<!-- end -->

Expand Down
2 changes: 0 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ from ph7.css import CSSObject


class flex_center(CSSObject):
"""Flex center"""

display = "flex"
align_items = "center"
justify_content = "center"
Expand Down
1 change: 0 additions & 1 deletion docs/js.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ def _user(name: str) -> HtmlNode:


def _users(context: dict) -> HtmlNode:
"""List users."""
return div(_user(name=name) for name in context["users"])


Expand Down

0 comments on commit 6c7123a

Please sign in to comment.