docsonnet/doc-util/main.libsonnet

215 lines
5.9 KiB
Jsonnet
Raw Normal View History

2020-03-25 16:20:51 +01:00
{
local d = self,
'#': d.pkg(
name='d',
url='github.com/jsonnet-libs/docsonnet/doc-util',
help=|||
`doc-util` provides a Jsonnet interface for `docsonnet`,
a Jsonnet API doc generator that uses structured data instead of comments.
|||,
filename=std.thisFile,
),
package:: {
'#new':: d.fn(|||
`new` creates a new package
Arguments:
* given `name`
* source `url` for jsonnet-bundler and the import
* `help` text
* `filename` for the import, defaults to blank for backward compatibility
* `version` for jsonnet-bundler install, defaults to `master` just like jsonnet-bundler
|||, [
d.arg('name', d.T.string),
d.arg('url', d.T.string),
d.arg('help', d.T.string),
d.arg('filename', d.T.string, ''),
d.arg('version', d.T.string, 'master'),
]),
new(name, url, help, filename='', version='master')::
{
name: name,
help: help,
'import':
if filename != ''
then url + '/' + filename
else url,
url: url,
filename: filename,
version: version,
}
+ self.withInstallTemplate(
'jb install %(url)s@%(version)s'
)
+ self.withUsageTemplate(
'local %(name)s = import "%(import)s"'
),
2023-02-16 19:56:58 +01:00
'#newSub':: d.fn(|||
`newSub` creates a package without the preconfigured install/usage templates.
Arguments:
* given `name`
* `help` text
|||, [
d.arg('name', d.T.string),
d.arg('help', d.T.string),
]),
newSub(name, help)::
{
name: name,
help: help,
},
withUsageTemplate(template):: {
usageTemplate: template,
},
withInstallTemplate(template):: {
installTemplate: template,
},
2020-03-25 16:20:51 +01:00
},
'#pkg':: self.package['#new'] + d.func.withHelp('`new` is a shorthand for `package.new`'),
pkg:: self.package.new,
2020-03-25 16:20:51 +01:00
'#object': d.obj('Utilities for documenting Jsonnet objects (`{ }`).'),
2020-03-25 16:20:51 +01:00
object:: {
'#new': d.fn('new creates a new object, optionally with description and fields', [d.arg('help', d.T.string), d.arg('fields', d.T.object)]),
2020-03-25 16:20:51 +01:00
new(help='', fields={}):: { object: {
help: help,
fields: fields,
} },
'#withFields': d.fn('The `withFields` modifier overrides the fields property of an already created object', [d.arg('fields', d.T.object)]),
2020-03-25 16:20:51 +01:00
withFields(fields):: { object+: {
fields: fields,
} },
},
'#obj': self.object['#new'] + d.func.withHelp('`obj` is a shorthand for `object.new`'),
2020-03-25 16:20:51 +01:00
obj:: self.object.new,
'#func': d.obj('Utilities for documenting Jsonnet methods (functions of objects)'),
2020-03-25 16:20:51 +01:00
func:: {
'#new': d.fn('new creates a new function, optionally with description and arguments', [d.arg('help', d.T.string), d.arg('args', d.T.array)]),
2020-03-25 16:20:51 +01:00
new(help='', args=[]):: { 'function': {
help: help,
args: args,
} },
'#withHelp': d.fn('The `withHelp` modifier overrides the help text of that function', [d.arg('help', d.T.string)]),
withHelp(help):: { 'function'+: {
2020-03-25 16:20:51 +01:00
help: help,
} },
2020-05-13 12:31:07 +02:00
'#withArgs': d.fn('The `withArgs` modifier overrides the arguments of that function', [d.arg('args', d.T.array)]),
withArgs(args):: { 'function'+: {
args: args,
} },
2020-03-25 16:20:51 +01:00
},
'#fn': self.func['#new'] + d.func.withHelp('`fn` is a shorthand for `func.new`'),
2020-03-25 16:20:51 +01:00
fn:: self.func.new,
'#argument': d.obj('Utilities for creating function arguments'),
2020-03-25 16:20:51 +01:00
argument:: {
2023-02-16 19:57:15 +01:00
'#new': d.fn(|||
`new` creates a new function argument, taking the `name`, the `type`. Optionally it
can take a `default` value and `enum`-erate potential values.
Examples:
```jsonnet
[
d.argument.new('foo', d.T.string),
d.argument.new('bar', d.T.string, default='loo'),
d.argument.new('baz', d.T.number, enums=[1,2,3]),
]
```
|||, [
d.arg('name', d.T.string),
d.arg('type', d.T.string),
d.arg('default', d.T.any),
d.arg('enums', d.T.array),
]),
new(name, type, default=null, enums=null): {
2020-03-25 16:20:51 +01:00
name: name,
type: type,
default: default,
2023-02-16 19:57:15 +01:00
enums: enums,
2020-03-25 16:20:51 +01:00
},
},
'#arg': self.argument['#new'] + self.func.withHelp('`arg` is a shorthand for `argument.new`'),
2020-03-25 16:20:51 +01:00
arg:: self.argument.new,
'#value': d.obj('Utilities for documenting plain Jsonnet values (primitives)'),
value:: {
'#new': d.fn('new creates a new object of given type, optionally with description and default value', [d.arg('type', d.T.string), d.arg('help', d.T.string), d.arg('default', d.T.any)]),
new(type, help='', default=null): { value: {
help: help,
type: type,
default: default,
} },
},
'#val': self.value['#new'] + self.func.withHelp('`val` is a shorthand for `value.new`'),
val:: self.value.new,
2020-03-25 16:20:51 +01:00
// T contains constants for the Jsonnet types
T:: {
'#string': d.val(d.T.string, 'argument of type "string"'),
2020-03-25 16:20:51 +01:00
string: 'string',
'#number': d.val(d.T.string, 'argument of type "number"'),
2020-03-25 16:20:51 +01:00
number: 'number',
int: self.number,
integer: self.number,
'#boolean': d.val(d.T.string, 'argument of type "boolean"'),
boolean: 'bool',
bool: self.boolean,
'#object': d.val(d.T.string, 'argument of type "object"'),
2020-03-25 16:20:51 +01:00
object: 'object',
'#array': d.val(d.T.string, 'argument of type "array"'),
2020-03-25 16:20:51 +01:00
array: 'array',
'#any': d.val(d.T.string, 'argument of type "any"'),
2020-03-25 16:20:51 +01:00
any: 'any',
'#null': d.val(d.T.string, 'argument of type "null"'),
'null': 'null',
nil: self['null'],
2020-05-13 12:31:07 +02:00
'#func': d.val(d.T.string, 'argument of type "func"'),
2020-03-25 16:20:51 +01:00
func: 'function',
'function': self.func,
2020-03-25 16:20:51 +01:00
},
'#render': d.fn(
|||
`render` converts the docstrings to human readable Markdown files.
Usage:
```jsonnet
// docs.jsonnet
d.render(import 'main.libsonnet')
```
Call with: `jsonnet -S -c -m docs/ docs.jsonnet`
|||,
args=[
d.arg('obj', d.T.object),
]
),
render:: (import './render.libsonnet').render,
2020-03-25 16:20:51 +01:00
}