-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathelement.go
More file actions
33 lines (26 loc) · 828 Bytes
/
element.go
File metadata and controls
33 lines (26 loc) · 828 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package dhtml
import (
"reflect"
"github.com/mitoteam/mttools"
)
// Element is something that can be turned in list of html tags.
// Very simple elements are: tags itself, html comments or just plain text content.
// It could be much more complex things like Bootstrap's card for example.
// Whole HTML document is element as well (see dhtml.Document helper).
type ElementI interface {
GetTags() TagList
}
// Function to be passed to Walk() or WalkR() methods
type ElementWalkFunc func(e ElementI, args ...any)
func AnyToElement(v any) ElementI {
if v, ok := v.(ElementI); ok {
//already an element
return v
}
if s, ok := mttools.AnyToStringOk(v); ok {
//strings are simple text elements
return Text(s)
}
mttools.PanicWithSignatureF("unsupported type: %s", reflect.ValueOf(v).Type().Name())
return nil
}