tpl: Misco GoDoc improvements

This commit is contained in:
Bjørn Erik Pedersen 2022-11-29 11:38:21 +01:00
parent dc44bca963
commit 7d5e3ab8a8
3 changed files with 20 additions and 3 deletions

View file

@ -59,11 +59,12 @@ func (d goatDiagram) Height() int {
return d.d.Height
}
type Diagrams struct {
// Namespace provides template functions for the diagrams namespace.
type Namespace struct {
d *deps.Deps
}
func (d *Diagrams) Goat(v any) SVGDiagram {
func (d *Namespace) Goat(v any) SVGDiagram {
var r io.Reader
switch vv := v.(type) {

View file

@ -22,7 +22,7 @@ const name = "diagrams"
func init() {
f := func(d *deps.Deps) *internal.TemplateFuncsNamespace {
ctx := &Diagrams{
ctx := &Namespace{
d: d,
}

View file

@ -141,6 +141,22 @@ func (t goDocFunc) toJSON() ([]byte, error) {
return buf.Bytes(), nil
}
// ToMap returns a limited map representation of the namespaces.
func (namespaces TemplateFuncsNamespaces) ToMap() map[string]any {
m := make(map[string]any)
for _, ns := range namespaces {
mm := make(map[string]any)
for name, mapping := range ns.MethodMappings {
mm[name] = map[string]any{
"Examples": mapping.Examples,
"Aliases": mapping.Aliases,
}
}
m[ns.Name] = mm
}
return m
}
// MarshalJSON returns the JSON encoding of namespaces.
func (namespaces TemplateFuncsNamespaces) MarshalJSON() ([]byte, error) {
var buf bytes.Buffer