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 {
|
2020-06-16 18:35:52 +00:00
|
|
|
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
|
2020-06-16 18:35:52 +00:00
|
|
|
parentName string
|
2020-06-12 16:22:02 +00:00
|
|
|
}
|
|
|
|
|
2020-06-16 18:35:52 +00:00
|
|
|
func (h *Hypha) AddChild(childName string) {
|
|
|
|
h.ChildrenNames = append(h.ChildrenNames, childName)
|
2020-06-12 16:22:02 +00:00
|
|
|
}
|
|
|
|
|
2020-06-16 18:35:52 +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
|
|
|
}
|
2020-06-16 18:35:52 +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
|
|
|
}
|
|
|
|
|
2020-06-16 18:35:52 +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
|
|
|
}
|
|
|
|
}
|
2020-06-16 18:35:52 +00:00
|
|
|
return strconv.Itoa(largest)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *Hypha) ParentName() string {
|
|
|
|
return h.parentName
|
2020-06-12 16:22:02 +00:00
|
|
|
}
|