aboutsummaryrefslogtreecommitdiffhomepage
path: root/tpl
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2022-11-29 11:38:21 +0100
committerBjørn Erik Pedersen <[email protected]>2022-12-03 11:54:33 +0100
commit7d5e3ab8a8b6beb9e367047c5bd4573fe3f8967d (patch)
treec9c4e280d9c6d3a5a1d1419e2db4882f5a79b064 /tpl
parentdc44bca963b0035818d4521b73c39af63db3a230 (diff)
downloadhugo-7d5e3ab8a8b6beb9e367047c5bd4573fe3f8967d.tar.gz
hugo-7d5e3ab8a8b6beb9e367047c5bd4573fe3f8967d.zip
tpl: Misco GoDoc improvements
Diffstat (limited to 'tpl')
-rw-r--r--tpl/diagrams/diagrams.go5
-rw-r--r--tpl/diagrams/init.go2
-rw-r--r--tpl/internal/templatefuncsRegistry.go16
3 files changed, 20 insertions, 3 deletions
diff --git a/tpl/diagrams/diagrams.go b/tpl/diagrams/diagrams.go
index 7f0a171b2..9abe9e24c 100644
--- a/tpl/diagrams/diagrams.go
+++ b/tpl/diagrams/diagrams.go
@@ -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) {
diff --git a/tpl/diagrams/init.go b/tpl/diagrams/init.go
index fed85e6a3..005e942b7 100644
--- a/tpl/diagrams/init.go
+++ b/tpl/diagrams/init.go
@@ -22,7 +22,7 @@ const name = "diagrams"
func init() {
f := func(d *deps.Deps) *internal.TemplateFuncsNamespace {
- ctx := &Diagrams{
+ ctx := &Namespace{
d: d,
}
diff --git a/tpl/internal/templatefuncsRegistry.go b/tpl/internal/templatefuncsRegistry.go
index d06b55b4d..da9aa5d29 100644
--- a/tpl/internal/templatefuncsRegistry.go
+++ b/tpl/internal/templatefuncsRegistry.go
@@ -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