mirror of
https://github.com/TECHNOFAB11/docsonnet.git
synced 2025-12-14 23:33:56 +01:00
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:
parent
14e9fc8f3f
commit
66a158a8f2
7 changed files with 85 additions and 46 deletions
|
|
@ -2,31 +2,26 @@ package render
|
|||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/sh0rez/docsonnet/pkg/docsonnet"
|
||||
)
|
||||
|
||||
func To(api, out string) error {
|
||||
pkg, err := docsonnet.Load(api)
|
||||
if err != nil {
|
||||
return err
|
||||
func To(pkg docsonnet.Package, dir string, opts Opts) (int, error) {
|
||||
if err := os.MkdirAll(dir, os.ModePerm); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
if err := os.MkdirAll(out, os.ModePerm); err != nil {
|
||||
return err
|
||||
}
|
||||
data := Render(pkg, opts)
|
||||
|
||||
log.Println("Rendering .md files")
|
||||
data := Render(*pkg)
|
||||
n := 0
|
||||
for k, v := range data {
|
||||
if err := ioutil.WriteFile(filepath.Join(out, k), []byte(v), 0644); err != nil {
|
||||
return err
|
||||
if err := ioutil.WriteFile(filepath.Join(dir, k), []byte(v), 0644); err != nil {
|
||||
return n, err
|
||||
}
|
||||
n++
|
||||
}
|
||||
|
||||
log.Printf("Success! Rendered %v packages from '%s' to '%s'", len(data), api, out)
|
||||
return nil
|
||||
return n, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue