Plugins in Rust #
The lsdocs-plugin-sdk crate has the traits, the document types and the
protocol (its API reference: lsdocs_plugin_sdk,
generated from its source). Implement Parser, Transformer or Renderer, put them in a
Plugin, and hand it to lsdocs_plugin_sdk::main:
use Node;
use ;
use ;
/// Upper-cases every text node.
;
Build it and point the site at the program:
[[]]
= "shout"
= ["target/release/shout"]
The traits #
Parser:extensions()(without the dot) andparse(params, ctx), which gets the file'ssourcepath andtextand returns aParseResult(the document and diagnostics).Transformer:nodes()(node kinds to select; empty for every document) andapply(render/transform/each). Setconst READS: bool = trueand implementread(parse/transform/each) to gather data first:applythen finds a map from each document's source to what was read inparams.collected.conclude(parse/transform/all) sees all of it once and may add documents.Renderer:formats()andrender, returning the output bytes and their file extension. Setconst RENDERS_ALL: bool = trueand implementrender_all(render/transform/all) to add files no single page makes, such as a sitemap.
The Context gives the project (ctx.project(): its directory and
source files), the site (ctx.site(): title and base URL), where
settings are (ctx.config(): the .config/ directory and the plugin's
name) and the
plugin's settings (ctx.settings()), and sends logs (ctx.info(...)),
progress and diagnostics to lsdocs while a request runs.
Settings are read once, when the session starts, by a loader the plugin
registers with Plugin::settings; it returns them with the files it read.
lsdocs_plugin_sdk::config has loaders for TOML:
use config;
// `.config/acme/<name>/settings.toml`, any keys:
new
.settings
// lsdocs' layout (`lsdocs/<name>/settings.toml`), only these keys:
// .settings(|c| config::settings_toml_keys(c, &["depth"]))
Plugin::cacheable() lets lsdocs cache results that depend only on the
request, the site settings and the plugin's settings files; cache_key
covers other inputs, such as a template file.
Testing #
lsdocs_plugin_sdk::testing runs a plugin without lsdocs:
testing::run_transform(&plugin, &initialize, documents) runs the collect
and apply passes the way lsdocs does, and testing::context makes a
Context for calling parse or render directly.