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
refactor(extensions): register scripts through a mrdocs object, not globals
`register_transform` and `register_generator` were bare globals in the
extension environment. This moves them onto a `mrdocs` global object,
the way `console` is already provided, so a script writes
`mrdocs.register_transform(fn)` / `mrdocs.register_generator(id, fn)`.
Among Lua-embedding applications that expose a "register an extension"
call, a host namespace object is the prevailing convention - darktable
uses `dt.register_*`, Aegisub `aegisub.register_*`, Redis
`redis.register_function` - while bare globals are the exception. The
main advantage of exposing an object is that it makes the surface
discoverable.
Note that the per-invocation `ctx` (`ctx.corpus`, `ctx.output`,
`ctx.config`) is unchanged: only load-time declarations go through
`mrdocs`.
Copy file name to clipboardExpand all lines: docs/modules/ROOT/pages/extensions/corpus-extensions.adoc
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ An extension is a Lua or JavaScript script that runs as part of a Mr.Docs build
5
5
* A *corpus transform* rewrites metadata across many symbols at once: backfill briefs from a naming convention, tag symbols by group, mark generated code as "see below" in the output. Transforms run between extraction and rendering, so every generator sees the change.
6
6
* A *generator* owns the whole emit: instead of rendering one page per symbol, it traverses the corpus and writes whatever files it wants. That lets it produce shapes the per-page generators cannot, such as a single artifact aggregated across every symbol.
7
7
8
-
A script declares a transform with `register_transform(fn)` and a generator with `register_generator(id, fn)`. Either way the registered function receives a single context object, `ctx`.
8
+
A script declares a transform with `mrdocs.register_transform(fn)` and a generator with `mrdocs.register_generator(id, fn)`. Either way the registered function receives a single context object, `ctx`.
9
9
10
10
== Languages and addon locations
11
11
@@ -33,7 +33,7 @@ A script can register any number of transforms and generators, or none at all. I
33
33
[#corpus-transforms]
34
34
== Corpus transforms
35
35
36
-
A transform is a function passed to `register_transform`. Mr.Docs invokes each registered function once, in registration order, with the `ctx` object. A flat view of the corpus reaches the script through `ctx.corpus`.
36
+
A transform is a function passed to `mrdocs.register_transform`. Mr.Docs invokes each registered function once, in registration order, with the `ctx` object. A flat view of the corpus reaches the script through `ctx.corpus`.
37
37
38
38
[tabs]
39
39
======
@@ -65,7 +65,7 @@ JavaScript::
65
65
.`addons/extensions/count_by_kind.js`
66
66
[source,javascript]
67
67
----
68
-
register_transform(function(ctx) {
68
+
mrdocs.register_transform(function(ctx) {
69
69
var counts = {};
70
70
for (var i = 0; i < ctx.corpus.symbols.length; ++i) {
71
71
var k = ctx.corpus.symbols[i].kind;
@@ -82,7 +82,7 @@ Lua::
82
82
.`addons/extensions/count_by_kind.lua`
83
83
[source,lua]
84
84
----
85
-
register_transform(function(ctx)
85
+
mrdocs.register_transform(function(ctx)
86
86
local counts = {}
87
87
for _, sym in ipairs(ctx.corpus.symbols) do
88
88
counts[sym.kind] = (counts[sym.kind] or 0) + 1
@@ -225,7 +225,7 @@ Notice in this example that `s.doc.sees` receives a list of polymorphic types th
225
225
226
226
The built-in generators render one page per symbol. When you need a different output structure, e.g. one file per namespace, or a single artifact aggregated across every symbol such as a search index, that page-per-symbol shape cannot express it. A generator hands the whole emit to the script instead: it traverses the corpus and writes whatever files it wants. No C++ and no templates are involved.
227
227
228
-
A script declares a generator with `register_generator(id, fn)`. The `id` is the name you select on the command line with `--generator=<id>`; a registered generator takes precedence over a built-in of the same name. Selecting a generator is a request for output, so its function does the work directly, the page-per-symbol fallback the built-ins provide does not apply.
228
+
A script declares a generator with `mrdocs.register_generator(id, fn)`. The `id` is the name you select on the command line with `--generator=<id>`; a registered generator takes precedence over a built-in of the same name. Selecting a generator is a request for output, so its function does the work directly, the page-per-symbol fallback the built-ins provide does not apply.
229
229
230
230
The function receives the same `ctx` a transform does, plus `ctx.output`:
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
@@ -282,7 +282,7 @@
282
282
"default": [
283
283
"html"
284
284
],
285
-
"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`, `xml`, and `noop` (which extracts but writes no output, useful for checking extraction warnings); data-driven generators can be added by dropping a template folder under <addon>/generator/<name>/; a script-driven generator is declared by an extension with `register_generator` and produces the output itself. This option accepts a single generator (`generator: xml`), a list (`generator: [xml, adoc]`), or a comma-separated string (`generator: \"xml,adoc\"`); when more than one is given the documentation is produced once per generator.",
285
+
"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`, `xml`, and `noop` (which extracts but writes no output, useful for checking extraction warnings); data-driven generators can be added by dropping a template folder under <addon>/generator/<name>/; a script-driven generator is declared by an extension with `mrdocs.register_generator` and produces the output itself. This option accepts a single generator (`generator: xml`), a list (`generator: [xml, adoc]`), or a comma-separated string (`generator: \"xml,adoc\"`); when more than one is given the documentation is produced once per generator.",
286
286
"title": "Generator(s) 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
@@ -443,7 +443,7 @@
443
443
{
444
444
"name": "generator",
445
445
"brief": "Generator(s) used to create the documentation",
446
-
"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`, `xml`, and `noop` (which extracts but writes no output, useful for checking extraction warnings); data-driven generators can be added by dropping a template folder under <addon>/generator/<name>/; a script-driven generator is declared by an extension with `register_generator` and produces the output itself. This option accepts a single generator (`generator: xml`), a list (`generator: [xml, adoc]`), or a comma-separated string (`generator: \"xml,adoc\"`); when more than one is given the documentation is produced once per generator.",
446
+
"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`, `xml`, and `noop` (which extracts but writes no output, useful for checking extraction warnings); data-driven generators can be added by dropping a template folder under <addon>/generator/<name>/; a script-driven generator is declared by an extension with `mrdocs.register_generator` and produces the output itself. This option accepts a single generator (`generator: xml`), a list (`generator: [xml, adoc]`), or a comma-separated string (`generator: \"xml,adoc\"`); when more than one is given the documentation is produced once per generator.",
0 commit comments