github.com/gnolang/gno@v0.0.0-20240520182011-228e9d0192ce/examples/gno.land/r/demo/groups/render.gno (about)

     1  package groups
     2  
     3  import (
     4  	"strings"
     5  )
     6  
     7  //----------------------------------------
     8  // Render functions
     9  
    10  func RenderGroup(gid GroupID) string {
    11  	group := getGroup(gid)
    12  	if group == nil {
    13  		return "missing Group"
    14  	}
    15  	return group.RenderGroup()
    16  }
    17  
    18  func Render(path string) string {
    19  	if path == "" {
    20  		str := "List of all Groups:\n\n"
    21  		gGroups.Iterate("", "", func(key string, value interface{}) bool {
    22  			group := value.(*Group)
    23  			str += " * [" + group.name + "](" + group.url + ")\n"
    24  			return false
    25  		})
    26  		return str
    27  	}
    28  	parts := strings.Split(path, "/")
    29  	if len(parts) == 1 {
    30  		// /r/Groups:Group_NAME
    31  		name := parts[0]
    32  		groupI, exists := gGroupsByName.Get(name)
    33  		if !exists {
    34  			return "Group does not exist: " + name
    35  		}
    36  		return groupI.(*Group).RenderGroup()
    37  	} else {
    38  		return "unrecognized path " + path
    39  	}
    40  }