Skip to content

Commit

Permalink
Allow alpine-like attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
jpsca committed Apr 22, 2024
1 parent 7c8d4ee commit 0dffc48
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>"]
license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion src/jinjax/jinjax.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
re_attr_name = r""
re_equal = r""
re_attr = r"""
(?P<name>[a-zA-Z_][0-9a-zA-Z:_-]*)
(?P<name>[a-zA-Z@:$_][a-zA-Z@:$_0-9-]*)
(?:
\s*=\s*
(?P<value>".*?"|'.*?'|\{.*?\})
Expand Down
25 changes: 25 additions & 0 deletions tests/test_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -686,3 +686,28 @@ def test_template_globals_update_cache(catalog, folder):
html = catalog.render("Page", __globals={"csrf_token": "xyz"})
print(html)
assert """<input type="hidden" name="csrft" value="xyz">""" in html


def test_alpine_sintax(catalog, folder):
(folder / "Greeting.jinja").write_text("""
{#def message #}
<button @click="alert('{{ message }}')">Say Hi</button>""")

html = catalog.render("Greeting", message="Hello world!")
print(html)
expected = """<button @click="alert('Hello world!')">Say Hi</button>"""
assert html == expected


def test_alpine_sintax_in_component(catalog, folder):
(folder / "Button.jinja").write_text(
"""<button {{ attrs.render() }}>{{ content }}</button>"""
)

(folder / "Greeting.jinja").write_text(
"""<Button @click="alert('Hello world!')">Say Hi</Button>"""
)

html = catalog.render("Greeting")
print(html)
assert html == """<button @click="alert('Hello world!')">Say Hi</button>"""

0 comments on commit 0dffc48

Please sign in to comment.