Skip to content

Commit

Permalink
feat: support HTMX wildcard attribute names, fixes #271
Browse files Browse the repository at this point in the history
  • Loading branch information
a-h committed Nov 6, 2023
1 parent 6662349 commit 43545f8
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.458
0.2.459
10 changes: 10 additions & 0 deletions generator/test-element-attributes/expected.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,13 @@
end">
</div>

<h2>HTMX Wildcard attribute</h2>

<form
hx-post="/api/secret/unlock"
hx-target="#secret"
hx-target-*="#errors"
hx-indicator="#loading-indicator"
>
<input type="button" value="Unlock"/>
</form>
9 changes: 9 additions & 0 deletions generator/test-element-attributes/template.templ
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,13 @@ templ render(p person) {
do something
end"
></div>
<h2>HTMX Wildcard attribute</h2>
<form
hx-post="/api/secret/unlock"
hx-target="#secret"
hx-target-*="#errors"
hx-indicator="#loading-indicator"
>
<input type="button" value="Unlock"/>
</form>
}
11 changes: 10 additions & 1 deletion generator/test-element-attributes/template_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion parser/v2/elementparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ var elementCloseTagParser = parse.Func(func(in *parse.Input) (ct elementCloseTag
// Attribute name.
var (
attributeNameFirst = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ:_@"
attributeNameSubsequent = attributeNameFirst + "-.0123456789"
attributeNameSubsequent = attributeNameFirst + "-.0123456789*"
attributeNameParser = parse.Func(func(in *parse.Input) (name string, ok bool, err error) {
start := in.Index()
var prefix, suffix string
Expand Down
9 changes: 9 additions & 0 deletions parser/v2/elementparser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,15 @@ if test {
Value: `<">`,
},
},
{
name: "HTMX wildcard attribute names are supported",
input: ` hx-target-*="#errors"`,
parser: StripType(constantAttributeParser),
expected: ConstantAttribute{
Name: "hx-target-*",
Value: `#errors`,
},
},
}
for _, tt := range tests {
tt := tt
Expand Down
2 changes: 1 addition & 1 deletion parser/v2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ type ExpressionAttribute struct {

func (ea ExpressionAttribute) String() string {
sb := new(strings.Builder)
ea.Write(sb, 0)
_ = ea.Write(sb, 0)
return sb.String()
}

Expand Down

0 comments on commit 43545f8

Please sign in to comment.