2021-02-20 14:03:54 +00:00
|
|
|
package shroom
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
|
|
|
|
"github.com/bouncepaw/mycorrhiza/hyphae"
|
2021-02-20 15:48:51 +00:00
|
|
|
"github.com/bouncepaw/mycorrhiza/views"
|
2021-05-12 13:34:24 +00:00
|
|
|
|
2021-10-05 20:10:28 +00:00
|
|
|
"github.com/bouncepaw/mycomarkup/v3/globals"
|
2021-02-20 14:03:54 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2022-02-19 08:26:38 +00:00
|
|
|
// TODO: clean this complete and utter mess
|
2021-05-13 18:13:11 +00:00
|
|
|
globals.HyphaExists = func(hyphaName string) bool {
|
2022-02-04 14:56:28 +00:00
|
|
|
switch hyphae.ByName(hyphaName).(type) {
|
|
|
|
case *hyphae.EmptyHypha:
|
|
|
|
return false
|
|
|
|
default:
|
|
|
|
return true
|
|
|
|
}
|
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) {
|
2022-02-04 14:56:28 +00:00
|
|
|
switch h := hyphae.ByName(hyphaName).(type) {
|
|
|
|
case *hyphae.EmptyHypha:
|
|
|
|
err = errors.New("Hypha " + hyphaName + " does not exist")
|
2022-02-19 08:26:38 +00:00
|
|
|
case *hyphae.TextualHypha:
|
|
|
|
rawText, err = FetchTextFile(h)
|
|
|
|
case *hyphae.MediaHypha:
|
|
|
|
rawText, err = FetchTextFile(h)
|
|
|
|
binaryBlock = views.AttachmentHTMLRaw(h)
|
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() {
|
2022-02-03 21:47:36 +00:00
|
|
|
λ(h.CanonicalName())
|
2021-02-20 14:03:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|