registry.mdin: /docs/internal/components/
import (
"path/filepath"
"runtime"
"strings"
"github.com/stanistan/veun"
)
We need a way to embed the components in the actual page.
A static map and an init hook is enough for this, and our doc handler can use this to see if there's any component to actually render in the page.
var registry = map[string]Views{}
func show(vs ...IComponent) {
_, file, _, ok := runtime.Caller(1)
if !ok {
panic("no caller")
} else {
file = strings.TrimSuffix(filepath.Base(file), ".generated.go")
}
registry[file+".md"] = Views(vs)
}
Access
Callers should use ForURL
to get a view based on the key.
func ForFullURL(url string) (veun.AsView, bool) {
return ForURL(strings.TrimPrefix(url, "/docs/internal/components/"))
}
func ForURL(url string) (veun.AsView, bool) {
v, ok := registry[url]
return v, ok
}