ponzu-cms / ponzu

Headless CMS with automatic JSON API. Featuring auto-HTTPS from Let's Encrypt, HTTP/2 Server Push, and flexible server framework written in Go.
https://docs.ponzu-cms.org
BSD 3-Clause "New" or "Revised" License
5.7k stars 385 forks source link

Docu request: Kitchen sink demo #106

Closed fbaube closed 7 years ago

fbaube commented 7 years ago

It would be great to have a "kitchen sink" demo that shows all available widgets. It would consist of a long "ponzu gen" command plus some additional instructions to modify the generated files to get additional widget types, for example a Richtext editor widget.

fbaube commented 7 years ago

I have this in content/myfields.go:

type Myfields struct {
        item.Item
        Mytitle      string   `json:"mytitle"`
        Myrich1      string   `json:"myrich1"`
        Myrich2      string   `json:"myrich2"`
        Myrich3      string   `json:"myrich3"`
        Mystringlist []string `json:"mystringlist"`
        Mycheckbox   string   `json:"mycheckbox"`
        Myfile       string   `json:"myfile"`
        Myselect     string   `json:"myselect"`
        Mytags       string   `json:"mytags"`
        Mytextarea   string   `json:"mytextarea"`
        Mytimestamp  string   `json:"mytimestamp"`
}

I assume I have some incorrect values in the code block above (all the "string" entries), but it's generating a UI without any visible errors (except, there is no UI widget generated for the "[]string" item).

I'll keep experimenting :)

nilslice commented 7 years ago

Hey - I'm traveling back from vacation, and am just now seeing your comments.

I have some new code to release that will help, and am planning to do a series of videos once the APIs are locked down.

All UI is done in the MarshalEditor() func, would you be able to share that?

On Sun, Apr 2, 2017 at 08:00 F.Baube notifications@github.com wrote:

I have this in content/myfields.go:

type Myfields struct { item.Item Mytitle string json:"mytitle" Myrich1 string json:"myrich1" Myrich2 string json:"myrich2" Myrich3 string json:"myrich3" Mystringlist []string json:"mystringlist" Mycheckbox string json:"mycheckbox" Myfile string json:"myfile" Myselect string json:"myselect" Mytags string json:"mytags" Mytextarea string json:"mytextarea" Mytimestamp string json:"mytimestamp" }

I assume I have some incorrect values in the code block above (all the "string" entries), but it's generating a UI without any visible errors (except, there is no UI widget generated for the "[]string" item).

I'll keep experimenting :)

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/ponzu-cms/ponzu/issues/106#issuecomment-290981935, or mute the thread https://github.com/notifications/unsubscribe-auth/AHK1S1ygRKlWslyk1PSFQ_z49jNNMok2ks5rr43JgaJpZM4Ms7T3 .

fbaube commented 7 years ago

Like, just paste in the whole thing ?

nilslice commented 7 years ago

The more the merrier :)

On Sun, Apr 2, 2017 at 08:35 F.Baube notifications@github.com wrote:

Like, just paste in the whole thing ?

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/ponzu-cms/ponzu/issues/106#issuecomment-290983656, or mute the thread https://github.com/notifications/unsubscribe-auth/AHK1S3AJpC823bOpSKcC0SM84t2FMvbTks5rr5YAgaJpZM4Ms7T3 .

fbaube commented 7 years ago

Here's my content/myfields.go. Note that I did not use "ponzu gen" for this; I hacked it custom.

myfields.go.txt

nilslice commented 7 years ago

I don't see an editor.Field for your Mystrunglist []string - is this the one that has no UI?

On Sun, Apr 2, 2017 at 08:39 F.Baube notifications@github.com wrote:

Here's my content/myfields.go. Note that I did not use "ponzu gen" for this; I hacked it custom.

myfields.go.txt https://github.com/ponzu-cms/ponzu/files/888364/myfields.go.txt

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/ponzu-cms/ponzu/issues/106#issuecomment-290983880, or mute the thread https://github.com/notifications/unsubscribe-auth/AHK1S5F2xSm4Wk8HzSdVVSAxqBw91Jmqks5rr5cLgaJpZM4Ms7T3 .

fbaube commented 7 years ago

Ah, right you are, I added an entry and it appeared. But the widget only displays as a single text field, so are the list entries separated by whitespace ?

nilslice commented 7 years ago

Glad it worked!

Try using an editor.InputRepeater func instead of an editor.Input

Also, keep in mind that you don't necessarily need to use the HTML helper funcs from the editor package - though they are specifically tuned to be useful for the CMS. Any []byte will be rendered as long as you append them to the return value of MarshalEditor, so the sky's the limit ;)

fbaube commented 7 years ago

The new "gen c" syntax works nicely. After the following command, and "ponzu build", I only had to go in and change the editor for "mystringlist" from Input(..) to InputRepeater(..).The UI looks fine; I'll exercise it next. Now I'm curious how it all integrates with Buffalo, mainly bcos Buffalo's DB access layer is based on "sqlx"; is there any chance of that video demo happening soon ?

ponzu gen c myfields \ mytitle:string:text \ mydesc:string:textarea \ myrich1:string:richtext \ myrich2:string:richtext \ myrich3:string:richtext \ mystringlist:"[]string" \ mycheckbox:string:checkbox \ myfile:string:file \ myselect:string:select

nilslice commented 7 years ago

@fbaube - very glad to hear it is working for you now.

In order to use Ponzu with Buffalo or any other web framework, you need to think of Ponzu as the data layer (DB/backend/etc) and Buffalo as the frontend. You will make HTTP calls to fetch your Ponzu CMS data from the controllers/models in the frontend, and use that JSON data to populate your views with content or conversely send data to Ponzu from Buffalo in a controller/model via the same HTTP API.

Since your Ponzu content types are all exported from the content package, you can easily re-use them in any other Go app, so unmarshaling your JSON from a Ponzu API response back into Go structs is simple: import the content package from your Ponzu project and use your content types.

At the moment, I do not have plans to make a video for Ponzu+Buffalo specifically, but I am working on a set of videos to show how one might use Ponzu with a smaller web framework (maybe in Go, maybe not) or just net/http to make a simple frontend that talks to Ponzu over HTTP.

I believe the GopherCon website is the current best available combination of Ponzu+Buffalo:

You can see how they import the Ponzu content types from within the Buffalo models package: https://github.com/gopheracademy/gcon/blob/master/models/workshop.go#L6 and @bketelsen wrote an optional, but super useful cache & content API generator to work with Ponzu data: https://github.com/bketelsen/ponzi https://github.com/bketelsen/ponzigen

That's about all I can offer from a "how to use" Ponzu+Buffalo, so I hope it helps.. Both the #buffalo and #ponzu channels on the Gopher's Slack are pretty active with people who can help. So I'd suggest that those be the next places you check for more specific questions. I'm happy to help, but don't know much about Buffalo specifically.

Steve

ghost commented 7 years ago

thats all. looks really useful. Will give it a whirl now

nilslice commented 7 years ago

@fbaube - I finally have a walk-through introduction to Ponzu recorded: https://www.youtube.com/watch?v=T_1ncPoLgrg

I hope its helpful! Feel free to comment here after I close the issue.

iharsuvorau commented 6 years ago

@nilslice the video is very helpful to start and get the overall understanding

but it seems that it is worth to have the 'kitchen sink' example somewhere written in the docs, because it's not very convenient to navigate the video to find, for example, the checkbox usage example, it would be better to work with searchable text

by the way, I've noticed that the General Usage command example:

$ ponzu gen content review title:"string" body:"string":richtext rating:"int"

produces:

type Review struct {
    item.Item

    Title  string   `json:"title"`
    Body   string   `json:"body"`
    Rating int      `json:"rating"`
    Tags   []string `json:"tags"`
}

The field Tags wasn't mentioned in the command but exists in the struct. It seems like a little bit confusing.

nilslice commented 6 years ago

@iharsuvorau - thanks for calling that out, I can definitely edit it unless you want to open a PR to remove the Tags field from the struct in the docs?

iharsuvorau commented 6 years ago

@nilslice I'm trying to push but have the same error as in #192:

$  git push origin ponzu-dev
remote: Permission to ponzu-cms/ponzu.git denied to iharsuvorau.
fatal: unable to access 'https://github.com/ponzu-cms/ponzu/': The requested URL returned error: 403

.git/config:

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
    ignorecase = true
    precomposeunicode = true
[remote "origin"]
    url = https://github.com/ponzu-cms/ponzu
    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
    remote = origin
    merge = refs/heads/master
[branch "ponzu-dev"]
    remote = origin
    merge = refs/heads/ponzu-dev
nilslice commented 6 years ago

@iharsuvorau - thank you! you'll need to make a pull request on the Github repo page itself, not through Git. Fork the repo, clone it and checkout a ponzu-dev branch, make your changes locally, then push to your repo. Then open a PR to ponzu, to merge into the ponzu-dev branch from your ponzu-dev branch.