visualci-gallery (Rust)
A screenshots page from a VisualCI public gallery manifest, rendered in Rust as
the gallery contract's markup.
The markup is byte for byte what the visualci-gallery JS library renders, so the library's script hydrates it: tabs,
light and dark, desktop and phone, and the full-size view.
use ;
// The manifest a build step wrote: a copy of https://app.visualci.com/g/<org>/<project>.json.
let manifest = read_to_string?;
let gallery = from_json?;
println!;
# Ok::
Rendering fails when the manifest has nothing to show or the options are invalid. There is no fallback: read the
manifest when the site builds (a CI step that fails the build if VisualCI can't be read), and render from that copy.
The fetch feature adds a blocking fetch(url, timeout, attempts) for that step.
Askama
With the askama feature (askama 0.16), Gallery is safe HTML, so a template writes {{ gallery }}:
Add the library's stylesheet and script (visualci-gallery on npm: dist/gallery.css and the ES5 dist/gallery.iife.js,
which sets window.VisualCIGallery), then
document.querySelectorAll("[data-vg]").forEach((el) => VisualCIGallery.hydrate(el)).
Options
Options::default() and its setters (title, heading_level, id, screen, order, group, group_order,
credit, layout, theme_switch, see_all), or Options::from_json with the contract's JSON names.
Development
cargo test --all-features checks the contract's golden fixtures, refusals and messages.