// Package manager contains the admin UI to the CMS which wraps all content editor // interfaces to manage the create/edit/delete capabilities of Ponzu content. package manager import ( "bytes" "fmt" "html/template" "github.com/haturatu/ponzu/management/editor" "github.com/haturatu/ponzu/system/item" "github.com/gofrs/uuid" ) const managerHTML = `
{{ .Editor }}
` var managerTmpl = template.Must(template.New("manager").Parse(managerHTML)) 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(), Editor: template.HTML(v), } // execute html template into buffer for func return val buf := &bytes.Buffer{} if err := managerTmpl.Execute(buf, m); err != nil { return nil, err } return buf.Bytes(), nil }