mirror of
https://github.com/TECHNOFAB11/docsonnet.git
synced 2025-12-12 06:20:12 +01:00
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
27 lines
447 B
Go
27 lines
447 B
Go
package render
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"github.com/sh0rez/docsonnet/pkg/docsonnet"
|
|
)
|
|
|
|
func To(pkg docsonnet.Package, dir string, opts Opts) (int, error) {
|
|
if err := os.MkdirAll(dir, os.ModePerm); err != nil {
|
|
return 0, err
|
|
}
|
|
|
|
data := Render(pkg, opts)
|
|
|
|
n := 0
|
|
for k, v := range data {
|
|
if err := ioutil.WriteFile(filepath.Join(dir, k), []byte(v), 0644); err != nil {
|
|
return n, err
|
|
}
|
|
n++
|
|
}
|
|
|
|
return n, nil
|
|
}
|