Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow alpine-like attributes #60

Merged
merged 1 commit into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>"""
Loading