Last active
January 23, 2020 08:57
-
-
Save dhilst/09f0fba73aa544408b0532a8176de855 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package content | |
import ( | |
"fmt" | |
"net/http" | |
"github.com/ponzu-cms/ponzu/management/editor" | |
"github.com/ponzu-cms/ponzu/system/item" | |
) | |
type Foo struct { | |
item.Item | |
Bar string `json:"bar"` | |
} | |
func (f *Foo) Create(res http.ResponseWriter, req *http.Request) error { | |
return nil | |
} | |
func (f *Foo) Update(res http.ResponseWriter, req *http.Request) error { | |
return nil | |
} | |
func (f *Foo) AutoApprove(http.ResponseWriter, *http.Request) error { | |
return nil | |
} | |
func (f *Foo) Delete(res http.ResponseWriter, req *http.Request) error { | |
return nil | |
} | |
// MarshalEditor writes a buffer of html to edit a Foo within the CMS | |
// and implements editor.Editable | |
func (f *Foo) MarshalEditor() ([]byte, error) { | |
view, err := editor.Form(f, | |
// Take note that the first argument to these Input-like functions | |
// is the string version of each Foo field, and must follow | |
// this pattern for auto-decoding and auto-encoding reasons: | |
editor.Field{ | |
View: editor.Input("Bar", f, map[string]string{ | |
"label": "Bar", | |
"type": "text", | |
"placeholder": "Enter the Bar here", | |
}), | |
}, | |
) | |
if err != nil { | |
return nil, fmt.Errorf("Failed to render Foo editor view: %s", err.Error()) | |
} | |
return view, nil | |
} | |
func init() { | |
item.Types["Foo"] = func() interface{} { return new(Foo) } | |
} | |
// String defines how a Foo is printed. Update it using more descriptive | |
// fields from the Foo struct type | |
func (f *Foo) String() string { | |
return fmt.Sprintf("Foo: %s", f.UUID) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment