github.com/gnolang/gno@v0.0.0-20240520182011-228e9d0192ce/examples/gno.land/p/demo/dom/dom.gno (about) 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 5 package dom 6 7 import ( 8 "strconv" 9 10 "gno.land/p/demo/avl" 11 ) 12 13 type Plot struct { 14 Name string 15 Posts avl.Tree // postsCtr -> *Post 16 PostsCtr int 17 } 18 19 func (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 30 func (plot *Plot) String() string { 31 str := "# [plot] " + plot.Name + "\n" 32 if plot.Posts.Size() > 0 { 33 plot.Posts.Iterate("", "", func(key string, value interface{}) bool { 34 str += "\n" 35 str += value.(*Post).String() 36 return false 37 }) 38 } 39 return str 40 } 41 42 type Post struct { 43 Title string 44 Body string 45 Comments avl.Tree 46 } 47 48 func (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 interface{}) bool { 54 str += "\n" 55 str += value.(*Comment).String() 56 return false 57 }) 58 } 59 return str 60 } 61 62 type Comment struct { 63 Creator string 64 Body string 65 } 66 67 func (cmm Comment) String() string { 68 return cmm.Body + " - @" + cmm.Creator + "\n" 69 }