1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2025-03-12 14:38:20 +00:00
mycorrhiza/shroom/init.go

34 lines
794 B
Go
Raw Normal View History

2021-02-20 19:03:54 +05:00
package shroom
import (
"errors"
"github.com/bouncepaw/mycorrhiza/hyphae"
"github.com/bouncepaw/mycorrhiza/views"
"github.com/bouncepaw/mycomarkup/v2/globals"
2021-02-20 19:03:54 +05:00
)
func init() {
2021-05-13 23:13:11 +05:00
globals.HyphaExists = func(hyphaName string) bool {
2021-02-20 19:03:54 +05:00
return hyphae.ByName(hyphaName).Exists
}
2021-05-13 23:13:11 +05:00
globals.HyphaAccess = func(hyphaName string) (rawText, binaryBlock string, err error) {
2021-02-20 19:03:54 +05:00
if h := hyphae.ByName(hyphaName); h.Exists {
rawText, err = FetchTextPart(h)
if h.BinaryPath != "" {
2021-09-07 01:46:34 +08:00
// the view is localized, but we can't pass it, so...
binaryBlock = views.AttachmentHTMLRaw(h)
2021-02-20 19:03:54 +05:00
}
} else {
err = errors.New("Hypha " + hyphaName + " does not exist")
}
return
}
2021-05-13 23:13:11 +05:00
globals.HyphaIterate = func(λ func(string)) {
2021-02-20 19:03:54 +05:00
for h := range hyphae.YieldExistingHyphae() {
λ(h.Name)
}
}
}