Skip to content

Commit

Permalink
Merge pull request #29 from xushiwei/q
Browse files Browse the repository at this point in the history
edit
  • Loading branch information
xushiwei committed Jan 10, 2024
2 parents 0f88a42 + 4a1c497 commit 37dc524
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 23 deletions.
19 changes: 15 additions & 4 deletions cmd/gopcomm/community_yap.gox
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ get "/p/:id", ctx => {
ctx.yap "article", {
"ID": id,
"Title": article.Title,
"Body": string(html),
"Body": html,
}
}
get "/", ctx => {
Expand All @@ -24,10 +24,21 @@ get "/", ctx => {
}
}
get "/edit", ctx => {
// canEditable
ctx.yap "edit", {
"ID": ctx.param("id"),
uid := ""
id := ctx.param("id")
doc := {
"ID": id,
}
if id != "" {
if editable, _ := community.canEditable(nil, uid, id); !editable {
// TODO: can't edit this article
return
}
article, _ := community.article(nil, id)
doc["Title"] = article.Title
doc["Content"] = article.Content
}
ctx.yap "edit", doc
}
post "/commit", ctx => {
// ...
Expand Down
34 changes: 28 additions & 6 deletions cmd/gopcomm/gop_autogen.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func (this *community) MainEntry() {
//line cmd/gopcomm/community_yap.gox:13:1
html, _ := markdown.Render(article.Content)
//line cmd/gopcomm/community_yap.gox:14:1
ctx.Yap__1("article", map[string]string{"ID": id, "Title": article.Title, "Body": string(html)})
ctx.Yap__1("article", map[string]string{"ID": id, "Title": article.Title, "Body": html})
})
//line cmd/gopcomm/community_yap.gox:20:1
this.Get("/", func(ctx *yap.Context) {
Expand All @@ -32,17 +32,39 @@ func (this *community) MainEntry() {
})
//line cmd/gopcomm/community_yap.gox:26:1
this.Get("/edit", func(ctx *yap.Context) {
//line cmd/gopcomm/community_yap.gox:27:1
uid := ""
//line cmd/gopcomm/community_yap.gox:28:1
ctx.Yap__1("edit", map[string]string{"ID": ctx.Param("id")})
})
id := ctx.Param("id")
//line cmd/gopcomm/community_yap.gox:29:1
doc := map[string]string{"ID": id}
//line cmd/gopcomm/community_yap.gox:32:1
if id != "" {
//line cmd/gopcomm/community_yap.gox:33:1
if
//line cmd/gopcomm/community_yap.gox:33:1
editable, _ := this.community.CanEditable(nil, uid, id); !editable {
//line cmd/gopcomm/community_yap.gox:35:1
return
}
//line cmd/gopcomm/community_yap.gox:37:1
article, _ := this.community.Article(nil, id)
//line cmd/gopcomm/community_yap.gox:38:1
doc["Title"] = article.Title
//line cmd/gopcomm/community_yap.gox:39:1
doc["Content"] = article.Content
}
//line cmd/gopcomm/community_yap.gox:41:1
ctx.Yap__1("edit", doc)
})
//line cmd/gopcomm/community_yap.gox:43:1
this.Post("/commit", func(ctx *yap.Context) {
})
//line cmd/gopcomm/community_yap.gox:36:1
//line cmd/gopcomm/community_yap.gox:47:1
config := &core.Config{}
//line cmd/gopcomm/community_yap.gox:37:1
//line cmd/gopcomm/community_yap.gox:48:1
this.community, _ = core.New(config)
//line cmd/gopcomm/community_yap.gox:39:1
//line cmd/gopcomm/community_yap.gox:50:1
this.Run__1(":8080")
}
func main() {
Expand Down
7 changes: 6 additions & 1 deletion cmd/gopcomm/yap/edit_yap.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
<meta charset="utf-8"/>
</head>
<body>
Edit {{.ID}}
<form action="/commit" method="post">
<input type="hidden" name="id" value="{{.ID}}">
<p><input type="text" name="title" value="{{.Title}}"></p>
<p><textarea name="content" rows="10" cols="30">{{.Content}}</textarea></p>
<p><input type="submit" value="Submit"></p>
</form>
</body>
</html>
6 changes: 3 additions & 3 deletions internal/core/community.gop
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type ArticleEntry struct {

type Article struct {
ArticleEntry
Content []byte // in markdown
Content string // in markdown
}

type Community struct {
Expand All @@ -64,7 +64,7 @@ func (p *Community) Article(ctx context.Context, id string) (article *Article, e
ID: id,
Title: "Title",
},
[]byte(contentSummary),
contentSummary,
}
return
}
Expand All @@ -73,7 +73,7 @@ func (p *Community) Article(ctx context.Context, id string) (article *Article, e

// CanEditable
func (p *Community) CanEditable(ctx context.Context, uid, id string) (editable bool, err error) {
return
return true, nil
}

// PutArticle adds new article (ID == "") or edits an existing article (ID != "").
Expand Down
15 changes: 8 additions & 7 deletions internal/core/gop_autogen.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type ArticleEntry struct {
}
type Article struct {
ArticleEntry
Content []byte
Content string
}
type Community struct {
}
Expand All @@ -41,7 +41,7 @@ func (p *Community) Article(ctx context.Context, id string) (article *Article, e
//line internal/core/community.gop:61:1
if id == "123" {
//line internal/core/community.gop:62:1
article = &Article{ArticleEntry{ID: id, Title: "Title"}, []byte(contentSummary)}
article = &Article{ArticleEntry{ID: id, Title: "Title"}, contentSummary}
//line internal/core/community.gop:69:1
return
}
Expand All @@ -53,7 +53,7 @@ func (p *Community) Article(ctx context.Context, id string) (article *Article, e
//line internal/core/community.gop:75:1
func (p *Community) CanEditable(ctx context.Context, uid string, id string) (editable bool, err error) {
//line internal/core/community.gop:76:1
return
return true, nil
}
// PutArticle adds new article (ID == "") or edits an existing article (ID != "").
//
Expand Down Expand Up @@ -85,16 +85,17 @@ func (p *Community) ListArticle(ctx context.Context, from string, limit int) (it
//
//line internal/core/media.gop:6:1
func (p *Community) PutMedia(ctx context.Context, uid string, media []byte) (id string, err error) {
//line internal/core/media.gop:7:1
return
}
//line internal/core/media.gop:9:1
func (p *Community) DeleteMedia(ctx context.Context, uid string, id string) (err error) {
//line internal/core/media.gop:10:1
func (p *Community) DeleteMedia(ctx context.Context, uid string, id string) (err error) {
//line internal/core/media.gop:11:1
return
}
//line internal/core/media.gop:13:1
func (p *Community) MediaURL(id string) (url string) {
//line internal/core/media.gop:14:1
func (p *Community) MediaURL(id string) (url string) {
//line internal/core/media.gop:15:1
return
}
//line internal/core/community.gop:48:1
Expand Down
2 changes: 1 addition & 1 deletion markdown/gop_autogen.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package markdown
// Render renders a markdown text into html.
//
//line markdown/render.gop:20:1
func Render(md []byte) (html []byte, err error) {
func Render(md string) (html string, err error) {
//line markdown/render.gop:21:1
return md, nil
}
2 changes: 1 addition & 1 deletion markdown/render.gop
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
package markdown

// Render renders a markdown text into html.
func Render(md []byte) (html []byte, err error) {
func Render(md string) (html string, err error) {
return md, nil
}

0 comments on commit 37dc524

Please sign in to comment.