render.gno

0.80 Kb ยท 40 lines
 1package groups
 2
 3import (
 4	"strings"
 5)
 6
 7//----------------------------------------
 8// Render functions
 9
10func RenderGroup(gid GroupID) string {
11	group := getGroup(gid)
12	if group == nil {
13		return "missing Group"
14	}
15	return group.RenderGroup()
16}
17
18func 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/demo/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}