diff options
Diffstat (limited to 'cmd/ponzu/templates')
-rw-r--r-- | cmd/ponzu/templates/gen-content.tmpl | 39 | ||||
-rw-r--r-- | cmd/ponzu/templates/gen-input.tmpl | 5 |
2 files changed, 44 insertions, 0 deletions
diff --git a/cmd/ponzu/templates/gen-content.tmpl b/cmd/ponzu/templates/gen-content.tmpl new file mode 100644 index 0000000..2d92b88 --- /dev/null +++ b/cmd/ponzu/templates/gen-content.tmpl @@ -0,0 +1,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 }}) } +}
\ No newline at end of file diff --git a/cmd/ponzu/templates/gen-input.tmpl b/cmd/ponzu/templates/gen-input.tmpl new file mode 100644 index 0000000..8bea12a --- /dev/null +++ b/cmd/ponzu/templates/gen-input.tmpl @@ -0,0 +1,5 @@ +View: editor.Input("{{ .Name }}", {{ .Initial }}, map[string]string{ + "label": "{{ .Name }}", + "type": "text", + "placeholder": "Enter the {{ .Name }} here", +}),
\ No newline at end of file |