-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from angrybayblade/feat/named-arguments
Named arguments
- Loading branch information
Showing
4 changed files
with
146 additions
and
7 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import typing as t | ||
|
||
from ph7.html import body, div, html, node | ||
|
||
user = div(class_name="user") | ||
users = div(class_name="user") | ||
nousers = div("Error, Users not found", class_name="error") | ||
|
||
|
||
def render_users(number_of_users: t.Optional[int] = None) -> node: | ||
"""Render users.""" | ||
if number_of_users is None: | ||
return nousers | ||
return users(user(f"User {i}") for i in range(number_of_users)) | ||
|
||
|
||
template = html( | ||
body( | ||
render_users, | ||
) | ||
) | ||
|
||
print("<!-- With `number_of_users` parameter -->\n") | ||
print(template.render(context={"number_of_users": 5}), end="\n\n") | ||
|
||
print("<!-- Without `number_of_users` parameter -->\n") | ||
print(template.render(context={})) |
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