mirror of
https://github.com/TECHNOFAB11/docsonnet.git
synced 2025-12-12 06:20:12 +01:00
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:
parent
f47f46f93f
commit
fedfb4920f
5 changed files with 119 additions and 34 deletions
|
|
@ -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)),
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue