Skip to content
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
9 changes: 5 additions & 4 deletions htmx/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import (
)

// Text is plain text content for HTMX responses.
type Text struct {
Content string
type Text[T ~string] struct {
Content T
}

// Write writes the plain text content to w.
func (t *Text) Write(w io.Writer) error {
_, err := io.Copy(w, strings.NewReader(t.Content))
func (t *Text[T]) Write(w io.Writer) error {
s := string(t.Content)
_, err := io.Copy(w, strings.NewReader(s))
return err
}
2 changes: 1 addition & 1 deletion htmx/text_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestText_Write(t *testing.T) {

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
text := &Text{Content: tc.content}
text := &Text[string]{Content: tc.content}
var sb strings.Builder
must.NoError(t, text.Write(&sb))
must.Eq(t, tc.want, sb.String())
Expand Down