From 2ed153f8d287b3ffb5e8d1667ab51c922d82c504 Mon Sep 17 00:00:00 2001 From: Steve Manuel Date: Mon, 19 Sep 2016 02:09:29 -0700 Subject: reorganizing files and dir structure. adding initial (incomplete) management, types, system and db functionality. --- management/editor/editor.go | 41 +++++++++++++++ management/editor/elements.go | 117 ++++++++++++++++++++++++++++++++++++++++++ management/manager/manager.go | 46 +++++++++++++++++ 3 files changed, 204 insertions(+) create mode 100644 management/editor/editor.go create mode 100644 management/editor/elements.go create mode 100644 management/manager/manager.go (limited to 'management') 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) +} diff --git a/management/editor/elements.go b/management/editor/elements.go new file mode 100644 index 0000000..59d74f0 --- /dev/null +++ b/management/editor/elements.go @@ -0,0 +1,117 @@ +package editor + +import ( + "bytes" + "reflect" +) + +// Input returns the []byte of an HTML element with a label. +// IMPORTANT: +// The `fieldName` argument will cause a panic if it is not exactly the string +// form of the struct field that this editor input is representing +func Input(fieldName string, p interface{}, attrs map[string]string) []byte { + var wrapInLabel = true + label, found := attrs["label"] + if !found { + wrapInLabel = false + label = "" + } + + e := newElement("input", label, fieldName, p, attrs) + + return domElementSelfClose(e, wrapInLabel) +} + +// Textarea returns the []byte of a