|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": null, |
| 6 | + "id": "e46ec9e8", |
| 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": "d4bc6a1f", |
| 17 | + "metadata": {}, |
| 18 | + "outputs": [], |
| 19 | + "source": [ |
| 20 | + "from tdom import html" |
| 21 | + ] |
| 22 | + }, |
| 23 | + { |
| 24 | + "cell_type": "code", |
| 25 | + "execution_count": null, |
| 26 | + "id": "25e7eb68", |
| 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": "6820086a", |
| 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": "cbc747a0", |
| 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": "9461dc1c", |
| 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 | +} |
0 commit comments