summaryrefslogtreecommitdiff
path: root/examples/docker/admin/cmd/ponzu/templates/gen-content.tmpl
blob: 2d92b88af37b839a517dba0f263969f628617a37 (plain)
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
package content

import (
	"fmt"

	"github.com/ponzu-cms/ponzu/management/editor"
	"github.com/ponzu-cms/ponzu/system/item"
)

type {{ .Name }} struct {
    item.Item

    {{ range .Fields }}{{ .Name }} {{ .TypeName }} `json:"{{ .JSONName }}"`    
    {{ end }}	
}

// MarshalEditor writes a buffer of html to edit a {{ .Name }} within the CMS
// and implements editor.Editable
func ({{ .Initial }} *{{ .Name }}) MarshalEditor() ([]byte, error) {
	view, err := editor.Form({{ .Initial }},
        // Take note that the first argument to these Input-like functions 
        // is the string version of each {{ .Name }} field, and must follow 
        // this pattern for auto-decoding and auto-encoding reasons:
        {{ range .Fields }}editor.Field{
			{{ .View }}
		},
		{{ end }}
	)

	if err != nil {
		return nil, fmt.Errorf("Failed to render {{ .Name }} editor view: %s", err.Error())
	}

	return view, nil
}

func init() {
	item.Types["{{ .Name }}"] = func() interface{} { return new({{ .Name }}) }
}