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
Copy file name to clipboardExpand all lines: docs/modules/ROOT/pages/generators.adoc
+70Lines changed: 70 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -200,6 +200,76 @@ Unknown top-level keys are silently ignored so future schema additions stay non-
200
200
If the same id appears under more than one addon root, the first one wins: that root's manifest sets the format's escape rules.
201
201
Later roots can still contribute layered partials and helpers under the same id through the existing template-loading path, so a project can supplement a shared format without redefining it.
202
202
203
+
To add a generator that builds its output structure imperatively, rather than rendering one page per symbol from templates, see <<script-driven-generators,Script-driven generators>>.
204
+
205
+
[#script-driven-generators]
206
+
== Script-driven generators
207
+
208
+
A data-driven generator renders one page per symbol from templates. When you need a different output structure - one file per namespace, or a single artifact aggregated across every symbol, such as a search index - a template generator cannot express it, because the page-per-symbol shape is fixed by the host. A script-driven generator hands the whole emit to a Lua or JavaScript script, which traverses the corpus and writes whatever files it wants. No C++ and no templates are involved.
209
+
210
+
A generator directory is script-driven when its `mrdocs-generator.yml` names an entry script:
211
+
212
+
[source,yaml]
213
+
----
214
+
script: generator.lua
215
+
----
216
+
217
+
The `script` key holds a path to a Lua (`.lua`) or JavaScript (`.js`) file, relative to the generator directory. Naming a script is what distinguishes the two flavors: a manifest with a `script` key is script-driven, otherwise the directory is a data-driven (template) generator. As with template generators, the directory name is the generator id you select with `--generator`.
218
+
219
+
=== The `generate` entry point
220
+
221
+
The script defines a single entry point:
222
+
223
+
[source]
224
+
----
225
+
generate(corpus, output)
226
+
----
227
+
228
+
`corpus.symbols` is the array of every symbol. Each symbol carries the same fields the template and helper layers see, plus a flat `_id` string suitable as a stable per-symbol URL fragment.
229
+
230
+
`output.write(relativePath, contents)` writes one file. The path is resolved under the output directory and may not escape it; an absolute path or one that climbs above the output directory is rejected. Parent directories are created as needed.
231
+
232
+
Because the script owns the output, it also owns what a per-page generator would otherwise do for it: the URLs it emits, and any escaping of the content it writes. The host does not apply an escape map to a script-driven generator's output.
233
+
234
+
In Lua, `generate` may be the value the script returns or a global function; in JavaScript it is a global function:
235
+
236
+
[source,lua]
237
+
----
238
+
return function(corpus, output)
239
+
-- ...
240
+
end
241
+
----
242
+
243
+
Unlike a corpus-transform extension, whose hook is optional, a generator must define a `generate` function: selecting the generator is a request for output, so a missing entry point is an error.
244
+
245
+
=== Example: a search index
246
+
247
+
This generator emits a single search-index.json aggregating every symbol, an artifact no per-page generator can produce:
The HTML and AsciiDoc generators ship a bundled stylesheet that is inlined by default. You can replace or layer styles with the following options (available in config files and on the CLI):
Copy file name to clipboardExpand all lines: docs/mrdocs.schema.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -252,7 +252,7 @@
252
252
},
253
253
"generator": {
254
254
"default": "adoc",
255
-
"description": "The generator is responsible for creating the documentation from the extracted symbols. The generator uses the extracted symbols and the templates to create the documentation. The built-in generators include `adoc`, `html`, and `xml`; data-driven generators can be added by dropping a template folder under <addon>/generator/<name>/.",
255
+
"description": "The generator is responsible for creating the documentation from the extracted symbols. The generator uses the extracted symbols and the templates to create the documentation. The built-in generators include `adoc`, `html`, and `xml`; data-driven generators can be added by dropping a template folder under <addon>/generator/<name>/; script-driven generators instead ship a Lua or JavaScript script that produces the output.",
256
256
"title": "Generator used to create the documentation",
Copy file name to clipboardExpand all lines: src/lib/ConfigOptions.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -397,7 +397,7 @@
397
397
{
398
398
"name": "generator",
399
399
"brief": "Generator used to create the documentation",
400
-
"details": "The generator is responsible for creating the documentation from the extracted symbols. The generator uses the extracted symbols and the templates to create the documentation. The built-in generators include `adoc`, `html`, and `xml`; data-driven generators can be added by dropping a template folder under <addon>/generator/<name>/.",
400
+
"details": "The generator is responsible for creating the documentation from the extracted symbols. The generator uses the extracted symbols and the templates to create the documentation. The built-in generators include `adoc`, `html`, and `xml`; data-driven generators can be added by dropping a template folder under <addon>/generator/<name>/; script-driven generators instead ship a Lua or JavaScript script that produces the output.",
0 commit comments