mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2024-10-30 03:36:16 +00:00
40 lines
951 B
Go
40 lines
951 B
Go
package shroom
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/bouncepaw/mycorrhiza/hyphae"
|
|
"github.com/bouncepaw/mycorrhiza/views"
|
|
|
|
"github.com/bouncepaw/mycomarkup/v3/globals"
|
|
)
|
|
|
|
func init() {
|
|
globals.HyphaExists = func(hyphaName string) bool {
|
|
switch hyphae.ByName(hyphaName).(type) {
|
|
case *hyphae.EmptyHypha:
|
|
return false
|
|
default:
|
|
return true
|
|
}
|
|
}
|
|
globals.HyphaAccess = func(hyphaName string) (rawText, binaryBlock string, err error) {
|
|
switch h := hyphae.ByName(hyphaName).(type) {
|
|
case *hyphae.EmptyHypha:
|
|
err = errors.New("Hypha " + hyphaName + " does not exist")
|
|
default:
|
|
rawText, err = FetchTextPart(h)
|
|
if h := h.(*hyphae.NonEmptyHypha); h.Kind() == hyphae.HyphaMedia {
|
|
// the view is localized, but we can't pass it, so...
|
|
binaryBlock = views.AttachmentHTMLRaw(h)
|
|
}
|
|
}
|
|
return
|
|
}
|
|
globals.HyphaIterate = func(λ func(string)) {
|
|
for h := range hyphae.YieldExistingHyphae() {
|
|
λ(h.CanonicalName())
|
|
}
|
|
}
|
|
}
|