-
Notifications
You must be signed in to change notification settings - Fork 0
/
db_entry_prop.go
121 lines (98 loc) · 2.46 KB
/
db_entry_prop.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package ast
import (
"fmt"
"github.com/kapitanov/notion2html/internal/html"
)
type DBEntryProperty struct {
Name string
Value DBEntryPropertyValue
Content string
}
func (v *DBEntryProperty) Render(w *html.Writer) {
v.Content = ""
if v.Value != nil {
v.Content = w.Render(func(wr *html.Writer) error {
v.Value.ToHTML(wr)
return nil
})
}
}
func (v *DBEntryProperty) ToHTML(w *html.Writer) {}
type DBEntryPropertyValue interface {
ToHTML(w *html.Writer)
}
type DBEntryPropertyTitleValue struct {
Value string
}
func NewDBEntryPropertyTitleValue(value string) *DBEntryPropertyTitleValue {
return &DBEntryPropertyTitleValue{
Value: value,
}
}
func (v *DBEntryPropertyTitleValue) ToHTML(w *html.Writer) {
w.PushTag(html.Tag("strong"))
w.WriteLine(html.Escape(v.Value))
w.PopTag()
}
type DBEntryPropertyTextValue struct {
Value string
}
func NewDBEntryPropertyTextValue(value string) *DBEntryPropertyTextValue {
return &DBEntryPropertyTextValue{
Value: value,
}
}
func (v *DBEntryPropertyTextValue) ToHTML(w *html.Writer) {
w.WriteLine(html.Escape(v.Value))
}
type DBEntryPropertyRichTextValue struct {
Value *Text
}
func NewDBEntryPropertyRichTextValue(value *Text) *DBEntryPropertyRichTextValue {
return &DBEntryPropertyRichTextValue{
Value: value,
}
}
func (v *DBEntryPropertyRichTextValue) ToHTML(w *html.Writer) {
v.Value.ToHTML(w)
}
type DBEntryPropertyTagsValue struct {
Values []*DBEntryTag
}
type DBEntryTag struct {
Name string
Color string
}
func NewDBEntryPropertyTagsValue(values []*DBEntryTag) *DBEntryPropertyTagsValue {
return &DBEntryPropertyTagsValue{
Values: values,
}
}
func (v *DBEntryPropertyTagsValue) ToHTML(w *html.Writer) {
for _, tag := range v.Values {
if tag.Color != "" && tag.Color != "default" {
w.PushTag(html.Tag("span").
Class("badge bg-primary").
Style(fmt.Sprintf("background-color: %s !important;", tag.Color)))
} else {
w.PushTag(html.Tag("span").Class("badge bg-primary"))
}
w.WriteLine(html.Escape(tag.Name))
w.PopTag()
}
}
type DBEntryPropertyBoolValue struct {
Value bool
}
func NewDBEntryPropertyBoolValue(value bool) *DBEntryPropertyBoolValue {
return &DBEntryPropertyBoolValue{
Value: value,
}
}
func (v *DBEntryPropertyBoolValue) ToHTML(w *html.Writer) {
if v.Value {
w.WriteLine(html.Escape("Yes"))
} else {
w.WriteLine(html.Escape("No"))
}
}