diff options
author | Steve Manuel <nilslice@gmail.com> | 2016-09-19 02:09:29 -0700 |
---|---|---|
committer | Steve Manuel <nilslice@gmail.com> | 2016-09-19 02:09:29 -0700 |
commit | 2ed153f8d287b3ffb5e8d1667ab51c922d82c504 (patch) | |
tree | 8bde4e8865e5502ff72487252bcd5fcc09cd89c2 /content | |
parent | d62f31d1932125db59c4cf813c54d95a4a0200ee (diff) |
reorganizing files and dir structure. adding initial (incomplete) management, types, system and db functionality.
Diffstat (limited to 'content')
-rw-r--r-- | content/post.go | 67 | ||||
-rw-r--r-- | content/types.go | 7 |
2 files changed, 74 insertions, 0 deletions
diff --git a/content/post.go b/content/post.go new file mode 100644 index 0000000..65ea88f --- /dev/null +++ b/content/post.go @@ -0,0 +1,67 @@ +package content + +import ( + "fmt" + + "github.com/nilslice/cms/management/editor" + "github.com/nilslice/cms/system/db" +) + +// Post is the generic content struct +type Post struct { + db.Item + editor editor.Editor + + Title []byte `json:"title"` + Content []byte `json:"content"` + Author []byte `json:"author"` + Timestamp []byte `json:"timestamp"` +} + +func init() { + Types["Post"] = Post{} +} + +// ContentID partially implements editor.Editable +func (p Post) ContentID() int { return p.ID } + +// Editor partially implements editor.Editable +func (p Post) Editor() *editor.Editor { return &p.editor } + +// MarshalEditor writes a buffer of html to edit a Post and partially implements editor.Editable +func (p Post) MarshalEditor() ([]byte, error) { + view, err := editor.New(&p, + editor.Field{ + View: editor.Input("Title", &p, map[string]string{ + "label": "Post Title", + "type": "text", + "placeholder": "Enter your Post Title here", + }), + }, + editor.Field{ + View: editor.Textarea("Content", &p, map[string]string{ + "label": "Content", + "placeholder": "Add the content of your post here", + }), + }, + editor.Field{ + View: editor.Input("Author", &p, map[string]string{ + "label": "Author", + "type": "text", + "placeholder": "Enter the author name here", + }), + }, + editor.Field{ + View: editor.Input("Timestamp", &p, map[string]string{ + "label": "Publish Date", + "type": "date", + }), + }, + ) + + if err != nil { + return nil, fmt.Errorf("Failed to render Post editor view: %s", err.Error()) + } + + return view, nil +} diff --git a/content/types.go b/content/types.go new file mode 100644 index 0000000..778f742 --- /dev/null +++ b/content/types.go @@ -0,0 +1,7 @@ +package content + +import "github.com/nilslice/cms/management/editor" + +// Types is a map used to reference a type name to its actual Editable type +// mainly for lookups in /admin route based utilities +var Types = make(map[string]editor.Editable) |