You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Update docs with enhanced usage info
Signed-off-by: Yoriyasu Yano <430092+yorinasub17@users.noreply.github.com>
* Fix incorrect “it’s” with “its”
* Make sure to bind /docs in docker docs so that output can be synced to host
Signed-off-by: Yoriyasu Yano <430092+yorinasub17@users.noreply.github.com>
* docs: use -J vendor
---------
Signed-off-by: Yoriyasu Yano <430092+yorinasub17@users.noreply.github.com>
Co-authored-by: Jeroen Op 't Eynde <jeroen@simplistic.be>
Copy file name to clipboardExpand all lines: README.md
+62-9Lines changed: 62 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -39,7 +39,7 @@ Jsonnet itself does not know traditional packages, classes or similar.
39
39
40
40
For documentation and distribution purposes however, it seems reasonable to introduce a concept of **loose packages**, defined as a single importable file, holding all of your **public API**.
41
41
42
-
As an example, a hypothetical `url` library could define it's package like above example does.
42
+
As an example, a hypothetical `url` library could define its package like above example does.
43
43
44
44
Packages are defined by including assigning a `d.pkg` call to a key literally named `#` (hash). All fields, including nested packages, of the same object having the `#` key belong to that package.
45
45
@@ -54,7 +54,7 @@ Most common part of an API will be functions. These are annotated in a similar f
54
54
}
55
55
```
56
56
57
-
Along the actual function definition, a _docsonnet_ key is added, with the functions name prefixed by the familiar `#` as it's name.
57
+
Along the actual function definition, a _docsonnet_ key is added, with the functions name prefixed by the familiar `#` as its name.
58
58
Above example defines `myFunc` as a function, that greets the user and takes a single argument of type `string`.
59
59
60
60
### Objects
@@ -73,18 +73,71 @@ Such an object might need a description as well, so you can also annotate it:
73
73
}
74
74
```
75
75
76
-
Again, the naming rule `#` joined with the fields name must be followed, so the `docsonnet` utility can automatically join together the contents of your object with it's annotated description.
76
+
Again, the naming rule `#` joined with the fields name must be followed, so the `docsonnet` utility can automatically join together the contents of your object with its annotated description.
77
77
78
-
## FAQ
79
78
80
-
#### Do my projects need to have `doc-util` installed to vendor/?
79
+
## Usage
80
+
81
+
Once you have a Jsonnet library annotated with `doc-util`, you can generate the docs using one of three ways:
In your library source, add a file `docs.jsonnet` (assuming your library entrypoint is `main.libsonnet`) with the
93
+
following contents:
94
+
95
+
```jsonnet
96
+
local d = import 'github.com/jsonnet-libs/docsonnet/doc-util/main.libsonnet';
97
+
d.render(import 'main.libsonnet')
98
+
```
99
+
100
+
Then, you can render the markdown to the `docs/` folder using the following command:
101
+
102
+
```
103
+
jsonnet -J vendor -S -c -m docs/ docs.jsonnet
104
+
```
105
+
106
+
Note that this requires `doc-util` to be installed to `vendor/` to work properly.
107
+
108
+
### docsonnet binary
109
+
110
+
Alternatively, the docs can be rendered using the `docsonnet` go binary. The `docsonnet` binary embeds the `doc-util`
111
+
library, avoiding the need to have `doc-util` installed.
81
112
82
-
No! The `docsonnet` binary comes included with it, and during normal Jsonnet use the docsonnet keys will never be accessed, so your Jsonnet runs just fine without.
113
+
You can install the `docsonnet` binary using `go install`:
83
114
84
-
> **Note**
85
-
>
115
+
```
116
+
go install github.com/jsonnet-libs/docsonnet@master
117
+
```
118
+
119
+
Once the binary is installed, you can generate the docs by passing it the main entrypoint to your Jsonnet library:
120
+
121
+
```
122
+
docsonnet main.libsonnet
123
+
```
124
+
125
+
> **Note**
126
+
>
86
127
> Linters like [jsonnet-lint](https://pkg.go.dev/github.com/google/go-jsonnet/linter) or `tk lint` require the imports to be resolvable, so you should add `doc-util` to `vendor/` when using these linters.
87
128
129
+
### docsonnet docker image
130
+
131
+
You can also use the [docker image](https://hub.docker.com/r/jsonnetlibs/docsonnet) which contains the `docsonnet`
132
+
binary if you do not wish to set up go or install the binary locally:
133
+
134
+
```
135
+
docker run --rm -v "$(pwd):/src" -v "$(pwd)/docs:/docs" jsonnetlibs/docsonnet /src/main.libsonnet
136
+
```
137
+
138
+
139
+
## FAQ
140
+
88
141
#### What's wrong with comments? Why not parse regular comments?
89
142
90
143
I had some attempts on this, especially because it feels more natural. However, the language properties of Jsonnet make this quite challenging:
@@ -132,4 +185,4 @@ This will all happen transparently, without any user interaction
132
185
133
186
Because the Docsonnet gives you the missing logical representation of your Jsonnet library, it enables straight forward implementation of other language tooling, such as **code-completion**.
134
187
135
-
Instead of inferring what fields are available for a library, we can _just_ look at it's docsonnet and provide the fields specified there, along with nice descriptions and argument types.
188
+
Instead of inferring what fields are available for a library, we can _just_ look at its docsonnet and provide the fields specified there, along with nice descriptions and argument types.
0 commit comments