-
Notifications
You must be signed in to change notification settings - Fork 0
/
editor.go
56 lines (45 loc) · 1.22 KB
/
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
54
55
56
// Package editor enables users to create edit templates from their entities
// structs so that admins can manage entities
package editor
import (
"bytes"
"fmt"
"github.com/fanky5g/ponzu/config"
"github.com/fanky5g/ponzu/util"
"html/template"
"path/filepath"
"runtime"
)
var pathToTemplates string
func init() {
_, b, _, _ := runtime.Caller(0)
rootPath := filepath.Join(filepath.Dir(b), "../..")
pathToTemplates = fmt.Sprintf("%s/content/editor/templates", rootPath)
}
// Editable ensures data is editable
type Editable interface {
MarshalEditor(paths config.Paths) ([]byte, error)
}
// Editor is a view containing fields to manage entities
type Editor struct {
ViewBuf *bytes.Buffer
}
type ContentMetadata struct {
TypeName string
}
// Field is used to create the editable view for a field
// within a particular entities struct
type Field struct {
View []byte
}
type FieldArgs struct {
Parent string
TypeName string
}
func makeScript(name string) *template.Template {
templateString := util.Html(fmt.Sprintf("%s/scripts/%s", pathToTemplates, name))
return template.Must(template.New(name).Parse(templateString))
}
func makeHtml(name string) string {
return util.Html(fmt.Sprintf("%s/html/%s", pathToTemplates, name))
}