-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.go
97 lines (74 loc) · 1.59 KB
/
helpers.go
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package dhtml
import (
"fmt"
"github.com/mitoteam/mttools"
)
//Some basic type and helper shorthands.
// Function returning some html.
type RenderFunc func() HtmlPiece
func Div() *Tag {
return NewTag("div")
}
func Span() *Tag {
return NewTag("span")
}
func Text(text string) *Tag {
return &Tag{
kind: tagKindText,
text: text,
}
}
func Textf(format string, args ...any) *Tag {
return &Tag{
kind: tagKindText,
text: fmt.Sprintf(format, args...),
}
}
func UnsafeText(text string) *Tag {
return &Tag{
kind: tagKindUnsafeText,
text: text,
}
}
func Comment(text string) *Tag {
return &Tag{
kind: tagKindComment,
text: text,
}
}
func EmptyLabel(label string) *Tag {
span := Span()
settings.EmptyLabelRendererF(label, span)
return span
}
// Renders title and some value
func RenderValue(title, value any) *Tag {
tag := Div()
titleP := Piece(title)
valueP := Piece(value)
if !titleP.IsEmpty() {
tag.Append(NewTag("strong").Style("vertical-align", "top").Append(titleP).Append(": "))
}
if !valueP.IsEmpty() {
tag.Append(Div().Style("display", "inline-block").Append(valueP))
}
return tag
}
// Renders title and some value. If value is empty, render EmptyLabel instead
func RenderValueE(title, value any, emptyLabel string) *Tag {
var valueP *HtmlPiece
if mttools.IsEmpty(value) {
valueP = Piece(EmptyLabel(emptyLabel))
} else {
valueP = Piece(value)
if valueP.IsEmpty() {
valueP.Append(EmptyLabel(emptyLabel))
}
}
return RenderValue(title, valueP)
}
func Dbg(format string, a ...any) ElementI {
e := NewDebugElement(2)
e.Textf(format, a...)
return e
}