1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-12-12 13:30:26 +00:00
mycorrhiza/hypha.go

53 lines
1.0 KiB
Go
Raw Normal View History

2020-06-12 16:22:02 +00:00
package main
import (
"fmt"
2020-06-13 11:18:11 +00:00
"strconv"
2020-06-12 16:22:02 +00:00
)
type Hypha struct {
FullName string
Path string
ViewCount int `json:"views"`
Deleted bool `json:"deleted"`
Revisions map[string]*Revision `json:"revisions"`
2020-06-12 16:22:02 +00:00
ChildrenNames []string
parentName string
2020-06-12 16:22:02 +00:00
}
func (h *Hypha) AddChild(childName string) {
h.ChildrenNames = append(h.ChildrenNames, childName)
2020-06-12 16:22:02 +00:00
}
// Used with action=zen|view
func (h *Hypha) AsHtml(hyphae map[string]*Hypha, rev string) (string, error) {
if "0" == rev {
rev = h.NewestRevision()
2020-06-13 11:18:11 +00:00
}
r, ok := h.Revisions[rev]
if !ok {
return "", fmt.Errorf("Hypha %v has no such revision: %v", h.FullName, rev)
}
html, err := r.AsHtml(hyphae)
return html, err
2020-06-12 16:22:02 +00:00
}
func (h *Hypha) Name() string {
return h.FullName
}
func (h *Hypha) NewestRevision() string {
var largest int
for k, _ := range h.Revisions {
rev, _ := strconv.Atoi(k)
if rev > largest {
largest = rev
2020-06-13 11:18:11 +00:00
}
}
return strconv.Itoa(largest)
}
func (h *Hypha) ParentName() string {
return h.parentName
2020-06-12 16:22:02 +00:00
}