diff --git a/Makefile b/Makefile index f9755cd..c4cef16 100644 --- a/Makefile +++ b/Makefile @@ -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." \ No newline at end of file diff --git a/content/boolean_attribute_value.ipynb b/content/boolean_attribute_value.ipynb new file mode 100644 index 0000000..0895d17 --- /dev/null +++ b/content/boolean_attribute_value.ipynb @@ -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\"
Hello World
\")\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 +} diff --git a/content/call_function.ipynb b/content/call_function.ipynb new file mode 100644 index 0000000..fb0d0eb --- /dev/null +++ b/content/call_function.ipynb @@ -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\"
Hello {make_bigly(name)}
\")\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 +} diff --git a/content/child_nodes.ipynb b/content/child_nodes.ipynb new file mode 100644 index 0000000..b2b74df --- /dev/null +++ b/content/child_nodes.ipynb @@ -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\"
Hello World!
\")\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 +} diff --git a/content/children_props.ipynb b/content/children_props.ipynb new file mode 100644 index 0000000..409e3e3 --- /dev/null +++ b/content/children_props.ipynb @@ -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\"

{title}

{children}
\")" + ] + }, + { + "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 +} diff --git a/content/components.ipynb b/content/components.ipynb new file mode 100644 index 0000000..c40976d --- /dev/null +++ b/content/components.ipynb @@ -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 +} diff --git a/content/conditional_default.ipynb b/content/conditional_default.ipynb new file mode 100644 index 0000000..db425d4 --- /dev/null +++ b/content/conditional_default.ipynb @@ -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\"

Default Heading

\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a0d305b4", + "metadata": {}, + "outputs": [], + "source": [ + "def OtherHeading():\n", + " \"\"\"Another heading used in another condition.\"\"\"\n", + " return html(t\"

Other Heading

\")" + ] + }, + { + "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\"{heading if heading else DefaultHeading}\")" + ] + }, + { + "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 +} diff --git a/content/conditionals.ipynb b/content/conditionals.ipynb new file mode 100644 index 0000000..3b0ae95 --- /dev/null +++ b/content/conditionals.ipynb @@ -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 +} diff --git a/content/dataclass_component.ipynb b/content/dataclass_component.ipynb new file mode 100644 index 0000000..830a43a --- /dev/null +++ b/content/dataclass_component.ipynb @@ -0,0 +1,80 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "71119db6", + "metadata": {}, + "outputs": [], + "source": [ + "\"\"\"Components can be any kind of dataclass_component.\"\"\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "382210dc", + "metadata": {}, + "outputs": [], + "source": [ + "from dataclasses import dataclass" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "28ee3d40", + "metadata": {}, + "outputs": [], + "source": [ + "from tdom import html" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6c6933f0", + "metadata": {}, + "outputs": [], + "source": [ + "@dataclass\n", + "class Greeting:\n", + " \"\"\"Give a greeting.\"\"\"\n", + "\n", + " name: str\n", + "\n", + " def __call__(self):\n", + " \"\"\"Render to a string.\"\"\"\n", + " return f\"Hello {self.name}\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f654950b", + "metadata": {}, + "outputs": [], + "source": [ + "def main():\n", + " \"\"\"Render a template to a string.\"\"\"\n", + " greeting = Greeting(name=\"viewdom\")\n", + " # TODO Teach the constructor to make dataclass components\n", + " result = html(t\"
<{greeting} />
\")\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 +} diff --git a/content/default_component.ipynb b/content/default_component.ipynb new file mode 100644 index 0000000..94c9a15 --- /dev/null +++ b/content/default_component.ipynb @@ -0,0 +1,86 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "56d2b568", + "metadata": {}, + "outputs": [], + "source": [ + "\"\"\"Overriding a default \"built-in\" component.\"\"\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "192a7356", + "metadata": {}, + "outputs": [], + "source": [ + "from tdom import html" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a98f8299", + "metadata": {}, + "outputs": [], + "source": [ + "def DefaultHeading(): # pragma: nocover\n", + " \"\"\"The default heading.\"\"\"\n", + " return html(t\"

Default Heading

\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "29f36c13", + "metadata": {}, + "outputs": [], + "source": [ + "def OtherHeading():\n", + " \"\"\"Another heading used in another condition.\"\"\"\n", + " return html(t\"

Other Heading

\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "161562db", + "metadata": {}, + "outputs": [], + "source": [ + "def Body(heading):\n", + " \"\"\"Render the body with a heading based on which is passed in.\"\"\"\n", + " return html(t\"<{heading} />\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8e71f8d2", + "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 +} diff --git a/content/default_value.ipynb b/content/default_value.ipynb new file mode 100644 index 0000000..800fa30 --- /dev/null +++ b/content/default_value.ipynb @@ -0,0 +1,62 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "19fd9766", + "metadata": {}, + "outputs": [], + "source": [ + "\"\"\"The prop has a default value, so caller doesn't have to provide it.\"\"\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "886be312", + "metadata": {}, + "outputs": [], + "source": [ + "from tdom import html" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a66f3040", + "metadata": {}, + "outputs": [], + "source": [ + "def Hello(name=\"viewdom\"):\n", + " \"\"\"A simple hello component.\"\"\"\n", + " return html(t\"
Hello {name}
\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "afc510aa", + "metadata": {}, + "outputs": [], + "source": [ + "def main():\n", + " \"\"\"Main entry point.\"\"\"\n", + " result = Hello()\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 +} diff --git a/content/examples.ipynb b/content/examples.ipynb new file mode 100644 index 0000000..a623565 --- /dev/null +++ b/content/examples.ipynb @@ -0,0 +1,27 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "24b07721", + "metadata": {}, + "outputs": [], + "source": [ + "\"\"\"Examples that serve as documentation and tests.\"\"\"" + ] + } + ], + "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 +} diff --git a/content/expression_props.ipynb b/content/expression_props.ipynb new file mode 100644 index 0000000..5b6bd7c --- /dev/null +++ b/content/expression_props.ipynb @@ -0,0 +1,62 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "a40d8058", + "metadata": {}, + "outputs": [], + "source": [ + "\"\"\"Pass a Python symbol as part of an expression.\"\"\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "abfcf1b2", + "metadata": {}, + "outputs": [], + "source": [ + "from tdom import html" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2fe946ef", + "metadata": {}, + "outputs": [], + "source": [ + "def Heading(title):\n", + " \"\"\"The default heading.\"\"\"\n", + " return html(t\"

{title}

\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "38787b67", + "metadata": {}, + "outputs": [], + "source": [ + "def main():\n", + " \"\"\"Main entry point.\"\"\"\n", + " result = html(t'<{Heading} title={\"My Title\"} />')\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 +} diff --git a/content/expressions.ipynb b/content/expressions.ipynb new file mode 100644 index 0000000..0444e86 --- /dev/null +++ b/content/expressions.ipynb @@ -0,0 +1,27 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "17d48718", + "metadata": {}, + "outputs": [], + "source": [ + "\"\"\"Examples that show expressions.\"\"\"" + ] + } + ], + "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 +} diff --git a/content/expressions_as_values.ipynb b/content/expressions_as_values.ipynb new file mode 100644 index 0000000..5602139 --- /dev/null +++ b/content/expressions_as_values.ipynb @@ -0,0 +1,50 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "b2b5e6f0", + "metadata": {}, + "outputs": [], + "source": [ + "\"\"\"Use a nested f-string to communicate a dynamic attribute value.\"\"\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "908949fe", + "metadata": {}, + "outputs": [], + "source": [ + "from tdom import html" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "76d55172", + "metadata": {}, + "outputs": [], + "source": [ + "def main():\n", + " \"\"\"Main entry point.\"\"\"\n", + " result = html(t'
Hello World
')\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 +} diff --git a/content/generators.ipynb b/content/generators.ipynb new file mode 100644 index 0000000..77eca43 --- /dev/null +++ b/content/generators.ipynb @@ -0,0 +1,64 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "7ce2a334", + "metadata": {}, + "outputs": [], + "source": [ + "\"\"\"Generators as components.\"\"\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "47bc41da", + "metadata": {}, + "outputs": [], + "source": [ + "from tdom import html" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "13a94b39", + "metadata": {}, + "outputs": [], + "source": [ + "def Todos():\n", + " \"\"\"A sequence of li items.\"\"\"\n", + " for todo in [\"First\", \"Second\"]: # noqa B007\n", + " # TODO Andrea need to add generator support\n", + " yield html(t\"
  • {todo}
  • \")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9302490a", + "metadata": {}, + "outputs": [], + "source": [ + "def main():\n", + " \"\"\"Main entry point.\"\"\"\n", + " result = html(t\"\")\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 +} diff --git a/content/insert_value.ipynb b/content/insert_value.ipynb new file mode 100644 index 0000000..bd69d79 --- /dev/null +++ b/content/insert_value.ipynb @@ -0,0 +1,51 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "67019110", + "metadata": {}, + "outputs": [], + "source": [ + "\"\"\"Simple example of inserting a variable value into a template.\"\"\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "837e4357", + "metadata": {}, + "outputs": [], + "source": [ + "from tdom import html" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5095d0ae", + "metadata": {}, + "outputs": [], + "source": [ + "def main():\n", + " \"\"\"Main entry point.\"\"\"\n", + " name = \"viewdom\"\n", + " result = html(t\"
    Hello {name}
    \")\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 +} diff --git a/content/looping.ipynb b/content/looping.ipynb new file mode 100644 index 0000000..c1905a7 --- /dev/null +++ b/content/looping.ipynb @@ -0,0 +1,27 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "9278e4bc", + "metadata": {}, + "outputs": [], + "source": [ + "\"\"\"Examples that show looping.\"\"\"" + ] + } + ], + "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 +} diff --git a/content/notebooks.json b/content/notebooks.json new file mode 100644 index 0000000..3f51f03 --- /dev/null +++ b/content/notebooks.json @@ -0,0 +1 @@ +["boolean_attribute_value", "call_function", "child_nodes", "children_props", "components", "conditional_default", "conditionals", "dataclass_component", "default_component", "default_value", "examples", "expression_props", "expressions", "expressions_as_values", "generators", "insert_value", "looping", "optional_props", "pass_component", "passed_in_prop", "python_operation", "rendered_looping", "scope_values", "shorthand_syntax", "show_vdom", "simple_arithmetic", "simple_heading", "simple_looping", "simple_props", "simple_render", "static_string", "string_literal", "subcomponents", "syntax", "value_from_import", "variables"] \ No newline at end of file diff --git a/content/optional_props.ipynb b/content/optional_props.ipynb new file mode 100644 index 0000000..c137364 --- /dev/null +++ b/content/optional_props.ipynb @@ -0,0 +1,54 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "cee9717b", + "metadata": {}, + "outputs": [], + "source": [ + "\"\"\"Optional props.\"\"\"\n", + "from tdom import html" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9b254628", + "metadata": {}, + "outputs": [], + "source": [ + "def Heading(title=\"My Title\"):\n", + " \"\"\"The default heading.\"\"\"\n", + "\n", + " return html(t\"

    {title}

    \")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c30831d0", + "metadata": {}, + "outputs": [], + "source": [ + "def main():\n", + " \"\"\"Main entry point.\"\"\"\n", + " result = html(t\"<{Heading} />\")\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 +} diff --git a/content/pass_component.ipynb b/content/pass_component.ipynb new file mode 100644 index 0000000..c3f924d --- /dev/null +++ b/content/pass_component.ipynb @@ -0,0 +1,74 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "c0cb9eae", + "metadata": {}, + "outputs": [], + "source": [ + "\"\"\"Pass a component as a prop value.\"\"\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7e4cbaea", + "metadata": {}, + "outputs": [], + "source": [ + "from tdom import html" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4eb1bc30", + "metadata": {}, + "outputs": [], + "source": [ + "def DefaultHeading():\n", + " \"\"\"The default heading.\"\"\"\n", + " return html(t\"

    Default Heading

    \")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "eb94e8c5", + "metadata": {}, + "outputs": [], + "source": [ + "def Body(heading):\n", + " \"\"\"The body which renders the heading.\"\"\"\n", + " return html(t\"<{heading} />\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "cc8e951b", + "metadata": {}, + "outputs": [], + "source": [ + "def main():\n", + " \"\"\"Main entry point.\"\"\"\n", + " result = html(t\"<{Body} heading={DefaultHeading} />\")\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 +} diff --git a/content/passed_in_prop.ipynb b/content/passed_in_prop.ipynb new file mode 100644 index 0000000..d8aa2b2 --- /dev/null +++ b/content/passed_in_prop.ipynb @@ -0,0 +1,62 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "53473af2", + "metadata": {}, + "outputs": [], + "source": [ + "\"\"\"Get a variable from a passed-in ``prop``.\"\"\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "82a6e226", + "metadata": {}, + "outputs": [], + "source": [ + "from tdom import html" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e9e140a2", + "metadata": {}, + "outputs": [], + "source": [ + "def Hello(name):\n", + " \"\"\"A simple hello component.\"\"\"\n", + " return html(t\"
    Hello {name}
    \")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "aa135554", + "metadata": {}, + "outputs": [], + "source": [ + "def main():\n", + " \"\"\"Main entry point.\"\"\"\n", + " result = Hello(name=\"viewdom\")\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 +} diff --git a/content/python_operation.ipynb b/content/python_operation.ipynb new file mode 100644 index 0000000..4be0a5a --- /dev/null +++ b/content/python_operation.ipynb @@ -0,0 +1,51 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "ccceff2f", + "metadata": {}, + "outputs": [], + "source": [ + "\"\"\"Python operation in the expression.\"\"\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8c05b64c", + "metadata": {}, + "outputs": [], + "source": [ + "from tdom import html" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2ab18fa7", + "metadata": {}, + "outputs": [], + "source": [ + "def main():\n", + " \"\"\"Main entry point.\"\"\"\n", + " name = \"viewdom\"\n", + " result = html(t\"
    Hello {name.upper()}
    \")\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 +} diff --git a/content/rendered_looping.ipynb b/content/rendered_looping.ipynb new file mode 100644 index 0000000..6c2a9dc --- /dev/null +++ b/content/rendered_looping.ipynb @@ -0,0 +1,59 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "1e9106fd", + "metadata": {}, + "outputs": [], + "source": [ + "\"\"\"Generate a list of VDOMs then use in a render.\"\"\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "561ae11e", + "metadata": {}, + "outputs": [], + "source": [ + "from tdom import html" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1d82901d", + "metadata": {}, + "outputs": [], + "source": [ + "def main():\n", + " \"\"\"Main entry point.\"\"\"\n", + " message = \"Hello\"\n", + " names = [\"World\", \"Universe\"]\n", + " items = [html(t\"
  • {label}
  • \") for label in names]\n", + " result = html(\n", + " t\"\"\"\n", + " \n", + " \"\"\"\n", + " )\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 +} diff --git a/content/scope_values.ipynb b/content/scope_values.ipynb new file mode 100644 index 0000000..3461fb8 --- /dev/null +++ b/content/scope_values.ipynb @@ -0,0 +1,64 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "9dc8f8ff", + "metadata": {}, + "outputs": [], + "source": [ + "\"\"\"Prop values from scope variables.\"\"\"\n", + "from tdom import html" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9ddb542c", + "metadata": {}, + "outputs": [], + "source": [ + "def Heading(title):\n", + " \"\"\"The default heading.\"\"\"\n", + "\n", + " return html(t\"

    {title}

    \")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "81785b05", + "metadata": {}, + "outputs": [], + "source": [ + "this_title = \"My Title\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "90f6b34a", + "metadata": {}, + "outputs": [], + "source": [ + "def main():\n", + " \"\"\"Main entry point.\"\"\"\n", + " result = html(t\"<{Heading} title={this_title} />\")\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 +} diff --git a/content/shorthand_syntax.ipynb b/content/shorthand_syntax.ipynb new file mode 100644 index 0000000..0683af7 --- /dev/null +++ b/content/shorthand_syntax.ipynb @@ -0,0 +1,50 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "c4f86e99", + "metadata": {}, + "outputs": [], + "source": [ + "\"\"\"Shorthand syntax for attribute values means no need for double quotes.\"\"\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e961754f", + "metadata": {}, + "outputs": [], + "source": [ + "from tdom import html" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7392958e", + "metadata": {}, + "outputs": [], + "source": [ + "def main():\n", + " \"\"\"Main entry point.\"\"\"\n", + " result = html(t'
    Hello World
    ')\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 +} diff --git a/content/show_vdom.ipynb b/content/show_vdom.ipynb new file mode 100644 index 0000000..2076bf0 --- /dev/null +++ b/content/show_vdom.ipynb @@ -0,0 +1,41 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "c2851d88", + "metadata": {}, + "outputs": [], + "source": [ + "\"\"\"Show the VDOM itself.\"\"\"\n", + "from tdom import html" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6beeace9", + "metadata": {}, + "outputs": [], + "source": [ + "def main():\n", + " \"\"\"Main entry point.\"\"\"\n", + " result = html(t'
    Hello World
    ')\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 +} diff --git a/content/simple_arithmetic.ipynb b/content/simple_arithmetic.ipynb new file mode 100644 index 0000000..3408cca --- /dev/null +++ b/content/simple_arithmetic.ipynb @@ -0,0 +1,51 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "fb3ad238", + "metadata": {}, + "outputs": [], + "source": [ + "\"\"\"Simple arithmetic expression in a template.\"\"\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "913a24e8", + "metadata": {}, + "outputs": [], + "source": [ + "from tdom import html" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0d38b355", + "metadata": {}, + "outputs": [], + "source": [ + "def main():\n", + " \"\"\"Main entry point.\"\"\"\n", + " name = \"viewdom\"\n", + " result = html(t\"
    Hello {1 + 3}
    \")\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 +} diff --git a/content/simple_heading.ipynb b/content/simple_heading.ipynb new file mode 100644 index 0000000..c483a26 --- /dev/null +++ b/content/simple_heading.ipynb @@ -0,0 +1,53 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "4b3cb7bf", + "metadata": {}, + "outputs": [], + "source": [ + "\"\"\"Simple function component, nothing dynamic, that returns a VDOM.\"\"\"\n", + "from tdom import html" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4d4c2870", + "metadata": {}, + "outputs": [], + "source": [ + "def Heading():\n", + " \"\"\"The default heading.\"\"\"\n", + " return html(t\"

    My Title

    \")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "56324984", + "metadata": {}, + "outputs": [], + "source": [ + "def main():\n", + " \"\"\"Main entry point.\"\"\"\n", + " result = html(t\"<{Heading} />\")\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 +} diff --git a/content/simple_looping.ipynb b/content/simple_looping.ipynb new file mode 100644 index 0000000..9789b00 --- /dev/null +++ b/content/simple_looping.ipynb @@ -0,0 +1,61 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "49ed5029", + "metadata": {}, + "outputs": [], + "source": [ + "\"\"\"Loop through values in a template and render them in a nested template.\"\"\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "dbccb589", + "metadata": {}, + "outputs": [], + "source": [ + "from tdom import html" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4dfe6005", + "metadata": {}, + "outputs": [], + "source": [ + "def main():\n", + " \"\"\"Main entry point.\"\"\"\n", + " message = \"Hello\"\n", + " names = [\"World\", \"Universe\"]\n", + " result = html(\n", + " t\"\"\"\n", + " \n", + " \"\"\"\n", + " )\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 +} diff --git a/content/simple_props.ipynb b/content/simple_props.ipynb new file mode 100644 index 0000000..12171ed --- /dev/null +++ b/content/simple_props.ipynb @@ -0,0 +1,62 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "4df44cc8", + "metadata": {}, + "outputs": [], + "source": [ + "\"\"\"Use ``children`` as a built-in \"prop\".\"\"\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "eb6c65f0", + "metadata": {}, + "outputs": [], + "source": [ + "from tdom import html" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9e8bfa50", + "metadata": {}, + "outputs": [], + "source": [ + "def Heading(title):\n", + " \"\"\"Default heading.\"\"\"\n", + " return html(t\"

    {title}

    \")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "51c93a8c", + "metadata": {}, + "outputs": [], + "source": [ + "def main():\n", + " \"\"\"Main entry point.\"\"\"\n", + " result = html(t'<{Heading} title=\"My Title\" />')\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 +} diff --git a/content/simple_render.ipynb b/content/simple_render.ipynb new file mode 100644 index 0000000..d372e62 --- /dev/null +++ b/content/simple_render.ipynb @@ -0,0 +1,50 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "fe879e65", + "metadata": {}, + "outputs": [], + "source": [ + "\"\"\"Render a string wrapped by a div.\"\"\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f3335088", + "metadata": {}, + "outputs": [], + "source": [ + "from tdom import html" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c1eaec0b", + "metadata": {}, + "outputs": [], + "source": [ + "def main():\n", + " \"\"\"Main entry point.\"\"\"\n", + " result = html(t\"
    Hello World
    \")\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 +} diff --git a/content/static_string.ipynb b/content/static_string.ipynb new file mode 100644 index 0000000..d968247 --- /dev/null +++ b/content/static_string.ipynb @@ -0,0 +1,27 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "e7487082", + "metadata": {}, + "outputs": [], + "source": [ + "\"\"\"Examples that show static strings.\"\"\"" + ] + } + ], + "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 +} diff --git a/content/string_literal.ipynb b/content/string_literal.ipynb new file mode 100644 index 0000000..c667f4b --- /dev/null +++ b/content/string_literal.ipynb @@ -0,0 +1,50 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "b1ae5d47", + "metadata": {}, + "outputs": [], + "source": [ + "\"\"\"Render just a string literal.\"\"\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "899a3647", + "metadata": {}, + "outputs": [], + "source": [ + "from tdom import html" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "16f67740", + "metadata": {}, + "outputs": [], + "source": [ + "def main():\n", + " \"\"\"Main entry point.\"\"\"\n", + " result = html(t\"Hello World\")\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 +} diff --git a/content/subcomponents.ipynb b/content/subcomponents.ipynb new file mode 100644 index 0000000..65987b9 --- /dev/null +++ b/content/subcomponents.ipynb @@ -0,0 +1,90 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "f4a5b8e2", + "metadata": {}, + "outputs": [], + "source": [ + "\"\"\"Subcomponents.\"\"\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f26b5438", + "metadata": {}, + "outputs": [], + "source": [ + "from tdom import html" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6c1cecb8", + "metadata": {}, + "outputs": [], + "source": [ + "title = \"My Todos\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "31890981", + "metadata": {}, + "outputs": [], + "source": [ + "def Todo(label):\n", + " \"\"\"An individual to do component.\"\"\"\n", + " return html(t\"
  • {label}
  • \")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a447db6f", + "metadata": {}, + "outputs": [], + "source": [ + "def TodoList(todos):\n", + " \"\"\"A to do list component.\"\"\"\n", + " # Pass an argument, not the normal props style\n", + " return html(t\"\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8fb6ef64", + "metadata": {}, + "outputs": [], + "source": [ + "def main():\n", + " \"\"\"Main entry point.\"\"\"\n", + " todos = [\"first\"]\n", + " return html(\n", + " t\"\"\"\n", + "

    {title}

    \n", + " <{TodoList} todos={todos} />\n", + " \"\"\"\n", + " )" + ] + } + ], + "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 +} diff --git a/content/syntax.ipynb b/content/syntax.ipynb new file mode 100644 index 0000000..829f305 --- /dev/null +++ b/content/syntax.ipynb @@ -0,0 +1,58 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "021c98af", + "metadata": {}, + "outputs": [], + "source": [ + "\"\"\"Use normal Python syntax for conditional rendering in a template.\"\"\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "65681b94", + "metadata": {}, + "outputs": [], + "source": [ + "from tdom import html" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6c9597c9", + "metadata": {}, + "outputs": [], + "source": [ + "def main():\n", + " \"\"\"Main entry point.\"\"\"\n", + " message = \"Say Howdy\"\n", + " not_message = \"So Sad\"\n", + " show_message = True\n", + " result = html(\n", + " t\"\"\"\n", + "

    Show?

    \n", + " {message if show_message else not_message}\n", + " \"\"\"\n", + " )\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 +} diff --git a/content/value_from_import.ipynb b/content/value_from_import.ipynb new file mode 100644 index 0000000..3d69589 --- /dev/null +++ b/content/value_from_import.ipynb @@ -0,0 +1,63 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "29f6b333", + "metadata": {}, + "outputs": [], + "source": [ + "\"\"\"Get a variable from an import.\"\"\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d5866c9e", + "metadata": {}, + "outputs": [], + "source": [ + "from .. import name # noqa F401\n", + "from tdom import html" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5b39e9be", + "metadata": {}, + "outputs": [], + "source": [ + "def Hello():\n", + " \"\"\"A simple hello component.\"\"\"\n", + " return html(t\"
    Hello {name}
    \")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "bda92319", + "metadata": {}, + "outputs": [], + "source": [ + "def main():\n", + " \"\"\"Main entry point.\"\"\"\n", + " result = Hello()\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 +} diff --git a/content/variables.ipynb b/content/variables.ipynb new file mode 100644 index 0000000..3e08a84 --- /dev/null +++ b/content/variables.ipynb @@ -0,0 +1,37 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "c647fe48", + "metadata": {}, + "outputs": [], + "source": [ + "\"\"\"Examples that show variables.\"\"\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f24f5def", + "metadata": {}, + "outputs": [], + "source": [ + "name = \"viewdom\"" + ] + } + ], + "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 +} diff --git a/public/playground.html b/public/playground.html index 14cd54c..0fec937 100644 --- a/public/playground.html +++ b/public/playground.html @@ -1,101 +1,125 @@ - - - + + + t-strings: coming soon to a Python near you - + - - -
    -
    + + +
    +
    +

    - T-strings playground! + T-strings playground!

    -

    - Let's try t-strings now!! -

    - -
    + + + +
    - +
    + + + diff --git a/pyproject.toml b/pyproject.toml index 05bddf6..af42824 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,8 @@ description = "The https://t-strings.help/ website" readme = "README.md" requires-python = ">=3.13" dependencies = [ -# "sphinx>=8.2.3", + # "sphinx>=8.2.3", "jupyterlite-core[all]>=0.6.0b0", "jupyterlite-pyodide-kernel>=0.6.0b1", + "jupytext>=1.17.1", ] diff --git a/tools/convert_py_to_ipynb.py b/tools/convert_py_to_ipynb.py new file mode 100644 index 0000000..9822fc5 --- /dev/null +++ b/tools/convert_py_to_ipynb.py @@ -0,0 +1,18 @@ +import json +from pathlib import Path +import jupytext, nbformat as nbf + +ROOT = Path(__file__).parent.parent +TDOM = ROOT.parent / "tdom" +OUT = ROOT / "content" +OUT.mkdir(parents=True, exist_ok=True) + +notebooks = [] + +for init_py in TDOM.joinpath("examples").rglob("__init__.py"): + name = init_py.parent.name # e.g. call_function + ipynb = OUT / f"{name}.ipynb" + nbf.write(jupytext.read(init_py), ipynb) + notebooks.append(name) # just the bare name + +(OUT / "notebooks.json").write_text(json.dumps(sorted(notebooks))) diff --git a/uv.lock b/uv.lock index ea56360..eb01aa1 100644 --- a/uv.lock +++ b/uv.lock @@ -306,12 +306,14 @@ source = { virtual = "." } dependencies = [ { name = "jupyterlite-core", extra = ["all"] }, { name = "jupyterlite-pyodide-kernel" }, + { name = "jupytext" }, ] [package.metadata] requires-dist = [ { name = "jupyterlite-core", extras = ["all"], specifier = ">=0.6.0b0" }, { name = "jupyterlite-pyodide-kernel", specifier = ">=0.6.0b1" }, + { name = "jupytext", specifier = ">=1.17.1" }, ] [[package]] @@ -706,6 +708,22 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/55/36/b874e43c6e8cd1fc228bb024e5544b26fc3f52aab3f41286a8371e62ee99/jupyterlite_pyodide_kernel-0.6.0b1-py3-none-any.whl", hash = "sha256:d13b1342ffef08edf5484b98e7be0c826e4b8ba8669e8278219940bf48f3f432", size = 904176 }, ] +[[package]] +name = "jupytext" +version = "1.17.1" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "markdown-it-py" }, + { name = "mdit-py-plugins" }, + { name = "nbformat" }, + { name = "packaging" }, + { name = "pyyaml" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/6e/d9/b7acd3bed66c194cec1915c5bbec30994dbb50693ec209e5b115c28ddf63/jupytext-1.17.1.tar.gz", hash = "sha256:c02fda8af76ffd6e064a04cf2d3cc8aae242b2f0e38c42b4cd80baf89c3325d3", size = 3746897 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/12/b7/e7e3d34c8095c19228874b1babedfb5d901374e40d51ae66f2a90203be53/jupytext-1.17.1-py3-none-any.whl", hash = "sha256:99145b1e1fa96520c21ba157de7d354ffa4904724dcebdcd70b8413688a312de", size = 164286 }, +] + [[package]] name = "libarchive-c" version = "5.2" @@ -715,6 +733,18 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/89/ef/b21525339880eda2ee8e9018b7c5f74e1856e5bde257dde54b9e2274b323/libarchive_c-5.2-py3-none-any.whl", hash = "sha256:9e6dfae09c9c47cd9348410967af547efe80dc619e2066f20941b57296f0435a", size = 15690 }, ] +[[package]] +name = "markdown-it-py" +version = "3.0.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "mdurl" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/38/71/3b932df36c1a044d397a1f92d1cf91ee0a503d91e470cbd670aa66b07ed0/markdown-it-py-3.0.0.tar.gz", hash = "sha256:e3f60a94fa066dc52ec76661e37c851cb232d92f9886b15cb560aaada2df8feb", size = 74596 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/42/d7/1ec15b46af6af88f19b8e5ffea08fa375d433c998b8a7639e76935c14f1f/markdown_it_py-3.0.0-py3-none-any.whl", hash = "sha256:355216845c60bd96232cd8d8c40e8f9765cc86f46880e43a8fd22dc1a1a8cab1", size = 87528 }, +] + [[package]] name = "markupsafe" version = "3.0.2" @@ -755,6 +785,27 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/8f/8e/9ad090d3553c280a8060fbf6e24dc1c0c29704ee7d1c372f0c174aa59285/matplotlib_inline-0.1.7-py3-none-any.whl", hash = "sha256:df192d39a4ff8f21b1895d72e6a13f5fcc5099f00fa84384e0ea28c2cc0653ca", size = 9899 }, ] +[[package]] +name = "mdit-py-plugins" +version = "0.4.2" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "markdown-it-py" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/19/03/a2ecab526543b152300717cf232bb4bb8605b6edb946c845016fa9c9c9fd/mdit_py_plugins-0.4.2.tar.gz", hash = "sha256:5f2cd1fdb606ddf152d37ec30e46101a60512bc0e5fa1a7002c36647b09e26b5", size = 43542 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/a7/f7/7782a043553ee469c1ff49cfa1cdace2d6bf99a1f333cf38676b3ddf30da/mdit_py_plugins-0.4.2-py3-none-any.whl", hash = "sha256:0c673c3f889399a33b95e88d2f0d111b4447bdfea7f237dab2d488f459835636", size = 55316 }, +] + +[[package]] +name = "mdurl" +version = "0.1.2" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/d6/54/cfe61301667036ec958cb99bd3efefba235e65cdeb9c84d24a8293ba1d90/mdurl-0.1.2.tar.gz", hash = "sha256:bb413d29f5eea38f31dd4754dd7377d4465116fb207585f97bf925588687c1ba", size = 8729 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/b3/38/89ba8ad64ae25be8de66a6d463314cf1eb366222074cfda9ee839c56a4b4/mdurl-0.1.2-py3-none-any.whl", hash = "sha256:84008a41e51615a49fc9966191ff91509e3c40b939176e643fd50a5c2196b8f8", size = 9979 }, +] + [[package]] name = "mistune" version = "3.1.3"