-
Notifications
You must be signed in to change notification settings - Fork 189
/
meta_rich_editor.go
53 lines (45 loc) · 1.38 KB
/
meta_rich_editor.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
package admin
import (
"github.com/qor/qor"
"github.com/qor/qor/resource"
"github.com/qor/qor/utils"
)
// RichEditorConfig rich editor meta config
type RichEditorConfig struct {
AssetManager *Resource
DisableHTMLSanitizer bool
Plugins []RedactorPlugin
Settings map[string]interface{}
metaConfig
}
// RedactorPlugin register redactor plugins into rich editor
type RedactorPlugin struct {
Name string
Source string
}
// ConfigureQorMeta configure rich editor meta
func (richEditorConfig *RichEditorConfig) ConfigureQorMeta(metaor resource.Metaor) {
if meta, ok := metaor.(*Meta); ok {
meta.Type = "rich_editor"
// Compatible with old rich editor setting
if meta.Resource != nil {
richEditorConfig.AssetManager = meta.Resource
meta.Resource = nil
}
if !richEditorConfig.DisableHTMLSanitizer {
setter := meta.GetSetter()
meta.SetSetter(func(resource interface{}, metaValue *resource.MetaValue, context *qor.Context) {
metaValue.Value = utils.HTMLSanitizer.Sanitize(utils.ToString(metaValue.Value))
setter(resource, metaValue, context)
})
}
if richEditorConfig.Settings == nil {
richEditorConfig.Settings = map[string]interface{}{}
}
plugins := []string{"source"}
for _, plugin := range richEditorConfig.Plugins {
plugins = append(plugins, plugin.Name)
}
richEditorConfig.Settings["plugins"] = plugins
}
}