-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
html_default.go
55 lines (45 loc) · 1.58 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
package htmljson
import "strings"
func NullHTML(k string) string { return `<div class="json-lang json-value json-null">null</div>` }
func BoolHTML(k string, v bool) string {
x := "false"
if v {
x = "true"
}
return `<div class="json-lang json-value json-bool">` + x + `</div>`
}
func StringHTML(k string, v string) string {
return `<div class="json-value json-string">"` + v + `"</div>`
}
func NumberHTML(k string, v float64, s string) string {
return `<div class="json-value json-number">` + s + `</div>`
}
var DefaultArrayHTML = ArrayMarshaler{
OpenBracket: `<div class="json-lang">[</div>`,
CloseBracket: `<div class="json-lang">]</div>`,
Comma: `<div class="json-lang">,</div>`,
}
var DefaultMapHTML = MapMarshaler{
OpenBracket: `<div class="json-lang">{</div>`,
CloseBracket: `<div class="json-lang">}</div>`,
Comma: `<div class="json-lang">,</div>`,
Colon: `<div class="json-lang">:</div>`,
Key: func(key string, v string) string { return `<div class="json-key json-string">"` + v + `"</div>` },
}
type DefaultRowHTML struct {
Padding int
}
func (s DefaultRowHTML) Marshal(v string, depth int) string {
p := `<div class="json-container-padding">` + strings.Repeat(" ", s.Padding*2*depth) + `</div>`
return `<div class="json-container-row">` + p + v + `</div>`
}
// DefaultMarshaler adds basic HTML div classes for further styling.
var DefaultMarshaler = Marshaler{
Null: NullHTML,
Bool: BoolHTML,
String: StringHTML,
Number: NumberHTML,
Array: DefaultArrayHTML,
Map: DefaultMapHTML,
Row: DefaultRowHTML{Padding: 4}.Marshal,
}