summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Manuel <nilslice@gmail.com>2016-12-18 15:06:25 -0800
committerSteve Manuel <nilslice@gmail.com>2016-12-18 15:06:25 -0800
commite187d5ee6354acf40ac8178b0a8a631e80e35e8e (patch)
treef5bef4723710b6d79cef85974bafde149afb44e4
parent7d87d40f8d0550331d1b19dea2c374ecfbc77d48 (diff)
moving item and types into system/item package and updating throughout codebase
-rw-r--r--cmd/ponzu/contentType.tmpl5
-rw-r--r--management/manager/manager.go10
-rw-r--r--system/admin/admin.go4
-rw-r--r--system/admin/config/config.go6
-rw-r--r--system/admin/handlers.go48
-rw-r--r--system/api/external.go8
-rw-r--r--system/api/handlers.go8
-rw-r--r--system/db/content.go16
-rw-r--r--system/db/init.go6
-rw-r--r--system/item/item.go (renamed from content/item.go)2
-rw-r--r--system/item/types.go (renamed from content/types.go)4
11 files changed, 59 insertions, 58 deletions
diff --git a/cmd/ponzu/contentType.tmpl b/cmd/ponzu/contentType.tmpl
index af60e57..1804555 100644
--- a/cmd/ponzu/contentType.tmpl
+++ b/cmd/ponzu/contentType.tmpl
@@ -4,10 +4,11 @@ import (
"fmt"
"github.com/bosssauce/ponzu/management/editor"
+ "github.com/bosssauce/ponzu/system/item"
)
type {{ .Name }} struct {
- Item
+ item.Item
editor editor.Editor
{{ range .Fields }}{{ .Name }} {{ .TypeName }} `json:"{{ .JSONName }}"`
@@ -38,7 +39,7 @@ func ({{ .Initial }} *{{ .Name }}) MarshalEditor() ([]byte, error) {
}
func init() {
- Types["{{ .Name }}"] = func() interface{} { return new({{ .Name }}) }
+ item.Types["{{ .Name }}"] = func() interface{} { return new({{ .Name }}) }
}
// Editor is a buffer of bytes for the Form function to write input views
diff --git a/management/manager/manager.go b/management/manager/manager.go
index 989eb98..5eafb9a 100644
--- a/management/manager/manager.go
+++ b/management/manager/manager.go
@@ -5,8 +5,8 @@ import (
"fmt"
"html/template"
- "github.com/bosssauce/ponzu/content"
"github.com/bosssauce/ponzu/management/editor"
+ "github.com/bosssauce/ponzu/system/item"
uuid "github.com/satori/go.uuid"
)
@@ -121,14 +121,14 @@ func Manage(e editor.Editable, typeName string) ([]byte, error) {
return nil, fmt.Errorf("Couldn't marshal editor for content %s. %s", typeName, err.Error())
}
- i, ok := e.(content.Identifiable)
+ i, ok := e.(item.Identifiable)
if !ok {
- return nil, fmt.Errorf("Content type %s does not implement content.Identifiable.", typeName)
+ return nil, fmt.Errorf("Content type %s does not implement item.Identifiable.", typeName)
}
- s, ok := e.(content.Sluggable)
+ s, ok := e.(item.Sluggable)
if !ok {
- return nil, fmt.Errorf("Content type %s does not implement content.Sluggable.", typeName)
+ return nil, fmt.Errorf("Content type %s does not implement item.Sluggable.", typeName)
}
m := manager{
diff --git a/system/admin/admin.go b/system/admin/admin.go
index 9ddff84..53948af 100644
--- a/system/admin/admin.go
+++ b/system/admin/admin.go
@@ -8,10 +8,10 @@ import (
"html/template"
"net/http"
- "github.com/bosssauce/ponzu/content"
"github.com/bosssauce/ponzu/system/admin/user"
"github.com/bosssauce/ponzu/system/api/analytics"
"github.com/bosssauce/ponzu/system/db"
+ "github.com/bosssauce/ponzu/system/item"
)
var startAdminHTML = `<!doctype html>
@@ -104,7 +104,7 @@ func Admin(view []byte) ([]byte, error) {
a := admin{
Logo: string(cfg),
- Types: content.Types,
+ Types: item.Types,
Subview: template.HTML(view),
}
diff --git a/system/admin/config/config.go b/system/admin/config/config.go
index 2e957ed..6c315f5 100644
--- a/system/admin/config/config.go
+++ b/system/admin/config/config.go
@@ -1,13 +1,13 @@
package config
import (
- "github.com/bosssauce/ponzu/content"
"github.com/bosssauce/ponzu/management/editor"
+ "github.com/bosssauce/ponzu/system/item"
)
//Config represents the confirgurable options of the system
type Config struct {
- content.Item
+ item.Item
editor editor.Editor
Name string `json:"name"`
@@ -19,7 +19,7 @@ type Config struct {
CacheInvalidate []string `json:"cache"`
}
-// String partially implements content.Identifiable and overrides Item's String()
+// String partially implements item.Identifiable and overrides Item's String()
func (c *Config) String() string { return c.Name }
// Editor partially implements editor.Editable
diff --git a/system/admin/handlers.go b/system/admin/handlers.go
index 55a5f30..85c1f8b 100644
--- a/system/admin/handlers.go
+++ b/system/admin/handlers.go
@@ -11,7 +11,6 @@ import (
"strings"
"time"
- "github.com/bosssauce/ponzu/content"
"github.com/bosssauce/ponzu/management/editor"
"github.com/bosssauce/ponzu/management/manager"
"github.com/bosssauce/ponzu/system/admin/config"
@@ -19,6 +18,7 @@ import (
"github.com/bosssauce/ponzu/system/admin/user"
"github.com/bosssauce/ponzu/system/api"
"github.com/bosssauce/ponzu/system/db"
+ "github.com/bosssauce/ponzu/system/item"
"github.com/gorilla/schema"
emailer "github.com/nilslice/email"
@@ -759,7 +759,7 @@ func contentsHandler(res http.ResponseWriter, req *http.Request) {
status := q.Get("status")
- if _, ok := content.Types[t]; !ok {
+ if _, ok := item.Types[t]; !ok {
res.WriteHeader(http.StatusBadRequest)
errView, err := Error400()
if err != nil {
@@ -770,7 +770,7 @@ func contentsHandler(res http.ResponseWriter, req *http.Request) {
return
}
- pt := content.Types[t]()
+ pt := item.Types[t]()
p, ok := pt.(editor.Editable)
if !ok {
@@ -1053,17 +1053,17 @@ func contentsHandler(res http.ResponseWriter, req *http.Request) {
// p is the asserted post as an Editable, t is the Type of the post.
// specifier is passed to append a name to a namespace like __pending
func adminPostListItem(e editor.Editable, typeName, status string) []byte {
- s, ok := e.(content.Sortable)
+ s, ok := e.(item.Sortable)
if !ok {
- log.Println("Content type", typeName, "doesn't implement content.Sortable")
- post := `<li class="col s12">Error retreiving data. Your data type doesn't implement necessary interfaces. (content.Sortable)</li>`
+ log.Println("Content type", typeName, "doesn't implement item.Sortable")
+ post := `<li class="col s12">Error retreiving data. Your data type doesn't implement necessary interfaces. (item.Sortable)</li>`
return []byte(post)
}
- i, ok := e.(content.Identifiable)
+ i, ok := e.(item.Identifiable)
if !ok {
- log.Println("Content type", typeName, "doesn't implement content.Identifiable")
- post := `<li class="col s12">Error retreiving data. Your data type doesn't implement necessary interfaces. (content.Identifiable)</li>`
+ log.Println("Content type", typeName, "doesn't implement item.Identifiable")
+ post := `<li class="col s12">Error retreiving data. Your data type doesn't implement necessary interfaces. (item.Identifiable)</li>`
return []byte(post)
}
@@ -1127,12 +1127,12 @@ func approveContentHandler(res http.ResponseWriter, req *http.Request) {
t = strings.Split(t, "__")[0]
}
- post := content.Types[t]()
+ post := item.Types[t]()
// run hooks
- hook, ok := post.(content.Hookable)
+ hook, ok := post.(item.Hookable)
if !ok {
- log.Println("Type", t, "does not implement content.Hookable or embed content.Item.")
+ log.Println("Type", t, "does not implement item.Hookable or embed item.Item.")
res.WriteHeader(http.StatusBadRequest)
errView, err := Error400()
if err != nil {
@@ -1267,9 +1267,9 @@ func editHandler(res http.ResponseWriter, req *http.Request) {
t := q.Get("type")
status := q.Get("status")
- contentType, ok := content.Types[t]
+ contentType, ok := item.Types[t]
if !ok {
- fmt.Fprintf(res, content.ErrTypeNotRegistered, t)
+ fmt.Fprintf(res, item.ErrTypeNotRegistered, t)
return
}
post := contentType()
@@ -1317,9 +1317,9 @@ func editHandler(res http.ResponseWriter, req *http.Request) {
return
}
} else {
- item, ok := post.(content.Identifiable)
+ item, ok := post.(item.Identifiable)
if !ok {
- log.Println("Content type", t, "doesn't implement content.Identifiable")
+ log.Println("Content type", t, "doesn't implement item.Identifiable")
return
}
item.SetItemID(-1)
@@ -1419,7 +1419,7 @@ func editHandler(res http.ResponseWriter, req *http.Request) {
t = strings.Split(t, "__")[0]
}
- p, ok := content.Types[t]
+ p, ok := item.Types[t]
if !ok {
log.Println("Type", t, "is not a content type. Cannot edit or save.")
res.WriteHeader(http.StatusBadRequest)
@@ -1433,9 +1433,9 @@ func editHandler(res http.ResponseWriter, req *http.Request) {
}
post := p()
- hook, ok := post.(content.Hookable)
+ hook, ok := post.(item.Hookable)
if !ok {
- log.Println("Type", t, "does not implement content.Hookable or embed content.Item.")
+ log.Println("Type", t, "does not implement item.Hookable or embed item.Item.")
res.WriteHeader(http.StatusBadRequest)
errView, err := Error400()
if err != nil {
@@ -1530,9 +1530,9 @@ func deleteHandler(res http.ResponseWriter, req *http.Request) {
ct = spec[0]
}
- p, ok := content.Types[ct]
+ p, ok := item.Types[ct]
if !ok {
- log.Println("Type", t, "does not implement content.Hookable or embed content.Item.")
+ log.Println("Type", t, "does not implement item.Hookable or embed item.Item.")
res.WriteHeader(http.StatusBadRequest)
errView, err := Error400()
if err != nil {
@@ -1544,9 +1544,9 @@ func deleteHandler(res http.ResponseWriter, req *http.Request) {
}
post := p()
- hook, ok := post.(content.Hookable)
+ hook, ok := post.(item.Hookable)
if !ok {
- log.Println("Type", t, "does not implement content.Hookable or embed content.Item.")
+ log.Println("Type", t, "does not implement item.Hookable or embed item.Item.")
res.WriteHeader(http.StatusBadRequest)
errView, err := Error400()
if err != nil {
@@ -1661,7 +1661,7 @@ func searchHandler(res http.ResponseWriter, req *http.Request) {
posts := db.ContentAll(t + specifier)
b := &bytes.Buffer{}
- p := content.Types[t]().(editor.Editable)
+ p := item.Types[t]().(editor.Editable)
html := `<div class="col s9 card">
<div class="card-content">
diff --git a/system/api/external.go b/system/api/external.go
index 0d1ea03..8112e29 100644
--- a/system/api/external.go
+++ b/system/api/external.go
@@ -7,9 +7,9 @@ import (
"strings"
"time"
- "github.com/bosssauce/ponzu/content"
"github.com/bosssauce/ponzu/system/admin/upload"
"github.com/bosssauce/ponzu/system/db"
+ "github.com/bosssauce/ponzu/system/item"
)
// Externalable accepts or rejects external POST requests to endpoints such as:
@@ -44,7 +44,7 @@ func externalContentHandler(res http.ResponseWriter, req *http.Request) {
return
}
- p, found := content.Types[t]
+ p, found := item.Types[t]
if !found {
log.Println("[External] attempt to submit unknown type:", t, "from:", req.RemoteAddr)
res.WriteHeader(http.StatusNotFound)
@@ -105,9 +105,9 @@ func externalContentHandler(res http.ResponseWriter, req *http.Request) {
return
}
- hook, ok := post.(content.Hookable)
+ hook, ok := post.(item.Hookable)
if !ok {
- log.Println("[External] error: Type", t, "does not implement content.Hookable or embed content.Item.")
+ log.Println("[External] error: Type", t, "does not implement item.Hookable or embed item.Item.")
res.WriteHeader(http.StatusBadRequest)
return
}
diff --git a/system/api/handlers.go b/system/api/handlers.go
index fae3ef6..1e2f1e2 100644
--- a/system/api/handlers.go
+++ b/system/api/handlers.go
@@ -8,14 +8,14 @@ import (
"strconv"
"strings"
- "github.com/bosssauce/ponzu/content"
"github.com/bosssauce/ponzu/system/api/analytics"
"github.com/bosssauce/ponzu/system/db"
+ "github.com/bosssauce/ponzu/system/item"
)
func typesHandler(res http.ResponseWriter, req *http.Request) {
var types = []string{}
- for t := range content.Types {
+ for t := range item.Types {
types = append(types, string(t))
}
@@ -36,7 +36,7 @@ func contentsHandler(res http.ResponseWriter, req *http.Request) {
return
}
- if _, ok := content.Types[t]; !ok {
+ if _, ok := item.Types[t]; !ok {
res.WriteHeader(http.StatusNotFound)
return
}
@@ -98,7 +98,7 @@ func contentHandler(res http.ResponseWriter, req *http.Request) {
return
}
- if _, ok := content.Types[t]; !ok {
+ if _, ok := item.Types[t]; !ok {
res.WriteHeader(http.StatusNotFound)
return
}
diff --git a/system/db/content.go b/system/db/content.go
index 3293ff4..535b601 100644
--- a/system/db/content.go
+++ b/system/db/content.go
@@ -10,7 +10,7 @@ import (
"strconv"
"strings"
- "github.com/bosssauce/ponzu/content"
+ "github.com/bosssauce/ponzu/system/item"
"github.com/boltdb/bolt"
"github.com/gorilla/schema"
@@ -418,7 +418,7 @@ func SortContent(namespace string) {
// decode each (json) into type to then sort
for i := range all {
j := all[i]
- post := content.Types[namespace]()
+ post := item.Types[namespace]()
err := json.Unmarshal(j, &post)
if err != nil {
@@ -426,7 +426,7 @@ func SortContent(namespace string) {
return
}
- posts = append(posts, post.(content.Sortable))
+ posts = append(posts, post.(item.Sortable))
}
// sort posts
@@ -467,7 +467,7 @@ func SortContent(namespace string) {
}
-type sortableContent []content.Sortable
+type sortableContent []item.Sortable
func (s sortableContent) Len() int {
return len(s)
@@ -483,9 +483,9 @@ func (s sortableContent) Swap(i, j int) {
func postToJSON(ns string, data url.Values) ([]byte, error) {
// find the content type and decode values into it
- t, ok := content.Types[ns]
+ t, ok := item.Types[ns]
if !ok {
- return nil, fmt.Errorf(content.ErrTypeNotRegistered, ns)
+ return nil, fmt.Errorf(item.ErrTypeNotRegistered, ns)
}
post := t()
@@ -500,7 +500,7 @@ func postToJSON(ns string, data url.Values) ([]byte, error) {
// if the content has no slug, and has no specifier, create a slug, check it
// for duplicates, and add it to our values
if data.Get("slug") == "" && data.Get("__specifier") == "" {
- slug, err := content.Slug(post.(content.Identifiable))
+ slug, err := item.Slug(post.(item.Identifiable))
if err != nil {
return nil, err
}
@@ -510,7 +510,7 @@ func postToJSON(ns string, data url.Values) ([]byte, error) {
return nil, err
}
- post.(content.Sluggable).SetSlug(slug)
+ post.(item.Sluggable).SetSlug(slug)
data.Set("slug", slug)
}
diff --git a/system/db/init.go b/system/db/init.go
index fa2c42e..9a0c3e5 100644
--- a/system/db/init.go
+++ b/system/db/init.go
@@ -4,8 +4,8 @@ import (
"encoding/json"
"log"
- "github.com/bosssauce/ponzu/content"
"github.com/bosssauce/ponzu/system/admin/config"
+ "github.com/bosssauce/ponzu/system/item"
"github.com/boltdb/bolt"
"github.com/nilslice/jwt"
@@ -32,7 +32,7 @@ func Init() {
err = store.Update(func(tx *bolt.Tx) error {
// initialize db with all content type buckets & sorted bucket for type
- for t := range content.Types {
+ for t := range item.Types {
_, err := tx.CreateBucketIfNotExists([]byte(t))
if err != nil {
return err
@@ -86,7 +86,7 @@ func Init() {
}
go func() {
- for t := range content.Types {
+ for t := range item.Types {
SortContent(t)
}
}()
diff --git a/content/item.go b/system/item/item.go
index 9ccd420..a813669 100644
--- a/content/item.go
+++ b/system/item/item.go
@@ -1,4 +1,4 @@
-package content
+package item
import (
"fmt"
diff --git a/content/types.go b/system/item/types.go
index 696d589..33e9ced 100644
--- a/content/types.go
+++ b/system/item/types.go
@@ -1,4 +1,4 @@
-package content
+package item
const (
// ErrTypeNotRegistered means content type isn't registered (not found in Types map)
@@ -9,7 +9,7 @@ Add this to the file which defines %[1]s{} in the 'content' package:
func init() {
- Types["%[1]s"] = func() interface{} { return new(%[1]s) }
+ item.Types["%[1]s"] = func() interface{} { return new(%[1]s) }
}