Skip to main content

Crate visualci_gallery

Crate visualci_gallery 

Source
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 and any dimension a site adds, 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§

Dimension
A way a screen’s shots differ (contract/SPEC.md, “Dimensions”): theme and size are built in, a site adds others.
DimensionValue
Gallery
A rendered gallery. Displays as its HTML; with the askama feature, 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::default and the setters, or Options::from_json.
PreloadCaps
The preloader’s limits: fold above-the-fold thumbnails always load; past them at most count images and bytes bytes; parallel requests at once.
Screen
ScreenshotOptions
What screenshot and screenshot_markdown show, as JSON-shaped values like the gallery’s Options. Build them with ScreenshotOptions::new and the setters, or ScreenshotOptions::from_json.
SeeAll
Shot
How a manifest name pairs (contract/SPEC.md, “A shot’s name”).
Text
The gallery’s own words (contract/SPEC.md, “Text”), every one filled in. {title} in open is the screen’s title; {link} in credit is the link to VisualCI. label is the default title, and the gallery’s name when its title is null. and joins the values in an image’s alt text.
Thumb
Variant
Version
A version the manifest lists.
Versions
The Version switch (contract/SPEC.md, “The model”): the listed versions, the one shown and Latest’s manifest.

Enums§

Error
Why a gallery can’t be shown.
Missing
What a card does with no shot for the chosen value (contract/SPEC.md, “Dimensions”): Error, every screen needs every value; Hide, the card isn’t shown; First, it shows its own first value.
Preload
Predictive preloading other than the default (the model’s preload: "off", or the caps, every one filled in).
Shape
The shape of most of a size value’s images.

Constants§

NEW_DAYS
The New badge’s default window, in days.
SEARCH_FROM
The search box’s default threshold: shown once the gallery has this many screens.
SEE_ALL_TEXT
TEXT_DEFAULTS
The gallery’s own words by key, with their defaults (contract/SPEC.md, “Text”), in the model’s order.

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.
default_dimensions
The built-in dimensions: the theme (light, dark) and the size (desktop, phone below 768).
escape
& < > “ ’ as entities: the only escaping the contract allows, so every language’s output is the same.
humanize
["billing", "free"] → “Billing, free”.
manifest_url
The manifest to read for url: the main one, or with reference (a version’s label or key, v2.0.0), that version’s, …/<project>@<key>.json (contract/SPEC.md, “Pinning a version”). The key is the server’s: ASCII lower case, each run of anything else one hyphen, none at either end. Fails when that key is empty or latest, or url doesn’t end in .json.
options_json
The options as the Version switch carries them (the model’s versions.options): those of the contract’s table that are set and not null (a null title too), as canonical JSON (contract/SPEC.md, “The model”).
parse_shot
Trailing --separated tokens that are value keys of dimensions, a CSS width and 2x are peeled off the end, and the rest is the screen’s key (contract/SPEC.md, “A shot’s name”).
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.
screenshot
One screenshot as HTML: an <img>, or a <picture> with the dark shot for readers whose setting is dark. Fails when the manifest or the options are invalid, or the screen has no shot for what’s asked.
screenshot_markdown
One screenshot for a README: Markdown’s ![alt](url), linked with link, or the HTML <picture> when it has a dark shot.
slugify
A group’s name as an id: ASCII lower case, runs of anything else as one hyphen.

Type Aliases§

Values
A dimension’s value key per dimension key ({"theme": "dark", "size": "phone"}).