From 0dffc48c94a56f70c225fd843769a86a28ecd6f0 Mon Sep 17 00:00:00 2001 From: Juan-Pablo Scaletti Date: Mon, 22 Apr 2024 13:34:23 -0500 Subject: [PATCH] Allow alpine-like attributes --- pyproject.toml | 2 +- src/jinjax/jinjax.py | 2 +- tests/test_render.py | 25 +++++++++++++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 32ddd06..e15f196 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "jinjax" -version = "0.33" +version = "0.34" description = "Replace your HTML templates with Python server-Side components" authors = ["Juan-Pablo Scaletti "] license = "MIT" diff --git a/src/jinjax/jinjax.py b/src/jinjax/jinjax.py index 492157b..1c4cf3e 100644 --- a/src/jinjax/jinjax.py +++ b/src/jinjax/jinjax.py @@ -27,7 +27,7 @@ re_attr_name = r"" re_equal = r"" re_attr = r""" -(?P[a-zA-Z_][0-9a-zA-Z:_-]*) +(?P[a-zA-Z@:$_][a-zA-Z@:$_0-9-]*) (?: \s*=\s* (?P".*?"|'.*?'|\{.*?\}) diff --git a/tests/test_render.py b/tests/test_render.py index 8404844..8102b54 100644 --- a/tests/test_render.py +++ b/tests/test_render.py @@ -686,3 +686,28 @@ def test_template_globals_update_cache(catalog, folder): html = catalog.render("Page", __globals={"csrf_token": "xyz"}) print(html) assert """""" in html + + +def test_alpine_sintax(catalog, folder): + (folder / "Greeting.jinja").write_text(""" +{#def message #} +""") + + html = catalog.render("Greeting", message="Hello world!") + print(html) + expected = """""" + assert html == expected + + +def test_alpine_sintax_in_component(catalog, folder): + (folder / "Button.jinja").write_text( + """""" + ) + + (folder / "Greeting.jinja").write_text( + """""" + ) + + html = catalog.render("Greeting") + print(html) + assert html == """"""