Extend render template with common usage & install instructions (#27)

* Extend render template with jsonnet-bundler instructions

* push usage/install templates up the stack

* ensure newline between docs and header

* correctly quote default args
This commit is contained in:
Jeroen Op 't Eynde 2022-06-13 13:42:51 +02:00 committed by GitHub
parent f47f46f93f
commit fedfb4920f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 119 additions and 34 deletions

View file

@ -5,11 +5,7 @@
package: |||
# package %(name)s
```jsonnet
local %(name)s = import '%(import)s/%(filename)s';
```
%(help)s
%(content)s
|||,
indexPage: |||
@ -186,7 +182,11 @@
args: std.join(', ', [
if arg.default != null
then arg.name + '=' + arg.default
then arg.name + '=' + (
if arg.type == 'string'
then "'%s'" % arg.default
else std.toString(arg.default)
)
else arg.name
for arg in self.doc.args
]),
@ -203,15 +203,46 @@
help: doc.value.help,
value: obj,
},
package(doc, root):: {
name: doc.name,
content:
|||
%(help)s
||| % doc
+ (if 'installTemplate' in doc
then |||
## Install
```
%(install)s
```
||| % doc.installTemplate % doc
else '')
+ (if 'usageTemplate' in doc
then |||
## Usage
```jsonnet
%(usage)s
```
||| % doc.usageTemplate % doc
else ''),
},
},
prepare(obj, filename='', depth=0)::
prepare(obj, depth=0)::
std.foldl(
function(acc, key)
acc +
// Package definition
if key == '#'
then obj[key] { filename: filename }
then root.sections.package(
obj[key],
(depth == 0)
)
// Field definition
else if std.startsWith(key, '#')
@ -319,6 +350,6 @@
{}
),
render(obj, filename):
self.renderFiles(self.prepare(obj, filename)),
render(obj):
self.renderFiles(self.prepare(obj)),
}