diff options
author | Steve Manuel <nilslice@gmail.com> | 2016-11-03 00:54:13 -0700 |
---|---|---|
committer | Steve Manuel <nilslice@gmail.com> | 2016-11-03 00:54:13 -0700 |
commit | 9db0046fadcd703d9903c7abd4159ded0730bf3a (patch) | |
tree | 0ac3592b120e175372e3d78276d2cbf8bbf2bccd /content | |
parent | 607f29fd3e61df0b921178995eb12fdee5049f16 (diff) |
simplifying Editable interface by adding Sluggable and Identifiable interfaces, moving relevant interface methods to be implemented by other types and updating caller code to assert the new interface types as needed
Diffstat (limited to 'content')
-rw-r--r-- | content/item.go | 25 | ||||
-rw-r--r-- | content/post.go | 15 |
2 files changed, 27 insertions, 13 deletions
diff --git a/content/item.go b/content/item.go index f4a5489..0077dc6 100644 --- a/content/item.go +++ b/content/item.go @@ -18,7 +18,28 @@ func (i Item) Touch() int64 { return i.Updated } -// ContentID partially implements the Sortable interface -func (i Item) ContentID() int { +// ItemID partially implements the Sortable interface +func (i Item) ItemID() int { return i.ID } + +// SetSlug sets the item's slug for its URL +func (i *Item) SetSlug(slug string) { + i.Slug = slug +} + +// Sluggable makes a struct locatable by URL with it's own path +// As an Item implementing Sluggable, slugs may overlap. If this is an issue, +// make your content struct (or one which imbeds Item) implement Sluggable +// and it will override the slug created by Item's SetSlug with your struct's +type Sluggable interface { + SetSlug(string) +} + +// Identifiable enables a struct to have its ID set. Typically this is done +// to set an ID to -1 indicating it is new for DB inserts, since by default +// a newly initialized struct would have an ID of 0, the int zero-value, and +// BoltDB's starting key per bucket is 0, thus overwriting the first record. +type Identifiable interface { + SetContentID(int) +} diff --git a/content/post.go b/content/post.go index dcdfeff..b81bb5a 100644 --- a/content/post.go +++ b/content/post.go @@ -74,17 +74,10 @@ func init() { Types["Post"] = func() interface{} { return new(Post) } } -// SetContentID partially implements editor.Editable -func (p *Post) SetContentID(id int) { p.ID = id } - -// ContentID partially implements editor.Editable -func (p *Post) ContentID() int { return p.ID } - -// ContentName partially implements editor.Editable +// ContentName is required to set the display name for a piece of content in the editor +// Partially implements editor.Editable func (p *Post) ContentName() string { return p.Title } -// SetSlug partially implements editor.Editable -func (p *Post) SetSlug(slug string) { p.Slug = slug } - -// Editor partially implements editor.Editable +// Editor is a buffer of bytes for the Form function to write input views +// partially implements editor.Editable func (p *Post) Editor() *editor.Editor { return &p.editor } |