diff options
author | Steve Manuel <nilslice@gmail.com> | 2016-09-20 00:24:31 -0700 |
---|---|---|
committer | Steve Manuel <nilslice@gmail.com> | 2016-09-20 00:24:31 -0700 |
commit | cb545173a6f33aff050a1855dcb87184d50b79a6 (patch) | |
tree | a2293c3712af16d5d3b31dd5bb40ae5501e9b7e9 /content | |
parent | 3bbfb755411768fe8557b1e36ec10d65a351793f (diff) |
adding support for boltdb storage, updating and inserting content, some reorganization
Diffstat (limited to 'content')
-rw-r--r-- | content/item.go | 7 | ||||
-rw-r--r-- | content/post.go | 14 | ||||
-rw-r--r-- | content/types.go | 18 |
3 files changed, 30 insertions, 9 deletions
diff --git a/content/item.go b/content/item.go new file mode 100644 index 0000000..8b834e4 --- /dev/null +++ b/content/item.go @@ -0,0 +1,7 @@ +package content + +// Item should only be embedded into content type structs. +// Helper for DB-related actions +type Item struct { + ID int `json:"id"` +} diff --git a/content/post.go b/content/post.go index 1dfb8fb..7bb36f6 100644 --- a/content/post.go +++ b/content/post.go @@ -18,7 +18,7 @@ type Post struct { } func init() { - Types["Post"] = &Post{} + Types["Post"] = func() interface{} { return new(Post) } } // ContentID partially implements editor.Editable @@ -28,30 +28,30 @@ func (p *Post) ContentID() int { return p.ID } 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, +func (p *Post) MarshalEditor() ([]byte, error) { + view, err := editor.New(p, editor.Field{ - View: editor.Input("Title", &p, map[string]string{ + 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{ + 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{ + 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{ + View: editor.Input("Timestamp", p, map[string]string{ "label": "Publish Date", "type": "date", }), diff --git a/content/types.go b/content/types.go index 778f742..ede2b58 100644 --- a/content/types.go +++ b/content/types.go @@ -1,7 +1,21 @@ package content -import "github.com/nilslice/cms/management/editor" +const ( + // ErrTypeNotRegistered means content type isn't registered (not found in Types map) + ErrTypeNotRegistered = `Error: +There is no type registered for %[1]s + +Add this to the file which defines %[1]s{} in the 'content' package: +--------------------------------------------------------------------------+ + +func init() { + Types["%[1]s"] = func() interface{} { return new(%[1]s) } +} + +--------------------------------------------------------------------------+ +` +) // 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) +var Types = make(map[string]func() interface{}) |