feat: ignore

Implements ignoring certain keys right in Jsonnet, by adding:

  {
    '#foo': "ignore",
    foo: {}
  }

This is especially useful for objects that include `self` references,
which might otherwise recurse infinitely
This commit is contained in:
sh0rez 2020-05-12 22:48:02 +02:00
parent 14e9fc8f3f
commit 66a158a8f2
No known key found for this signature in database
GPG key ID: 87C71DF9F8181FF1
7 changed files with 85 additions and 46 deletions

View file

@ -2,6 +2,7 @@ package render
import (
"fmt"
"path"
"sort"
"strings"
@ -10,14 +11,18 @@ import (
"github.com/sh0rez/docsonnet/pkg/slug"
)
func Render(pkg docsonnet.Package) map[string]string {
return render(pkg, nil, true)
type Opts struct {
URLPrefix string
}
func render(pkg docsonnet.Package, parents []string, root bool) map[string]string {
link := "/" + strings.Join(append(parents, pkg.Name), "/")
func Render(pkg docsonnet.Package, opts Opts) map[string]string {
return render(pkg, nil, true, opts.URLPrefix)
}
func render(pkg docsonnet.Package, parents []string, root bool, urlPrefix string) map[string]string {
link := path.Join("/", urlPrefix, strings.Join(append(parents, pkg.Name), "/"))
if root {
link = "/"
link = path.Join("/", urlPrefix)
}
// head
@ -83,7 +88,7 @@ func render(pkg docsonnet.Package, parents []string, root bool) map[string]strin
if root {
path = parents
}
got := render(s, path, false)
got := render(s, path, false, urlPrefix)
for k, v := range got {
out[k] = v
}