Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: portal loop's main contracts and gnoweb improvements #1176

Merged
merged 23 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 35 additions & 16 deletions examples/gno.land/p/demo/blog/blog.gno
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,28 @@ import (
)

type Blog struct {
Title string
Prefix string // i.e. r/gnoland/blog:
Posts avl.Tree // slug -> Post
Title string
Prefix string // i.e. r/gnoland/blog:
Posts avl.Tree // slug -> Post
NoBreadcrumb bool
}

func (b Blog) RenderLastPostsWidget(limit int) string {
output := ""
i := 0
b.Posts.Iterate("", "", func(key string, value interface{}) bool {
p := value.(*Post)
output += ufmt.Sprintf("- [%s](%s)\n", p.Title, p.URL())
i++
return i >= limit
})
return output
}

func (b Blog) RenderHome(res *mux.ResponseWriter, req *mux.Request) {
res.Write(breadcrumb([]string{b.Title}))
if !b.NoBreadcrumb {
res.Write(breadcrumb([]string{b.Title}))
}

if b.Posts.Size() == 0 {
res.Write("No posts.")
Expand Down Expand Up @@ -47,12 +62,14 @@ func (b Blog) RenderPost(res *mux.ResponseWriter, req *mux.Request) {
}
p := post.(*Post)

breadStr := breadcrumb([]string{
ufmt.Sprintf("[%s](%s)", b.Title, b.Prefix),
"p",
p.Title,
})
res.Write(breadStr)
if !b.NoBreadcrumb {
breadStr := breadcrumb([]string{
ufmt.Sprintf("[%s](%s)", b.Title, b.Prefix),
"p",
p.Title,
})
res.Write(breadStr)
}

// output += ufmt.Sprintf("## [%s](%s)\n", p.Title, p.URL())
res.Write(p.Body + "\n\n")
Expand All @@ -75,12 +92,14 @@ func (b Blog) RenderTag(res *mux.ResponseWriter, req *mux.Request) {
return
}

breadStr := breadcrumb([]string{
ufmt.Sprintf("[%s](%s)", b.Title, b.Prefix),
"t",
slug,
})
res.Write(breadStr)
if !b.NoBreadcrumb {
breadStr := breadcrumb([]string{
ufmt.Sprintf("[%s](%s)", b.Title, b.Prefix),
"t",
slug,
})
res.Write(breadStr)
}

nb := 0
b.Posts.Iterate("", "", func(key string, value interface{}) bool {
Expand Down
44 changes: 43 additions & 1 deletion examples/gno.land/p/demo/ui/ui.gno
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package ui

import "strings"
import (
"strconv"
"strings"
)

type DOM struct {
// metadata
Expand Down Expand Up @@ -56,6 +59,17 @@ func (dom DOM) String() string {
return output
}

type Jumbotron []DomStringer

func (j Jumbotron) String(dom DOM) string {
output := `<div class="jumbotron">` + "\n\n"
for _, elem := range j {
output += elem.String(dom) + "\n"
}
output += `</div><!-- /jumbotron -->` + "\n"
return output
}

// XXX: rename Element to Div?
type Element []DomStringer

Expand Down Expand Up @@ -88,6 +102,26 @@ func (b Breadcrumb) String(dom DOM) string {
return output
}

type Columns struct {
MaxWidth int
Columns []Element
}

func (c *Columns) Append(elems ...Element) {
c.Columns = append(c.Columns, elems...)
}

func (c Columns) String(dom DOM) string {
output := `<div class="columns-` + strconv.Itoa(c.MaxWidth) + `">` + "\n"
for _, entry := range c.Columns {
output += `<div class="column">` + "\n\n"
output += entry.String(dom)
output += "</div><!-- /column-->\n"
}
output += "</div><!-- /columns-" + strconv.Itoa(c.MaxWidth) + " -->\n"
return output
}

type Link struct {
Text string
Path string
Expand All @@ -104,8 +138,14 @@ func (l Link) String(dom DOM) string {
case l.Path != "" && l.URL != "":
panic("a link should have a path or a URL, not both.")
case l.Path != "":
if l.Text == "" {
l.Text = l.Path
}
url = dom.Prefix + l.Path
case l.URL != "":
if l.Text == "" {
l.Text = l.URL
}
url = l.URL
}

Expand Down Expand Up @@ -151,6 +191,7 @@ type (
Italic string
Code string
Paragraph string
Quote string
HR struct{}
)

Expand All @@ -160,6 +201,7 @@ func (text H3) String(_ DOM) string { return "### " + string(text) + "\n"
func (text H4) String(_ DOM) string { return "#### " + string(text) + "\n" }
func (text H5) String(_ DOM) string { return "##### " + string(text) + "\n" }
func (text H6) String(_ DOM) string { return "###### " + string(text) + "\n" }
func (text Quote) String(_ DOM) string { return "> " + string(text) + "\n" }
func (text Bold) String(_ DOM) string { return "**" + string(text) + "**" }
func (text Italic) String(_ DOM) string { return "_" + string(text) + "_" }
func (text Paragraph) String(_ DOM) string { return "\n" + string(text) + "\n" }
Expand Down
4 changes: 4 additions & 0 deletions examples/gno.land/r/gnoland/blog/gnoblog.gno
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ func AddComment(postSlug, comment string) {
func Render(path string) string {
return b.Render(path)
}

func RenderLastPostsWidget(limit int) string {
return b.RenderLastPostsWidget(limit)
}
8 changes: 8 additions & 0 deletions examples/gno.land/r/gnoland/home/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module gno.land/r/gnoland/home

require (
"gno.land/r/gnoland/blog" v0.0.0-latest
"gno.land/p/demo/ufmt" v0.0.0-latest
"gno.land/p/demo/avl" v0.0.0-latest
"gno.land/p/demo/ui" v0.0.0-latest
)
Loading
Loading