diff options
-rw-r--r-- | examples/docker/README.md | 10 | ||||
-rw-r--r-- | examples/docker/admin/cmd/ponzu/vendor/github.com/ponzu-cms/ponzu/content/song.go | 73 | ||||
-rw-r--r-- | examples/docker/admin/content/song.go | 73 |
3 files changed, 152 insertions, 4 deletions
diff --git a/examples/docker/README.md b/examples/docker/README.md index e46009a..bf9fb01 100644 --- a/examples/docker/README.md +++ b/examples/docker/README.md @@ -17,9 +17,12 @@ docker-compose build docker-compose start -d ``` -Visit the http://localhost:3000/admin to configure Ponzu. +#### Then follow these steps: +1. Visit the http://localhost:3000/admin to configure Ponzu. +2. Add several songs http://localhost:3000/admin/reviews +3. Visit http://localhost:3000/ to see the rest service accessed via AJAX -Stop the on containers: +Stop the containers: ``` docker-compose stop ``` @@ -44,7 +47,6 @@ docker run -v $(pwd)/admin:/go/src/project -it docker_admin # run a ponzu command ponzu generate content message title:"string" description:"string" - ``` -After the above your new `message.go` model is now available in your local filesystem. Use `docker-compose up -d` to see the new model in the admin. +After the above generate command `message.go` content type is now available in your local filesystem. Use `docker-compose build` then `docker-compose up -d` to see the new model in the admin. diff --git a/examples/docker/admin/cmd/ponzu/vendor/github.com/ponzu-cms/ponzu/content/song.go b/examples/docker/admin/cmd/ponzu/vendor/github.com/ponzu-cms/ponzu/content/song.go new file mode 100644 index 0000000..fa5e802 --- /dev/null +++ b/examples/docker/admin/cmd/ponzu/vendor/github.com/ponzu-cms/ponzu/content/song.go @@ -0,0 +1,73 @@ +package content + +import ( + "fmt" + + "github.com/ponzu-cms/ponzu/management/editor" + "github.com/ponzu-cms/ponzu/system/item" +) + +type Song struct { + item.Item + + Title string `json:"title"` + Artist string `json:"artist"` + Rating int `json:"rating"` + Opinion string `json:"opinion"` + SpotifyUrl string `json:"spotify_url"` +} + +// MarshalEditor writes a buffer of html to edit a Song within the CMS +// and implements editor.Editable +func (s *Song) MarshalEditor() ([]byte, error) { + view, err := editor.Form(s, + // Take note that the first argument to these Input-like functions + // is the string version of each Song field, and must follow + // this pattern for auto-decoding and auto-encoding reasons: + editor.Field{ + View: editor.Input("Title", s, map[string]string{ + "label": "Title", + "type": "text", + "placeholder": "Enter the Title here", + }), + }, + editor.Field{ + View: editor.Input("Artist", s, map[string]string{ + "label": "Artist", + "type": "text", + "placeholder": "Enter the Artist here", + }), + }, + editor.Field{ + View: editor.Input("Rating", s, map[string]string{ + "label": "Rating", + "type": "text", + "placeholder": "Enter the Rating here", + }), + }, + editor.Field{ + View: editor.Input("Opinion", s, map[string]string{ + "label": "Opinion", + "type": "text", + "placeholder": "Enter the Opinion here", + }), + }, + editor.Field{ + View: editor.Input("SpotifyUrl", s, map[string]string{ + "label": "SpotifyUrl", + "type": "text", + "placeholder": "Enter the SpotifyUrl here", + }), + }, + ) + + if err != nil { + return nil, fmt.Errorf("Failed to render Song editor view: %s", err.Error()) + } + + return view, nil +} + +func init() { + item.Types["Song"] = func() interface{} { return new(Song) } +} diff --git a/examples/docker/admin/content/song.go b/examples/docker/admin/content/song.go new file mode 100644 index 0000000..fa5e802 --- /dev/null +++ b/examples/docker/admin/content/song.go @@ -0,0 +1,73 @@ +package content + +import ( + "fmt" + + "github.com/ponzu-cms/ponzu/management/editor" + "github.com/ponzu-cms/ponzu/system/item" +) + +type Song struct { + item.Item + + Title string `json:"title"` + Artist string `json:"artist"` + Rating int `json:"rating"` + Opinion string `json:"opinion"` + SpotifyUrl string `json:"spotify_url"` +} + +// MarshalEditor writes a buffer of html to edit a Song within the CMS +// and implements editor.Editable +func (s *Song) MarshalEditor() ([]byte, error) { + view, err := editor.Form(s, + // Take note that the first argument to these Input-like functions + // is the string version of each Song field, and must follow + // this pattern for auto-decoding and auto-encoding reasons: + editor.Field{ + View: editor.Input("Title", s, map[string]string{ + "label": "Title", + "type": "text", + "placeholder": "Enter the Title here", + }), + }, + editor.Field{ + View: editor.Input("Artist", s, map[string]string{ + "label": "Artist", + "type": "text", + "placeholder": "Enter the Artist here", + }), + }, + editor.Field{ + View: editor.Input("Rating", s, map[string]string{ + "label": "Rating", + "type": "text", + "placeholder": "Enter the Rating here", + }), + }, + editor.Field{ + View: editor.Input("Opinion", s, map[string]string{ + "label": "Opinion", + "type": "text", + "placeholder": "Enter the Opinion here", + }), + }, + editor.Field{ + View: editor.Input("SpotifyUrl", s, map[string]string{ + "label": "SpotifyUrl", + "type": "text", + "placeholder": "Enter the SpotifyUrl here", + }), + }, + ) + + if err != nil { + return nil, fmt.Errorf("Failed to render Song editor view: %s", err.Error()) + } + + return view, nil +} + +func init() { + item.Types["Song"] = func() interface{} { return new(Song) } +} |