Skip to content

Commit 9ec0556

Browse files
authored
Merge pull request #12 from t-strings/add-examples
Add examples
2 parents 7162f53 + 7f1720b commit 9ec0556

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+2138
-90
lines changed

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,7 @@ clean-playground:
5050
.PHONY: check-jq
5151
check-jq:
5252
which jq || (echo "jq is not installed. Please install jq to continue." && exit 1)
53+
54+
convert-tdom-examples-to-ipynb:
55+
python tools/convert_py_to_ipynb.py
56+
@echo "Converted tdom examples to ipynb format."
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"id": "5b7d23a9",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"\"\"\"Boolean attribute values are reduced during rendering.\"\"\""
11+
]
12+
},
13+
{
14+
"cell_type": "code",
15+
"execution_count": null,
16+
"id": "4e709496",
17+
"metadata": {},
18+
"outputs": [],
19+
"source": [
20+
"from tdom import html"
21+
]
22+
},
23+
{
24+
"cell_type": "code",
25+
"execution_count": null,
26+
"id": "c219302b",
27+
"metadata": {},
28+
"outputs": [],
29+
"source": [
30+
"def main():\n",
31+
" \"\"\"Main entry point.\"\"\"\n",
32+
" result = html(t\"<div editable={True}>Hello World</div>\")\n",
33+
" return result"
34+
]
35+
}
36+
],
37+
"metadata": {
38+
"jupytext": {
39+
"cell_metadata_filter": "-all",
40+
"main_language": "python",
41+
"notebook_metadata_filter": "-all",
42+
"text_representation": {
43+
"extension": ".py",
44+
"format_name": "light"
45+
}
46+
}
47+
},
48+
"nbformat": 4,
49+
"nbformat_minor": 5
50+
}

content/call_function.ipynb

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"id": "fc98fedd",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"\"\"\"Call a function from inside a template expression.\"\"\""
11+
]
12+
},
13+
{
14+
"cell_type": "code",
15+
"execution_count": null,
16+
"id": "c0ad37f0",
17+
"metadata": {},
18+
"outputs": [],
19+
"source": [
20+
"from tdom import html"
21+
]
22+
},
23+
{
24+
"cell_type": "code",
25+
"execution_count": null,
26+
"id": "32f68a0d",
27+
"metadata": {},
28+
"outputs": [],
29+
"source": [
30+
"def make_bigly(name: str) -> str:\n",
31+
" \"\"\"A function returning a string, rather than a component.\"\"\"\n",
32+
" return f\"BIGLY: {name.upper()}\""
33+
]
34+
},
35+
{
36+
"cell_type": "code",
37+
"execution_count": null,
38+
"id": "ace28039",
39+
"metadata": {},
40+
"outputs": [],
41+
"source": [
42+
"def main():\n",
43+
" \"\"\"Main entry point.\"\"\"\n",
44+
" name = \"viewdom\"\n",
45+
" result = html(t\"<div>Hello {make_bigly(name)}</div>\")\n",
46+
" return result"
47+
]
48+
}
49+
],
50+
"metadata": {
51+
"jupytext": {
52+
"cell_metadata_filter": "-all",
53+
"main_language": "python",
54+
"notebook_metadata_filter": "-all",
55+
"text_representation": {
56+
"extension": ".py",
57+
"format_name": "light"
58+
}
59+
}
60+
},
61+
"nbformat": 4,
62+
"nbformat_minor": 5
63+
}

content/child_nodes.ipynb

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"id": "467bc5fe",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"\"\"\"Child nodes become part of the structure.\"\"\"\n",
11+
"from tdom import html"
12+
]
13+
},
14+
{
15+
"cell_type": "code",
16+
"execution_count": null,
17+
"id": "7b4ea151",
18+
"metadata": {},
19+
"outputs": [],
20+
"source": [
21+
"def main():\n",
22+
" \"\"\"Main entry point.\"\"\"\n",
23+
" structure = html(t\"<div>Hello <span>World<em>!</em></span></div>\")\n",
24+
" return structure"
25+
]
26+
}
27+
],
28+
"metadata": {
29+
"jupytext": {
30+
"cell_metadata_filter": "-all",
31+
"main_language": "python",
32+
"notebook_metadata_filter": "-all",
33+
"text_representation": {
34+
"extension": ".py",
35+
"format_name": "light"
36+
}
37+
}
38+
},
39+
"nbformat": 4,
40+
"nbformat_minor": 5
41+
}

content/children_props.ipynb

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"id": "f6a06f24",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"\"\"\"Children as props.\"\"\""
11+
]
12+
},
13+
{
14+
"cell_type": "code",
15+
"execution_count": null,
16+
"id": "40c22133",
17+
"metadata": {},
18+
"outputs": [],
19+
"source": [
20+
"from tdom import html"
21+
]
22+
},
23+
{
24+
"cell_type": "code",
25+
"execution_count": null,
26+
"id": "637d8b0e",
27+
"metadata": {},
28+
"outputs": [],
29+
"source": [
30+
"def Heading(title, children):\n",
31+
" \"\"\"The default heading.\"\"\"\n",
32+
" return html(t\"<h1>{title}</h1><div>{children}</div>\")"
33+
]
34+
},
35+
{
36+
"cell_type": "code",
37+
"execution_count": null,
38+
"id": "f53c087f",
39+
"metadata": {},
40+
"outputs": [],
41+
"source": [
42+
"def main():\n",
43+
" \"\"\"Main entry point.\"\"\"\n",
44+
" result = html(t'<{Heading} title=\"My Title\">Child<//>')\n",
45+
" return result"
46+
]
47+
}
48+
],
49+
"metadata": {
50+
"jupytext": {
51+
"cell_metadata_filter": "-all",
52+
"main_language": "python",
53+
"notebook_metadata_filter": "-all",
54+
"text_representation": {
55+
"extension": ".py",
56+
"format_name": "light"
57+
}
58+
}
59+
},
60+
"nbformat": 4,
61+
"nbformat_minor": 5
62+
}

content/components.ipynb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"id": "9304aabd",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"\"\"\"Examples that show components.\"\"\""
11+
]
12+
}
13+
],
14+
"metadata": {
15+
"jupytext": {
16+
"cell_metadata_filter": "-all",
17+
"main_language": "python",
18+
"notebook_metadata_filter": "-all",
19+
"text_representation": {
20+
"extension": ".py",
21+
"format_name": "light"
22+
}
23+
}
24+
},
25+
"nbformat": 4,
26+
"nbformat_minor": 5
27+
}

content/conditional_default.ipynb

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"id": "5ce4cf10",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"\"\"\"An expression which chooses subcomponent based on condition.\"\"\""
11+
]
12+
},
13+
{
14+
"cell_type": "code",
15+
"execution_count": null,
16+
"id": "d5b8f87c",
17+
"metadata": {},
18+
"outputs": [],
19+
"source": [
20+
"from tdom import html"
21+
]
22+
},
23+
{
24+
"cell_type": "code",
25+
"execution_count": null,
26+
"id": "f24050d3",
27+
"metadata": {},
28+
"outputs": [],
29+
"source": [
30+
"def DefaultHeading():\n",
31+
" \"\"\"The default heading.\"\"\"\n",
32+
" return html(t\"<h1>Default Heading</h1>\")"
33+
]
34+
},
35+
{
36+
"cell_type": "code",
37+
"execution_count": null,
38+
"id": "a0d305b4",
39+
"metadata": {},
40+
"outputs": [],
41+
"source": [
42+
"def OtherHeading():\n",
43+
" \"\"\"Another heading used in another condition.\"\"\"\n",
44+
" return html(t\"<h1>Other Heading</h1>\")"
45+
]
46+
},
47+
{
48+
"cell_type": "code",
49+
"execution_count": null,
50+
"id": "0c146bbd",
51+
"metadata": {},
52+
"outputs": [],
53+
"source": [
54+
"def Body(heading):\n",
55+
" \"\"\"Render the body with a heading based on which is passed in.\"\"\"\n",
56+
" return html(t\"<body>{heading if heading else DefaultHeading}</body>\")"
57+
]
58+
},
59+
{
60+
"cell_type": "code",
61+
"execution_count": null,
62+
"id": "b189a92f",
63+
"metadata": {},
64+
"outputs": [],
65+
"source": [
66+
"def main():\n",
67+
" \"\"\"Main entry point.\"\"\"\n",
68+
" result = html(t\"<{Body} heading={OtherHeading}/>\")\n",
69+
" return result"
70+
]
71+
}
72+
],
73+
"metadata": {
74+
"jupytext": {
75+
"cell_metadata_filter": "-all",
76+
"main_language": "python",
77+
"notebook_metadata_filter": "-all",
78+
"text_representation": {
79+
"extension": ".py",
80+
"format_name": "light"
81+
}
82+
}
83+
},
84+
"nbformat": 4,
85+
"nbformat_minor": 5
86+
}

content/conditionals.ipynb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"id": "5a3719e8",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"\"\"\"Examples that show conditionals.\"\"\""
11+
]
12+
}
13+
],
14+
"metadata": {
15+
"jupytext": {
16+
"cell_metadata_filter": "-all",
17+
"main_language": "python",
18+
"notebook_metadata_filter": "-all",
19+
"text_representation": {
20+
"extension": ".py",
21+
"format_name": "light"
22+
}
23+
}
24+
},
25+
"nbformat": 4,
26+
"nbformat_minor": 5
27+
}

0 commit comments

Comments
 (0)