-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
omit attr with None; remove prettify; add demo
- Loading branch information
Showing
9 changed files
with
234 additions
and
169 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 @@ | ||
<!DOCTYPE html><!--this is a demo showing how to use `tagit`--><html><head><title>testing html template</title><script defer src="https://cdn.jsdelivr.net/npm/@unocss/runtime/attributify.global.js"></script></head><body><img src="https://picsum.photos/200/300" /><div class="text-xl">pls select the direction:</div><select data-type="direction"><option>E</option><option selected>S</option><option>W</option><option>N</option></select><MyElement props="some-props" /></body></html> |
This file was deleted.
Oops, something went wrong.
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,52 @@ | ||
# standard elements | ||
from tagit import html, div, img, body, head, title, script, select, option | ||
|
||
# for creating custom element | ||
from tagit import tag | ||
|
||
# special elements | ||
from tagit import doctype, comment | ||
|
||
|
||
html_str = ( | ||
doctype() | ||
+ comment("this is a demo showing how to use `tagit`") | ||
+ html( | ||
# use list to enclose multiple elements | ||
[ | ||
head( | ||
[ | ||
title("testing html template"), | ||
script( | ||
"", # empty string content ensures closing tag | ||
"defer", # positional argument will be converted to value-less(boolean) attribute | ||
src="https://cdn.jsdelivr.net/npm/@unocss/runtime/attributify.global.js", | ||
), | ||
] | ||
), | ||
body( | ||
[ | ||
# if you don't provide content, element without closing tag will be created | ||
img(src="https://picsum.photos/200/300"), | ||
# class_ attribute will convert to `class` | ||
div("pls select the direction:", class_="text-xl"), | ||
select( | ||
[ | ||
# attr with None will be ommitted, | ||
# and empty string will be converted to boolean attribute | ||
option(d, selected=("" if d == "S" else None)) | ||
for d in "ESWN" | ||
], | ||
# underscore will convert to hyphen, eg. `data-type` | ||
data_type="direction", | ||
), | ||
# create custom element | ||
tag("MyElement", props="some-props"), | ||
], | ||
), | ||
] | ||
) | ||
) | ||
|
||
with open("demo.html", "w") as f: | ||
f.write(html_str) |
Oops, something went wrong.