Skip to content

Commit 6700664

Browse files
committed
Add support for dots in html attribute keys by @drkane
1 parent 9ede5f5 commit 6700664

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/jx/parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
re_attr_name = r""
2525
re_equal = r""
2626
re_attr = r"""
27-
(?P<name>[:a-zA-Z@$_][a-zA-Z@:$_0-9-]*)
27+
(?P<name>[:a-zA-Z@$_][a-zA-Z@:$_0-9-\.]*)
2828
(?:
2929
\s*=\s*
3030
(?P<value>".*?"|'.*?'|\{\{.*?\}\})

tests/test_component.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,3 +473,30 @@ def test_no_autoreload(folder):
473473
<link rel="stylesheet" href="before.css">
474474
BEFORE
475475
""".strip()
476+
477+
478+
def test_alpine_sintax(folder):
479+
(folder / "greeting.jinja").write_text("""
480+
{#def message #}
481+
<button @click.prevent="alert('{{ message }}')">Say Hi</button>""")
482+
cat = Catalog(folder, auto_reload=False)
483+
484+
html = cat.render("greeting.jinja", message="Hello world!")
485+
print(html)
486+
assert html == """<button @click.prevent="alert('Hello world!')">Say Hi</button>"""
487+
488+
489+
def test_alpine_sintax_in_component(folder):
490+
(folder / "button.jinja").write_text(
491+
"""<button {{ attrs.render() }}>{{ content }}</button>"""
492+
)
493+
494+
(folder / "greeting.jinja").write_text("""
495+
{# import "button.jinja" as Button #}
496+
<Button @click.prevent="alert('Hello world!')">Say Hi</Button>
497+
""")
498+
cat = Catalog(folder, auto_reload=False)
499+
500+
html = cat.render("greeting.jinja")
501+
print(html)
502+
assert html == """<button @click.prevent="alert('Hello world!')">Say Hi</button>"""

0 commit comments

Comments
 (0)