summaryrefslogtreecommitdiff
path: root/management/editor/editor.go
diff options
context:
space:
mode:
authorSteve Manuel <nilslice@gmail.com>2016-09-19 02:09:29 -0700
committerSteve Manuel <nilslice@gmail.com>2016-09-19 02:09:29 -0700
commit2ed153f8d287b3ffb5e8d1667ab51c922d82c504 (patch)
tree8bde4e8865e5502ff72487252bcd5fcc09cd89c2 /management/editor/editor.go
parentd62f31d1932125db59c4cf813c54d95a4a0200ee (diff)
reorganizing files and dir structure. adding initial (incomplete) management, types, system and db functionality.
Diffstat (limited to 'management/editor/editor.go')
-rw-r--r--management/editor/editor.go41
1 files changed, 41 insertions, 0 deletions
diff --git a/management/editor/editor.go b/management/editor/editor.go
new file mode 100644
index 0000000..24b514e
--- /dev/null
+++ b/management/editor/editor.go
@@ -0,0 +1,41 @@
+// Package editor enables users to create edit views from their content
+// structs so that admins can manage content
+package editor
+
+import "bytes"
+
+// Editable ensures data is editable
+type Editable interface {
+ ContentID() int
+ Editor() *Editor
+ MarshalEditor() ([]byte, error)
+}
+
+// Editor is a view containing fields to manage content
+type Editor struct {
+ ViewBuf *bytes.Buffer
+}
+
+// Field is used to create the editable view for a field
+// within a particular content struct
+type Field struct {
+ View []byte
+}
+
+// New takes editable content and any number of Field funcs to describe the edit
+// page for any content struct added by a user
+func New(post Editable, fields ...Field) ([]byte, error) {
+ editor := post.Editor()
+
+ editor.ViewBuf = &bytes.Buffer{}
+
+ for _, f := range fields {
+ addFieldToEditorView(editor, f)
+ }
+
+ return editor.ViewBuf.Bytes(), nil
+}
+
+func addFieldToEditorView(e *Editor, f Field) {
+ e.ViewBuf.Write(f.View)
+}