Skip to content

Commit fd8de90

Browse files
authored
feat(render): show arg type information in docs (#56)
* feat(render): show arg type information in docs * fix(render): don't assume help is set
1 parent 4af7ba8 commit fd8de90

1 file changed

Lines changed: 33 additions & 22 deletions

File tree

doc-util/render.libsonnet

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,11 @@
9292
toString():
9393
std.join(
9494
'\n',
95-
['# ' + doc.name + '\n']
96-
+ (if std.get(doc, 'help', '') != ''
97-
then [doc.help, '']
98-
else ['', ''])
95+
[
96+
'# ' + doc.name + '\n',
97+
std.get(doc, 'help', ''),
98+
'',
99+
]
99100
+ (if self.packages.hasPackages()
100101
then [
101102
'## Subpackages\n\n'
@@ -229,7 +230,7 @@
229230
std.join(
230231
'\n',
231232
[root.util.title('obj ' + self.path, std.length(path) + 2)]
232-
+ (if doc.object.help != ''
233+
+ (if std.get(doc.object, 'help', '') != ''
233234
then [doc.object.help]
234235
else [])
235236
+ [self.fields.toString()]
@@ -298,30 +299,40 @@
298299
for arg in doc['function'].args
299300
]),
300301

301-
enums: std.join('', [
302-
if arg.enums != null
302+
args_list:
303+
if std.length(doc['function'].args) > 0
303304
then
304-
'\nAccepted values for `%s` are %s\n' % [
305-
arg.name,
306-
std.join(', ', [
307-
std.manifestJsonEx(item, '', '')
308-
for item in arg.enums
309-
]),
310-
]
311-
else ''
312-
for arg in doc['function'].args
313-
]),
305+
'\nPARAMETERS:\n\n'
306+
+ std.join('\n', [
307+
'* **%s** (`%s`)' % [arg.name, arg.type]
308+
+ (if arg.default != null
309+
then std.join('=', [
310+
'\n - default value: `%s`' % std.manifestJsonEx(arg.default, '', ''),
311+
])
312+
else '')
313+
+ (if arg.enums != null
314+
then std.join('=', [
315+
'\n - valid values: %s' %
316+
std.join(', ', [
317+
'`%s`' % std.manifestJsonEx(item, '', '')
318+
for item in arg.enums
319+
]),
320+
])
321+
else '')
322+
for arg in doc['function'].args
323+
])
324+
else '',
314325

315326
toString():
316327
std.join('\n', [
317328
root.util.title('fn ' + self.path, std.length(path) + 2),
318329
|||
319330
```jsonnet
320-
%(name)s(%(args)s)
331+
%s(%s)
321332
```
322-
||| % [name, self.args],
323-
doc['function'].help,
324-
self.enums,
333+
%s
334+
||| % [self.path, self.args, self.args_list],
335+
std.get(doc['function'], 'help', ''),
325336
]),
326337
},
327338

@@ -366,7 +377,7 @@
366377
'(`%s`):' % doc.value.type,
367378
'`"%s"`' % obj,
368379
'-',
369-
doc.value.help,
380+
std.get(doc.value, 'help', ''),
370381
]),
371382
},
372383

0 commit comments

Comments
 (0)