summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Manuel <nilslice@gmail.com>2016-12-06 02:16:29 -0800
committerSteve Manuel <nilslice@gmail.com>2016-12-06 02:16:29 -0800
commit40b5cfe2289b179c511a6c73757bb64228f0bc82 (patch)
tree47d28cef40b495cf3e52c65b27aa69ffe605a171
parentd28d2b6a44bea1f269feadc2b773253a95649f52 (diff)
cleanup template, move ContentName into base Item as String on Identifiable interface, also makes Item implement Stringer, useful in fmt funcs
-rw-r--r--cmd/ponzu/contentType.tmpl4
-rw-r--r--content/item.go8
-rw-r--r--content/types.go10
3 files changed, 13 insertions, 9 deletions
diff --git a/cmd/ponzu/contentType.tmpl b/cmd/ponzu/contentType.tmpl
index df582a0..af60e57 100644
--- a/cmd/ponzu/contentType.tmpl
+++ b/cmd/ponzu/contentType.tmpl
@@ -41,10 +41,6 @@ func init() {
Types["{{ .Name }}"] = func() interface{} { return new({{ .Name }}) }
}
-// ContentName is required to set the display name for a piece of content in the editor
-// Partially implements editor.Editable
-func ({{ .Initial }} *{{ .Name }}) ContentName() string { return fmt.Sprintf("{{ .Name }} - ID: %s", {{ .Initial }}.UniqueID()) }
-
// Editor is a buffer of bytes for the Form function to write input views
// partially implements editor.Editable
func ({{ .Initial }} *{{ .Name }}) Editor() *editor.Editor { return &{{ .Initial }}.editor }
diff --git a/content/item.go b/content/item.go
index 9eb3c16..e6c8243 100644
--- a/content/item.go
+++ b/content/item.go
@@ -1,6 +1,7 @@
package content
import (
+ "fmt"
"net/http"
uuid "github.com/satori/go.uuid"
@@ -22,6 +23,7 @@ type Identifiable interface {
ItemID() int
SetItemID(int)
UniqueID() uuid.UUID
+ String() string
}
// Hookable provides our user with an easy way to intercept or add functionality
@@ -83,6 +85,12 @@ func (i Item) UniqueID() uuid.UUID {
return i.UUID
}
+// String formats an Item into a printable value
+// partially implements the Identifiable interface
+func (i Item) String() string {
+ return fmt.Sprintf("Item ID: %s", i.UniqueID())
+}
+
// BeforeSave is a no-op to ensure structs which embed Item implement Hookable
func (i Item) BeforeSave(req *http.Request) error {
return nil
diff --git a/content/types.go b/content/types.go
index ede2b58..696d589 100644
--- a/content/types.go
+++ b/content/types.go
@@ -6,13 +6,13 @@ const (
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) }
-}
+
+ func init() {
+ Types["%[1]s"] = func() interface{} { return new(%[1]s) }
+ }
---------------------------------------------------------------------------+
+
`
)