package manager import ( "bytes" "fmt" "html/template" "github.com/bosssauce/ponzu/management/editor" ) const managerHTML = `
{{ .Editor }}
` type manager struct { ID int Kind string Editor template.HTML } // Manage ... func Manage(e editor.Editable, typeName string) ([]byte, error) { v, err := e.MarshalEditor() if err != nil { return nil, fmt.Errorf("Couldn't marshal editor for content %s. %s", typeName, err.Error()) } s, ok := e.(editor.Sortable) if !ok { return nil, fmt.Errorf("Content type %s does not implement content.Identifiable.", typeName) } m := manager{ ID: s.ItemID(), Kind: typeName, Editor: template.HTML(v), } // execute html template into buffer for func return val buf := &bytes.Buffer{} tmpl := template.Must(template.New("manager").Parse(managerHTML)) tmpl.Execute(buf, m) return buf.Bytes(), nil }