Skip to content
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
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,7 @@ clean-playground:
.PHONY: check-jq
check-jq:
which jq || (echo "jq is not installed. Please install jq to continue." && exit 1)

convert-tdom-examples-to-ipynb:
python tools/convert_py_to_ipynb.py
@echo "Converted tdom examples to ipynb format."
50 changes: 50 additions & 0 deletions content/boolean_attribute_value.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "5b7d23a9",
"metadata": {},
"outputs": [],
"source": [
"\"\"\"Boolean attribute values are reduced during rendering.\"\"\""
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4e709496",
"metadata": {},
"outputs": [],
"source": [
"from tdom import html"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c219302b",
"metadata": {},
"outputs": [],
"source": [
"def main():\n",
" \"\"\"Main entry point.\"\"\"\n",
" result = html(t\"<div editable={True}>Hello World</div>\")\n",
" return result"
]
}
],
"metadata": {
"jupytext": {
"cell_metadata_filter": "-all",
"main_language": "python",
"notebook_metadata_filter": "-all",
"text_representation": {
"extension": ".py",
"format_name": "light"
}
}
},
"nbformat": 4,
"nbformat_minor": 5
}
63 changes: 63 additions & 0 deletions content/call_function.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "fc98fedd",
"metadata": {},
"outputs": [],
"source": [
"\"\"\"Call a function from inside a template expression.\"\"\""
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c0ad37f0",
"metadata": {},
"outputs": [],
"source": [
"from tdom import html"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "32f68a0d",
"metadata": {},
"outputs": [],
"source": [
"def make_bigly(name: str) -> str:\n",
" \"\"\"A function returning a string, rather than a component.\"\"\"\n",
" return f\"BIGLY: {name.upper()}\""
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ace28039",
"metadata": {},
"outputs": [],
"source": [
"def main():\n",
" \"\"\"Main entry point.\"\"\"\n",
" name = \"viewdom\"\n",
" result = html(t\"<div>Hello {make_bigly(name)}</div>\")\n",
" return result"
]
}
],
"metadata": {
"jupytext": {
"cell_metadata_filter": "-all",
"main_language": "python",
"notebook_metadata_filter": "-all",
"text_representation": {
"extension": ".py",
"format_name": "light"
}
}
},
"nbformat": 4,
"nbformat_minor": 5
}
41 changes: 41 additions & 0 deletions content/child_nodes.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "467bc5fe",
"metadata": {},
"outputs": [],
"source": [
"\"\"\"Child nodes become part of the structure.\"\"\"\n",
"from tdom import html"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7b4ea151",
"metadata": {},
"outputs": [],
"source": [
"def main():\n",
" \"\"\"Main entry point.\"\"\"\n",
" structure = html(t\"<div>Hello <span>World<em>!</em></span></div>\")\n",
" return structure"
]
}
],
"metadata": {
"jupytext": {
"cell_metadata_filter": "-all",
"main_language": "python",
"notebook_metadata_filter": "-all",
"text_representation": {
"extension": ".py",
"format_name": "light"
}
}
},
"nbformat": 4,
"nbformat_minor": 5
}
62 changes: 62 additions & 0 deletions content/children_props.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "f6a06f24",
"metadata": {},
"outputs": [],
"source": [
"\"\"\"Children as props.\"\"\""
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "40c22133",
"metadata": {},
"outputs": [],
"source": [
"from tdom import html"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "637d8b0e",
"metadata": {},
"outputs": [],
"source": [
"def Heading(title, children):\n",
" \"\"\"The default heading.\"\"\"\n",
" return html(t\"<h1>{title}</h1><div>{children}</div>\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f53c087f",
"metadata": {},
"outputs": [],
"source": [
"def main():\n",
" \"\"\"Main entry point.\"\"\"\n",
" result = html(t'<{Heading} title=\"My Title\">Child<//>')\n",
" return result"
]
}
],
"metadata": {
"jupytext": {
"cell_metadata_filter": "-all",
"main_language": "python",
"notebook_metadata_filter": "-all",
"text_representation": {
"extension": ".py",
"format_name": "light"
}
}
},
"nbformat": 4,
"nbformat_minor": 5
}
27 changes: 27 additions & 0 deletions content/components.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "9304aabd",
"metadata": {},
"outputs": [],
"source": [
"\"\"\"Examples that show components.\"\"\""
]
}
],
"metadata": {
"jupytext": {
"cell_metadata_filter": "-all",
"main_language": "python",
"notebook_metadata_filter": "-all",
"text_representation": {
"extension": ".py",
"format_name": "light"
}
}
},
"nbformat": 4,
"nbformat_minor": 5
}
86 changes: 86 additions & 0 deletions content/conditional_default.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "5ce4cf10",
"metadata": {},
"outputs": [],
"source": [
"\"\"\"An expression which chooses subcomponent based on condition.\"\"\""
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d5b8f87c",
"metadata": {},
"outputs": [],
"source": [
"from tdom import html"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f24050d3",
"metadata": {},
"outputs": [],
"source": [
"def DefaultHeading():\n",
" \"\"\"The default heading.\"\"\"\n",
" return html(t\"<h1>Default Heading</h1>\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a0d305b4",
"metadata": {},
"outputs": [],
"source": [
"def OtherHeading():\n",
" \"\"\"Another heading used in another condition.\"\"\"\n",
" return html(t\"<h1>Other Heading</h1>\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0c146bbd",
"metadata": {},
"outputs": [],
"source": [
"def Body(heading):\n",
" \"\"\"Render the body with a heading based on which is passed in.\"\"\"\n",
" return html(t\"<body>{heading if heading else DefaultHeading}</body>\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b189a92f",
"metadata": {},
"outputs": [],
"source": [
"def main():\n",
" \"\"\"Main entry point.\"\"\"\n",
" result = html(t\"<{Body} heading={OtherHeading}/>\")\n",
" return result"
]
}
],
"metadata": {
"jupytext": {
"cell_metadata_filter": "-all",
"main_language": "python",
"notebook_metadata_filter": "-all",
"text_representation": {
"extension": ".py",
"format_name": "light"
}
}
},
"nbformat": 4,
"nbformat_minor": 5
}
27 changes: 27 additions & 0 deletions content/conditionals.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "5a3719e8",
"metadata": {},
"outputs": [],
"source": [
"\"\"\"Examples that show conditionals.\"\"\""
]
}
],
"metadata": {
"jupytext": {
"cell_metadata_filter": "-all",
"main_language": "python",
"notebook_metadata_filter": "-all",
"text_representation": {
"extension": ".py",
"format_name": "light"
}
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading