Skip to content

Commit 220d3e6

Browse files
authored
refactor: render engine (#53)
* refactor: render engine * refactor: move install/usage into package.help * fix: found issues from running this against Grafonnet - reduce diff as much as possible (mostly whitespace/empty lines) - ensure relative path for links - make sure warning message is shown * chore: render README with new engine
1 parent 8b292be commit 220d3e6

3 files changed

Lines changed: 437 additions & 393 deletions

File tree

doc-util/README.md

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
`doc-util` provides a Jsonnet interface for `docsonnet`,
44
a Jsonnet API doc generator that uses structured data instead of comments.
55

6-
76
## Install
87

98
```
@@ -16,6 +15,7 @@ jb install github.com/jsonnet-libs/docsonnet/doc-util@master
1615
local d = import "github.com/jsonnet-libs/docsonnet/doc-util/main.libsonnet"
1716
```
1817

18+
1919
## Index
2020

2121
* [`fn arg(name, type, default, enums)`](#fn-arg)
@@ -44,39 +44,39 @@ local d = import "github.com/jsonnet-libs/docsonnet/doc-util/main.libsonnet"
4444

4545
### fn arg
4646

47-
```ts
47+
```jsonnet
4848
arg(name, type, default, enums)
4949
```
5050

5151
`arg` is a shorthand for `argument.new`
5252

5353
### fn fn
5454

55-
```ts
55+
```jsonnet
5656
fn(help, args)
5757
```
5858

5959
`fn` is a shorthand for `func.new`
6060

6161
### fn obj
6262

63-
```ts
63+
```jsonnet
6464
obj(help, fields)
6565
```
6666

6767
`obj` is a shorthand for `object.new`
6868

6969
### fn pkg
7070

71-
```ts
71+
```jsonnet
7272
pkg(name, url, help, filename="", version="master")
7373
```
7474

7575
`new` is a shorthand for `package.new`
7676

7777
### fn render
7878

79-
```ts
79+
```jsonnet
8080
render(obj)
8181
```
8282

@@ -94,7 +94,7 @@ Call with: `jsonnet -S -c -m docs/ docs.jsonnet`
9494

9595
### fn val
9696

97-
```ts
97+
```jsonnet
9898
val(type, help, default)
9999
```
100100

@@ -106,7 +106,7 @@ Utilities for creating function arguments
106106

107107
#### fn argument.new
108108

109-
```ts
109+
```jsonnet
110110
new(name, type, default, enums)
111111
```
112112

@@ -130,23 +130,23 @@ Utilities for documenting Jsonnet methods (functions of objects)
130130

131131
#### fn func.new
132132

133-
```ts
133+
```jsonnet
134134
new(help, args)
135135
```
136136

137137
new creates a new function, optionally with description and arguments
138138

139139
#### fn func.withArgs
140140

141-
```ts
141+
```jsonnet
142142
withArgs(args)
143143
```
144144

145145
The `withArgs` modifier overrides the arguments of that function
146146

147147
#### fn func.withHelp
148148

149-
```ts
149+
```jsonnet
150150
withHelp(help)
151151
```
152152

@@ -158,15 +158,15 @@ Utilities for documenting Jsonnet objects (`{ }`).
158158

159159
#### fn object.new
160160

161-
```ts
161+
```jsonnet
162162
new(help, fields)
163163
```
164164

165165
new creates a new object, optionally with description and fields
166166

167167
#### fn object.withFields
168168

169-
```ts
169+
```jsonnet
170170
withFields(fields)
171171
```
172172

@@ -178,15 +178,14 @@ Utilities for documenting plain Jsonnet values (primitives)
178178

179179
#### fn value.new
180180

181-
```ts
181+
```jsonnet
182182
new(type, help, default)
183183
```
184184

185185
new creates a new object of given type, optionally with description and default value
186186

187187
### obj T
188188

189-
190189
* `T.any` (`string`): `"any"` - argument of type "any"
191190
* `T.array` (`string`): `"array"` - argument of type "array"
192191
* `T.boolean` (`string`): `"bool"` - argument of type "boolean"
@@ -201,7 +200,7 @@ new creates a new object of given type, optionally with description and default
201200

202201
#### fn package.new
203202

204-
```ts
203+
```jsonnet
205204
new(name, url, help, filename="", version="master")
206205
```
207206

@@ -218,7 +217,7 @@ Arguments:
218217

219218
#### fn package.newSub
220219

221-
```ts
220+
```jsonnet
222221
newSub(name, help)
223222
```
224223

doc-util/main.libsonnet

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@
3636
new(name, url, help, filename='', version='master')::
3737
{
3838
name: name,
39-
help: help,
39+
help:
40+
help
41+
+ std.get(self, 'installTemplate', '') % self
42+
+ std.get(self, 'usageTemplate', '') % self,
4043
'import':
4144
if filename != ''
4245
then url + '/' + filename
@@ -70,12 +73,34 @@
7073
help: help,
7174
},
7275

73-
withUsageTemplate(template):: {
74-
usageTemplate: template,
76+
withInstallTemplate(template):: {
77+
installTemplate:
78+
if template != null
79+
then
80+
|||
81+
82+
## Install
83+
84+
```
85+
%s
86+
```
87+
||| % template
88+
else '',
7589
},
7690

77-
withInstallTemplate(template):: {
78-
installTemplate: template,
91+
withUsageTemplate(template):: {
92+
usageTemplate:
93+
if template != null
94+
then
95+
|||
96+
97+
## Usage
98+
99+
```jsonnet
100+
%s
101+
```
102+
||| % template
103+
else '',
79104
},
80105
},
81106

0 commit comments

Comments
 (0)