dom.gno

1.24 Kb ยท 69 lines
 1// XXX This is only used for testing in ./tests.
 2// Otherwise this package is deprecated.
 3// TODO: replace with a package that is supported, and delete this.
 4
 5package dom
 6
 7import (
 8	"strconv"
 9
10	"gno.land/p/demo/avl"
11)
12
13type Plot struct {
14	Name     string
15	Posts    avl.Tree // postsCtr -> *Post
16	PostsCtr int
17}
18
19func (plot *Plot) AddPost(title string, body string) {
20	ctr := plot.PostsCtr
21	plot.PostsCtr++
22	key := strconv.Itoa(ctr)
23	post := &Post{
24		Title: title,
25		Body:  body,
26	}
27	plot.Posts.Set(key, post)
28}
29
30func (plot *Plot) String() string {
31	str := "# [plot] " + plot.Name + "\n"
32	if plot.Posts.Size() > 0 {
33		plot.Posts.Iterate("", "", func(key string, value any) bool {
34			str += "\n"
35			str += value.(*Post).String()
36			return false
37		})
38	}
39	return str
40}
41
42type Post struct {
43	Title    string
44	Body     string
45	Comments avl.Tree
46}
47
48func (post *Post) String() string {
49	str := "## " + post.Title + "\n"
50	str += ""
51	str += post.Body
52	if post.Comments.Size() > 0 {
53		post.Comments.Iterate("", "", func(key string, value any) bool {
54			str += "\n"
55			str += value.(*Comment).String()
56			return false
57		})
58	}
59	return str
60}
61
62type Comment struct {
63	Creator string
64	Body    string
65}
66
67func (cmm Comment) String() string {
68	return cmm.Body + " - @" + cmm.Creator + "\n"
69}