Expand description
A screenshots page from a VisualCI public gallery manifest, rendered in Rust
as the gallery contract’s markup: byte for byte what the visualci-gallery JS library renders, so its script
hydrates it (tabs, light and dark, desktop and phone, the full-size view).
use visualci_gallery::{Gallery, Options};
// The manifest a build step wrote (a copy of https://app.visualci.com/g/<org>/<project>.json).
let manifest = std::fs::read_to_string("screenshots.json").expect("the build writes it");
let gallery = Gallery::from_json(&manifest, &Options::default().title(None))?;
let html = gallery.to_string();There is no fallback: rendering fails when the manifest has nothing to show or the options are invalid, and
[fetch] (feature fetch) fails when the manifest can’t be read. Read it when the site builds, fail the build if
it can’t be, and render from that copy.
With the askama feature, Gallery is safe HTML to Askama: a template writes {{ gallery }}.
Structs§
- Gallery
- A rendered gallery. Displays as its HTML; with the
askamafeature, Askama doesn’t escape it. - Group
- Model
- The manifest as the gallery shows it, with the keys of the contract fixtures’ model.json.
- Options
- The options a site can set (contract/SPEC.md, “Input”), as JSON-shaped values so every renderer takes the same
ones. Build them with
Options::defaultand the setters, orOptions::from_json. - Preload
Caps - The preloader’s limits:
foldabove-the-fold thumbnails always load; past them at mostcountimages andbytesbytes;parallelrequests at once. - Screen
- SeeAll
- Shot
- How a manifest name pairs (contract/SPEC.md, “A shot’s name”).
- Thumb
- Variant
Enums§
- Error
- Why a gallery can’t be shown.
- Preload
- Predictive preloading other than the default (the model’s
preload:"off", or the caps, every one filled in).
Constants§
Functions§
- build_
model - The manifest as the gallery shows it (contract/SPEC.md). Fails when it or the options are invalid, or nothing in it can be shown.
- escape
- & < > “ ’ as entities: the only escaping the contract allows, so every language’s output is the same.
- humanize
["billing", "free"]→ “Billing, free”.- parse_
shot <screen>-<theme>[-<width>][-2x], or<screen>/<width>-<theme>[-2x]. A name in neither shape is a screen of its own, in both themes. Under 768 wide is a phone; with no width, a portrait image is a phone and a landscape one a desktop, unlesssizesays.- render
- The gallery’s HTML for a parsed manifest.
- render_
model - The gallery’s markup: one line per block, no indentation, “\n” after each line.
- slugify
- A group’s name as an id: ASCII lower case, runs of anything else as one hyphen.