Files
inventory-plus-plus/server/ui/svg/void_element.go
T
angel 82efe19ae0
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 4s
prototyped svg reports
2026-08-19 23:19:41 -06:00

43 lines
736 B
Go

package svg
import (
"bytes"
"fmt"
"io"
"strings"
)
type (
// VoidElement is like Element but for void elements
VoidElement[T Tag, A Attribute] struct {
Attributes []A
}
)
func (e *VoidElement[T, A]) Attr(as ...A) *VoidElement[T, A] {
e.Attributes = append(e.Attributes, as...)
return e
}
func (e VoidElement[T, A]) GetMarkup() string {
attrs := make([]string, len(e.Attributes))
for i, a := range e.Attributes {
attrs[i] = PrintAttribute(a)
}
return fmt.Sprintf(
`<%s %s/>`,
e.PrintTag(),
strings.Join(attrs, " "),
)
}
func (e VoidElement[T, A]) GetMarkupReader() io.Reader {
return bytes.NewReader([]byte(e.GetMarkup()))
}
func (e VoidElement[T, _]) PrintTag() string {
var t T
return t.PrintTag()
}