-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhtml_default.go
57 lines (47 loc) · 1.65 KB
/
html_default.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
package htmlyaml
import "strings"
func DefaultNull(k string) string { return `<div class="yaml-lang yaml-value yaml-null">null</div>` }
func DefaultBool(k string, v bool) string {
x := "false"
if v {
x = "true"
}
return `<div class="yaml-lang yaml-value yaml-bool">` + x + `</div>`
}
func DefaultString(k string, v string) string {
return `<div class="yaml-value yaml-string">` + v + `</div>`
}
func DefaultNumber(k string, v float64, s string) string {
return `<div class="yaml-value yaml-number">` + s + `</div>`
}
var (
DefaultArrayDash = `<div class="yaml-lang">- </div>`
DefaultArrayEmpty = `<div class="yaml-lang"> []</div>`
DefaultMapColon = `<div class="yaml-lang">: </div>`
DefaultMapEmpty = `<div class="yaml-lang"> {}</div>`
DefaultPaddingSpace = `<span class="yaml-padding-space"> </span>`
)
func DefaultMapKey(key string, v string) string {
return `<div class="yaml-key yaml-string">` + v + `</div>`
}
type DefaultRow struct {
Padding int
Space string
}
func (s DefaultRow) Marshal(v string, depth int) string {
p := `<div class="yaml-container-padding">` + strings.Repeat(s.Space, s.Padding*depth) + `</div>`
return `<div class="yaml-container-row">` + p + v + `</div>`
}
// DefaultMarshaler adds basic HTML div classes for further styling.
var DefaultMarshaler = Marshaler{
Null: DefaultNull,
Bool: DefaultBool,
String: DefaultString,
Number: DefaultNumber,
MapKey: DefaultMapKey,
ArrayDash: DefaultArrayDash,
ArrayEmpty: DefaultArrayEmpty,
MapColon: DefaultMapColon,
MapEmpty: DefaultMapEmpty,
Row: DefaultRow{Padding: 2, Space: DefaultPaddingSpace}.Marshal,
}