Skip to content

Commit

Permalink
Merge pull request #1 from marcgibbons/main
Browse files Browse the repository at this point in the history
  • Loading branch information
SmileyChris authored Jun 3, 2024
2 parents 250bd74 + bb031d1 commit ac11e2a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
9 changes: 6 additions & 3 deletions includecontents/templatetags/includecontents.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,13 @@ def includecontents(parser, token):
# Nested attrs can't be handled by the standard include tag.
attr, value = match.groups()
advanced_attrs[attr] = parser.compile_filter(value or "True")
elif "-" in bit.split("=", 1)[0]:
elif "-" in bit:
# Attributes with a dash also can't be handled by the standard include.
attr, value = bit.split("=", 1)
advanced_attrs[attr] = parser.compile_filter(value)
if "=" in bit:
attr, value = bit.split("=", 1)
else:
attr, value = bit, ""
advanced_attrs[attr] = parser.compile_filter(value or "True")
elif match := re.match(r"^{ *(\w+) *}$", bit):
# Shorthand, e.g. {attr} is equivalent to attr=attr.
attr = match.group(1)
Expand Down
2 changes: 1 addition & 1 deletion tests/templates/test_component/attrs.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<main>
<include:card title="hello" large id="topcard" class="mycard">
<include:card title="hello" large id="topcard" class="mycard" x-data>
some content
</include:card>
</main>
2 changes: 1 addition & 1 deletion tests/test_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_debug_mode():
def test_attrs():
assert render_to_string("test_component/attrs.html") == (
"""<main>
<section class="mycard" id="topcard">
<section class="mycard" id="topcard" x-data>
<h3 class="large">hello</h3>
<div>
some content
Expand Down

0 comments on commit ac11e2a

Please sign in to comment.