-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
105 additions
and
71 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package htmx | ||
|
||
import "fmt" | ||
|
||
// NewStringAttrs returns a HX instance that returns stringified attributes for direct use in HTML. | ||
func NewStringAttrs() HX[string] { | ||
return NewHX(func(k Attribute, v any) string { | ||
switch v := v.(type) { | ||
// For strings, print the key='value' pair. | ||
case string: | ||
return fmt.Sprintf(`%s='%v'`, k, v) | ||
// For booleans, print just the key if true. | ||
case bool: | ||
if v { | ||
return string(k) | ||
} | ||
} | ||
|
||
return "" | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package htmx_test | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/will-wow/typed-htmx-go/htmx" | ||
) | ||
|
||
func ExampleNewStringAttrs() { | ||
hx := htmx.NewStringAttrs() | ||
|
||
fmt.Println(hx.Target(htmx.TargetNext)) | ||
fmt.Println(hx.Preserve()) | ||
|
||
// Output: | ||
// hx-target='next' | ||
// hx-preserve | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters