1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-12-13 14:00:25 +00:00
mycorrhiza/shroom/init.go

34 lines
860 B
Go
Raw Normal View History

2021-02-20 14:03:54 +00:00
package shroom
import (
"errors"
"github.com/bouncepaw/mycorrhiza/hyphae"
"github.com/bouncepaw/mycorrhiza/views"
"github.com/bouncepaw/mycomarkup/v3/globals"
2021-02-20 14:03:54 +00:00
)
func init() {
2021-05-13 18:13:11 +00:00
globals.HyphaExists = func(hyphaName string) bool {
return hyphae.ByName(hyphaName).DoesExist()
2021-02-20 14:03:54 +00:00
}
2021-05-13 18:13:11 +00:00
globals.HyphaAccess = func(hyphaName string) (rawText, binaryBlock string, err error) {
if h := hyphae.ByName(hyphaName); h.DoesExist() {
2021-02-20 14:03:54 +00:00
rawText, err = FetchTextPart(h)
2022-02-04 11:00:38 +00:00
if h := h.(*hyphae.MediaHypha); h.Kind() == hyphae.HyphaMedia {
2021-09-06 17:46:34 +00:00
// the view is localized, but we can't pass it, so...
binaryBlock = views.AttachmentHTMLRaw(h)
2021-02-20 14:03:54 +00:00
}
} else {
2022-02-04 11:00:38 +00:00
err = errors.New("MediaHypha " + hyphaName + " does not exist")
2021-02-20 14:03:54 +00:00
}
return
}
2021-05-13 18:13:11 +00:00
globals.HyphaIterate = func(λ func(string)) {
2021-02-20 14:03:54 +00:00
for h := range hyphae.YieldExistingHyphae() {
λ(h.CanonicalName())
2021-02-20 14:03:54 +00:00
}
}
}