package manager import ( "bytes" "fmt" "html/template" "github.com/ponzu-cms/ponzu/management/editor" "github.com/ponzu-cms/ponzu/system/item" uuid "github.com/satori/go.uuid" ) const managerHTML = `
{{ .Editor }}
` type manager struct { ID int UUID uuid.UUID Kind string Slug 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()) } i, ok := e.(item.Identifiable) if !ok { return nil, fmt.Errorf("Content type %s does not implement item.Identifiable.", typeName) } s, ok := e.(item.Sluggable) if !ok { return nil, fmt.Errorf("Content type %s does not implement item.Sluggable.", typeName) } m := manager{ ID: i.ItemID(), UUID: i.UniqueID(), Kind: typeName, Slug: s.ItemSlug(), // TODO: just added this and its implementation -- need to rebuild & test 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 }