blob: 83ed63af19cff7ba90180e8d1a5cf36e4b7f0d66 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
package manager
import (
"bytes"
"fmt"
"html/template"
"reflect"
"github.com/nilslice/cms/management/editor"
)
var html = `
<div class="manager">
<form method="post" action="/admin/edit?type={{.Kind}}&contentId={{.ID}}">
{{.Editor}}
<input type="submit" value="Save"/>
</form>
</div>
`
type form struct {
ID int
Kind string
Editor template.HTML
}
// Manage ...
func Manage(e editor.Editable) ([]byte, error) {
v, err := e.MarshalEditor()
if err != nil {
return nil, fmt.Errorf("Couldn't marshal editor for content %T. %s", e, err.Error())
}
f := form{
ID: e.ContentID(),
Kind: reflect.TypeOf(e).Name(),
Editor: template.HTML(v),
}
// execute html template into buffer for func return val
buf := &bytes.Buffer{}
tmpl := template.Must(template.New("manager").Parse(html))
tmpl.Execute(buf, f)
return buf.Bytes(), nil
}
|