visualci-gallery 0.7.0

A screenshots page from VisualCI's public gallery, rendered in Rust (or an Askama template) and hydrated by the visualci-gallery script.
Documentation
# visualci-gallery (Rust)

A screenshots page from a VisualCI [public gallery](https://visualci.com/docs/gallery/) manifest, rendered in Rust as
the [gallery contract](https://github.com/DocSpring/visualci/blob/main/clients/gallery/contract/SPEC.md)'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.

The [Rust guide](https://visualci.com/docs/gallery/rust/) shows it in a build step, an Askama template, a Loco app and
an axum app.

```rust,no_run
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")?;
let gallery = Gallery::from_json(&manifest, &Options::default().title(None))?;
println!("{gallery}");
# Ok::<(), Box<dyn std::error::Error>>(())
```

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 }}`:

```rust,ignore
#[derive(askama::Template)]
#[template(path = "screenshots.html")]
struct Screenshots { gallery: visualci_gallery::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`, `dimension`, `screen`, `order`, `group`,
`group_order`, `credit`, `layout`, `theme_switch`, `see_all`, `preload`, `preload_caps`, `deep_links`, `text`, `search`,
`search_from`, `zoom`, `new_badges`, `new_badges_days`, `versions`), or
`Options::from_json` with the contract's JSON names.

Shots differ by theme (light, dark) and size (desktop, phone) out of the box. `.dimension(key, label, missing, values)`
changes those (`"theme"`, `"size"`) or adds one, such as a language; each value is `(key, label, below)`:

```rust
use visualci_gallery::Options;

let options = Options::default()
    .dimension("lang", Some("Language"), None, &[("en", Some("English"), None), ("fr", Some("Français"), None)]);
```

Predictive preloading is on by default. `.preload(false)` turns it off; `.preload_caps(fold, count, bytes, parallel)`
sets its caps, each an `Option<u64>` where `None` keeps the default (250, 500, 50000000, 4):

```rust
use visualci_gallery::Options;

let options = Options::default().preload_caps(None, Some(100), Some(20_000_000), None);
```

`.deep_links(true)` makes the page's URL name the open tab, screen and values, so a link opens them. `.text(key,
value)` changes one of the gallery's own words, for another language: `label`, `open` (`{title}` is the screen's title),
`previous`, `next`, `close`, `back`, `forward`, `credit` (`{link}` is the link to VisualCI), `and`, `search`, `empty`, `new`,
`change` (`{title}` is the screen's title), `version` or `latest`. An unknown key is an error when the gallery renders.

```rust
use visualci_gallery::Options;

let options = Options::default().deep_links(true).text("label", "Captures d'écran").text("close", "Fermer");
```

The grid gets a search box, which filters the cards by title and caption across tabs, once the gallery has 40
screens: `.search_from(n)` changes that number (0 to 1000000), `.search(true)` always shows it and `.search(false)`
never does. The strip has none. Zoom in the full-size view (pinch, ctrl-wheel, double-click, `+` and `-`) is on by
default; `.zoom(false)` turns it off. `.new_badges(true)` puts a New badge on each screen whose picture changed in the
last 30 days, decided in the reader's browser; `.new_badges_days(days)` sets the window (1 to 3650):

```rust
use visualci_gallery::Options;

let options = Options::default().search_from(10).zoom(false).new_badges_days(14);
```

When the project reports releases ([Versions](https://visualci.com/docs/gallery/versions/)), `.versions(true)` adds a
Version switch to the grid: Latest and each release, read in the reader's browser. For a page that always shows one
release (versioned docs), `manifest_url(url, Some(reference))` gives that version's manifest from the main one's URL and
a version's label or key (`v2.0.0` reads `…/<project>@v2-0-0.json`); fetch and render that one. A reference whose key
is empty or `latest`, or a URL that doesn't end in `.json`, is an error.

```rust
use visualci_gallery::{Options, manifest_url};

let url = manifest_url("https://app.visualci.com/g/acme/web.json", Some("v2.0.0"))?;
assert_eq!(url, "https://app.visualci.com/g/acme/web@v2-0-0.json");
let options = Options::default().versions(true);
# Ok::<(), visualci_gallery::Error>(())
```

## One screenshot

`screenshot(&manifest, &ScreenshotOptions::new("overview"))` returns one screenshot as HTML, an `<img>` or a `<picture>` with the dark shot, and the
Markdown function a README's form ([One screenshot](https://visualci.com/docs/gallery/screenshot/)).

## Development

`cargo test --all-features` checks the contract's golden fixtures, refusals and messages.