-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathoptions.go
104 lines (81 loc) · 2.29 KB
/
options.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
package mjml
import "fmt"
type ValidationLevel string
const (
Strict ValidationLevel = "strict"
Soft ValidationLevel = "soft"
Skip ValidationLevel = "skip"
)
type JuiceTag struct {
Start string `json:"start"`
End string `json:"end"`
}
type options struct {
data map[string]interface{}
}
type Fonts map[string]string
// ToHTMLOption provides options to customize the compilation process
// Detailed explanations of each option is available here: https://github.com/mjmlio/mjml#inside-nodejs
type ToHTMLOption func(options)
func WithBeautify(beautify bool) ToHTMLOption {
return func(o options) {
o.data["beautify"] = beautify
}
}
func WithBeautifyOptions(bOptions BeautifyOptions) ToHTMLOption {
beautifyOptions, ok := bOptions.(*beautifyOptions)
if !ok {
panic(fmt.Errorf("unsupported BeautifyOptions implementation: %#v", beautifyOptions))
}
return func(o options) {
o.data["beautifyOptions"] = beautifyOptions.data
}
}
func WithFonts(fonts Fonts) ToHTMLOption {
return func(o options) {
o.data["fonts"] = fonts
}
}
func WithJuiceOptions(jOptions JuiceOptions) ToHTMLOption {
juiceOptions, ok := jOptions.(*juiceOptions)
if !ok {
panic(fmt.Errorf("unsupported JuiceOptions implementation: %#v", juiceOptions))
}
return func(o options) {
o.data["juiceOptions"] = juiceOptions.data
}
}
func WithJuicePreserveTags(preserveTags map[string]JuiceTag) ToHTMLOption {
return func(o options) {
o.data["juicePreserveTags"] = preserveTags
}
}
func WithKeepComments(keepComments bool) ToHTMLOption {
return func(o options) {
o.data["keepComments"] = keepComments
}
}
func WithMinify(minify bool) ToHTMLOption {
return func(o options) {
o.data["minify"] = minify
}
}
func WithMinifyOptions(minifyOptions HTMLMinifierOptions) ToHTMLOption {
htmlMinifierOptions, ok := minifyOptions.(*htmlMinifierOptions)
if !ok {
panic(fmt.Errorf("unsupported HTMLMinifierOptions implementation: %#v", htmlMinifierOptions))
}
return func(o options) {
o.data["minifyOptions"] = htmlMinifierOptions.data
}
}
func WithPreprocessors(preprocessors []string) ToHTMLOption {
return func(o options) {
o.data["preprocessors"] = preprocessors
}
}
func WithValidationLevel(validationLevel ValidationLevel) ToHTMLOption {
return func(o options) {
o.data["validationLevel"] = validationLevel
}
}