diff --git a/fasthtml/_modidx.py b/fasthtml/_modidx.py index b36fb6e3..8bc339b0 100644 --- a/fasthtml/_modidx.py +++ b/fasthtml/_modidx.py @@ -15,7 +15,6 @@ 'fasthtml.components.FT.__radd__': ('api/components.html#ft.__radd__', 'fasthtml/components.py'), 'fasthtml.components.FT.__str__': ('api/components.html#ft.__str__', 'fasthtml/components.py'), 'fasthtml.components.File': ('api/components.html#file', 'fasthtml/components.py'), - 'fasthtml.components.__getattr__': ('api/components.html#__getattr__', 'fasthtml/components.py'), 'fasthtml.components._fill_item': ('api/components.html#_fill_item', 'fasthtml/components.py'), 'fasthtml.components.attrmap_x': ('api/components.html#attrmap_x', 'fasthtml/components.py'), 'fasthtml.components.fill_dataclass': ('api/components.html#fill_dataclass', 'fasthtml/components.py'), diff --git a/fasthtml/components.py b/fasthtml/components.py index 3b0864f8..b4cf33d1 100644 --- a/fasthtml/components.py +++ b/fasthtml/components.py @@ -1,6 +1,6 @@ """`ft_html` and `ft_hx` functions to add some conveniences to `ft`, along with a full set of basic HTML components, and functions to work with forms and `FT` conversion -Docs: https://www.fastht.ml/docsapi/components.html.md""" +Docs: https://www.fastht.ml/docs/api/components.html.md""" # AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/api/01_components.ipynb. @@ -195,11 +195,7 @@ def find_inputs(e, tags='input', **kw): return inputs # %% ../nbs/api/01_components.ipynb #1d8a28b1 -def __getattr__(tag): - if tag.startswith('_') or tag[0].islower(): raise AttributeError - tag = re.sub(r'(?<=[a-z0-9])(?=[A-Z])', '-', tag.replace("_", "-")).lower() - def _f(*c, target_id=None, **kwargs): return ft_hx(tag, *c, target_id=target_id, **kwargs) - return _f +__getattr__ = mk_getattr(ft_hx) # %% ../nbs/api/01_components.ipynb #afb0f65c _re_h2x_attr_key = re.compile(r'^[A-Za-z_-][\w-]*$') diff --git a/fasthtml/core.py b/fasthtml/core.py index ebf03fd2..04739c36 100644 --- a/fasthtml/core.py +++ b/fasthtml/core.py @@ -1,6 +1,6 @@ """The `FastHTML` subclass of `Starlette`. -Docs: https://www.fastht.ml/docsapi/core.html.md""" +Docs: https://www.fastht.ml/docs/api/core.html.md""" # AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/api/00_core.ipynb. diff --git a/fasthtml/js.py b/fasthtml/js.py index b1410d32..2f0454c5 100644 --- a/fasthtml/js.py +++ b/fasthtml/js.py @@ -1,6 +1,6 @@ """Basic external Javascript lib wrappers -Docs: https://www.fastht.ml/docsapi/js.html.md""" +Docs: https://www.fastht.ml/docs/api/js.html.md""" # AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/api/03_js.ipynb. diff --git a/fasthtml/jupyter.py b/fasthtml/jupyter.py index 884b01e0..53532518 100644 --- a/fasthtml/jupyter.py +++ b/fasthtml/jupyter.py @@ -1,6 +1,6 @@ """Use FastHTML in Jupyter notebooks -Docs: https://www.fastht.ml/docsapi/jupyter.html.md""" +Docs: https://www.fastht.ml/docs/api/jupyter.html.md""" # AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/api/06_jupyter.ipynb. diff --git a/fasthtml/oauth.py b/fasthtml/oauth.py index c4b87278..e27cfab8 100644 --- a/fasthtml/oauth.py +++ b/fasthtml/oauth.py @@ -1,6 +1,6 @@ """Basic scaffolding for handling OAuth -Docs: https://www.fastht.ml/docsapi/oauth.html.md""" +Docs: https://www.fastht.ml/docs/api/oauth.html.md""" # AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/api/08_oauth.ipynb. diff --git a/fasthtml/pico.py b/fasthtml/pico.py index c2a63834..7bd0a82a 100644 --- a/fasthtml/pico.py +++ b/fasthtml/pico.py @@ -1,6 +1,6 @@ """Basic components for generating Pico CSS tags -Docs: https://www.fastht.ml/docsapi/pico.html.md""" +Docs: https://www.fastht.ml/docs/api/pico.html.md""" # AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/api/04_pico.ipynb. diff --git a/fasthtml/svg.py b/fasthtml/svg.py index 1c468781..f50a50e7 100644 --- a/fasthtml/svg.py +++ b/fasthtml/svg.py @@ -1,6 +1,6 @@ """Simple SVG FT elements -Docs: https://www.fastht.ml/docsapi/svg.html.md""" +Docs: https://www.fastht.ml/docs/api/svg.html.md""" # AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/api/05_svg.ipynb. diff --git a/fasthtml/xtend.py b/fasthtml/xtend.py index a4a31df7..cb8eee02 100644 --- a/fasthtml/xtend.py +++ b/fasthtml/xtend.py @@ -1,6 +1,6 @@ """Simple extensions to standard HTML components, such as adding sensible defaults -Docs: https://www.fastht.ml/docsapi/xtend.html.md""" +Docs: https://www.fastht.ml/docs/api/xtend.html.md""" # AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/api/02_xtend.ipynb. diff --git a/nbs/api/01_components.ipynb b/nbs/api/01_components.ipynb index dc22427c..895a5b7b 100644 --- a/nbs/api/01_components.ipynb +++ b/nbs/api/01_components.ipynb @@ -79,11 +79,15 @@ "

FastHTML is Fast

" ], "text/markdown": [ + "
\n", + "\n", "```html\n", "

\n", "FastHTML is Fast

\n", "\n", - "```" + "```\n", + "\n", + "
" ], "text/plain": [ "

FastHTML is Fast

" @@ -337,9 +341,13 @@ "" ], "text/markdown": [ + "
\n", + "\n", "```html\n", "\n", - "```" + "```\n", + "\n", + "
" ], "text/plain": [ "" @@ -366,9 +374,13 @@ "" ], "text/markdown": [ + "
\n", + "\n", "```html\n", "\n", - "```" + "```\n", + "\n", + "
" ], "text/plain": [ "" @@ -395,9 +407,13 @@ "" ], "text/markdown": [ + "
\n", + "\n", "```html\n", "\n", - "```" + "```\n", + "\n", + "
" ], "text/plain": [ "" @@ -434,9 +450,13 @@ "" ], "text/markdown": [ + "
\n", + "\n", "```html\n", "\n", - "```" + "```\n", + "\n", + "
" ], "text/plain": [ "" @@ -479,9 +499,13 @@ "" ], "text/markdown": [ + "
\n", + "\n", "```html\n", "\n", - "```" + "```\n", + "\n", + "
" ], "text/plain": [ "" @@ -508,9 +532,13 @@ "" ], "text/markdown": [ + "
\n", + "\n", "```html\n", "\n", - "```" + "```\n", + "\n", + "
" ], "text/plain": [ "" @@ -567,9 +595,13 @@ "
" ], "text/markdown": [ + "
\n", + "\n", "```html\n", "
\n", - "```" + "```\n", + "\n", + "
" ], "text/plain": [ "
" @@ -610,10 +642,14 @@ "" ], "text/markdown": [ + "
\n", + "\n", "```html\n", "\n", "\n", - "```" + "```\n", + "\n", + "
" ], "text/plain": [ "" @@ -641,10 +677,14 @@ "" ], "text/markdown": [ + "
\n", + "\n", "```html\n", "\n", "\n", - "```" + "```\n", + "\n", + "
" ], "text/plain": [ "" @@ -671,10 +711,14 @@ "" ], "text/markdown": [ + "
\n", + "\n", "```html\n", "\n", "\n", - "```" + "```\n", + "\n", + "
" ], "text/plain": [ "" @@ -920,12 +964,16 @@ "
" ], "text/markdown": [ + "
\n", + "\n", "```html\n", "
\n", " \n", "
\n", - "```" + "```\n", + "\n", + "
" ], "text/plain": [ "
" @@ -964,9 +1012,13 @@ "
" ], "text/markdown": [ + "
\n", + "\n", "```html\n", "
\n", - "```" + "```\n", + "\n", + "
" ], "text/plain": [ "
" @@ -1003,12 +1055,16 @@ "
" ], "text/markdown": [ + "
\n", + "\n", "```html\n", "
\n", - "```" + "```\n", + "\n", + "
" ], "text/plain": [ "
" @@ -1136,6 +1192,14 @@ "test_eq(elem.xpath(\"//input[@id='title']/@value\"), ['Profit'])" ] }, + { + "cell_type": "markdown", + "id": "db280a83", + "metadata": {}, + "source": [ + "Undefined exports like `MyTag` create a matching kebab-case tag () via `ft_hx`. The logic lives in `fastcore.xml.mk_getattr`; here we just supply `ft_hx` as the tag factory so custom tags get htmx attribute handling." + ] + }, { "cell_type": "code", "execution_count": null, @@ -1144,11 +1208,18 @@ "outputs": [], "source": [ "#| export\n", - "def __getattr__(tag):\n", - " if tag.startswith('_') or tag[0].islower(): raise AttributeError\n", - " tag = re.sub(r'(?<=[a-z0-9])(?=[A-Z])', '-', tag.replace(\"_\", \"-\")).lower()\n", - " def _f(*c, target_id=None, **kwargs): return ft_hx(tag, *c, target_id=target_id, **kwargs)\n", - " return _f" + "__getattr__ = mk_getattr(ft_hx)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "72f9f507", + "metadata": {}, + "outputs": [], + "source": [ + "from fasthtml.components import BarBaz\n", + "test_eq(to_xml(BarBaz(hx_get='/foo')), '')" ] }, {