Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,9 @@ jobs:
ruby-version: "3.4"
- run: ruby -Ilib spec/visualci_spec.rb
working-directory: clients/ruby
# The gallery's Ruby renderer: the contract's golden fixtures.
- run: ruby -Ilib test/gallery_test.rb
working-directory: clients/gallery/ruby
- uses: pnpm/action-setup@v4
with:
package_json_file: frontend/package.json
Expand All @@ -437,6 +440,9 @@ jobs:
# real astro build).
- run: pnpm install --frozen-lockfile && pnpm --filter visualci-gallery typecheck && pnpm build && pnpm test
working-directory: clients/gallery
# The gem carries the library's built script and stylesheet, and the licence: it builds with them.
- run: bin/assets && gem build visualci-gallery.gemspec && tar -xOf visualci-gallery-*.gem data.tar.gz | tar -tz > /tmp/gem-files && grep -x app/assets/javascripts/visualci_gallery.js /tmp/gem-files && grep -x LICENSE /tmp/gem-files
working-directory: clients/gallery/ruby
# The Compare two PDFs page runs crates/visualci-wasm in the browser (scripts/wasm.mjs builds it).
- run: rustup target add wasm32-unknown-unknown
# Compile cache (kache, as Cargo's rustc wrapper): the R2 bucket every machine shares (KACHE_BUCKET), else the
Expand Down
45 changes: 45 additions & 0 deletions .github/workflows/release-gallery-gem.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Publish the visualci-gallery gem (clients/gallery/ruby) to RubyGems with trusted publishing: RubyGems trusts this
# workflow through GitHub's OIDC token, so no API key is stored anywhere. Runs for a gallery-ruby-v* tag (matching
# VisualCI::Gallery::VERSION) or by hand. The gem carries the JS library's ES5 build and stylesheet (bin/assets).
name: Release gallery gem

on:
push:
tags: ["gallery-ruby-v*"]
workflow_dispatch:

permissions:
contents: read
id-token: write

jobs:
publish:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
with:
package_json_file: clients/gallery/package.json
- uses: actions/setup-node@v4
with:
node-version: "24"
- run: pnpm install --frozen-lockfile && pnpm --filter visualci-gallery build
working-directory: clients/gallery
- uses: ruby/setup-ruby@v1
with:
ruby-version: "3.4"
- name: The tag matches the gem's version
if: startsWith(github.ref, 'refs/tags/gallery-ruby-v')
working-directory: clients/gallery/ruby
run: |
version=$(ruby -r ./lib/visualci/gallery/version -e 'print VisualCI::Gallery::VERSION')
test "gallery-ruby-v$version" = "$GITHUB_REF_NAME" || { echo "tag $GITHUB_REF_NAME, gem $version"; exit 1; }
- run: ruby -Ilib test/gallery_test.rb
working-directory: clients/gallery/ruby
- uses: rubygems/configure-rubygems-credentials@v2.2.0
with:
# The RubyGems.org account that owns the gem (needed for the first push through a pending trusted publisher).
owner: "48431"
- run: bin/assets && gem build visualci-gallery.gemspec && gem push visualci-gallery-*.gem
working-directory: clients/gallery/ruby
6 changes: 4 additions & 2 deletions clients/gallery/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ variables.
fixtures every renderer's tests check.
- [`js/`](js/README.md): `visualci-gallery`, the browser library and reference renderer.
- [`astro/`](astro/README.md): `visualci-astro-gallery`, rendered when the site builds and hydrated by the library.
- [`ruby/`](ruby/README.md): the `visualci-gallery` gem, with a Rails helper and the library's files for the asset
pipeline.

A pnpm workspace: `pnpm install && pnpm build && pnpm test` here. Coming: the Ruby gem, the Python package and the Rust
crate, each emitting the contract's markup for the JS library to hydrate.
A pnpm workspace: `pnpm install && pnpm build && pnpm test` here. Coming: the Python package and the Rust crate, each
emitting the contract's markup for the JS library to hydrate.
10 changes: 7 additions & 3 deletions clients/gallery/contract/SPEC.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ word for word, in every language. An invalid option's message names it in the co

- The manifest is an object with a `groups` array. Each group is an object with a non-empty string `name`, a `title`
that's absent, null or a string, and an `items` array (possibly empty). Each item is an object with a non-empty
string `name`, a `url`, and a `width` and `height` that are positive integers (JSON numbers with no fraction).
string `name`, a `url`, and a `width` and `height` that are whole numbers from 1 to 1000000 (JSON numbers with no
fraction; the limit keeps the density maths below exact in every language's numbers).
- An item's `url` must be an absolute http or https URL: it starts with `http://` or `https://` (scheme in any case)
and has no character from U+0000 to U+0020 or U+007F anywhere (browsers drop those, so `java\tscript:` would
still run).
Expand All @@ -54,6 +55,8 @@ word for word, in every language. An invalid option's message names it in the co
`themeSwitch` booleans; `layout` `"grid"` or `"strip"`; `seeAll` an object with a string `href` and a `text` that's
absent, null or a string. `seeAll.href` is an absolute URL as above, or a relative one: not empty, no character from
U+0000 to U+0020 or U+007F, and not starting with a scheme (`^[A-Za-z][A-Za-z0-9+.-]*:`).
- The manifest is checked first, then the options in this order, and the first problem is the error: `headingLevel`,
`title`, `id`, `screens`, `groups`, `order`, `groupOrder`, `credit`, `themeSwitch`, `layout`, `seeAll`.
- Other fields, in the manifest or the options, are ignored.

## Reading the manifest
Expand Down Expand Up @@ -93,8 +96,9 @@ ASCII digits only, and `.` means any character at all, line breaks included:
3. Otherwise the key is the whole name without its extension, with no theme (it stands for both), no CSS width, not
2x.

Size: with a CSS width, under 768 is `phone`, else `desktop`. Without one, the group's `size` option when set, else
an image taller than it is wide (`height > width`) is `phone`, else `desktop`.
Size: with a CSS width (the number's value: leading zeros don't count, so `0390` is 390), under 768 is `phone`, else
`desktop`. Without one, the group's `size` option when set, else an image taller than it is wide (`height > width`)
is `phone`, else `desktop`.

### Pairing

Expand Down
2 changes: 1 addition & 1 deletion clients/gallery/contract/errors/fractional-size.message
Original file line number Diff line number Diff line change
@@ -1 +1 @@
gallery manifest group Web, item 0 (a-light-1440): its width and height aren't positive integers
gallery manifest group Web, item 0 (a-light-1440): its width and height aren't whole numbers from 1 to 1000000
2 changes: 1 addition & 1 deletion clients/gallery/contract/errors/no-size.message
Original file line number Diff line number Diff line change
@@ -1 +1 @@
gallery manifest group Web, item 0 (a-light-1440): its width and height aren't positive integers
gallery manifest group Web, item 0 (a-light-1440): its width and height aren't whole numbers from 1 to 1000000
1 change: 1 addition & 0 deletions clients/gallery/contract/errors/too-wide.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"groups": [{"name": "Web", "items": [{"name": "a-light-1440", "url": "https://app.visualci.com/g/acme/web/a.png", "width": 1000001, "height": 900}]}]}
1 change: 1 addition & 0 deletions clients/gallery/contract/errors/too-wide.message
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
gallery manifest group Web, item 0 (a-light-1440): its width and height aren't whole numbers from 1 to 1000000
13 changes: 13 additions & 0 deletions clients/gallery/contract/fixtures/widths/gallery.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<section class="vg" data-vg data-vg-layout="grid" aria-label="Screenshots" data-vg-size="desktop">
<div class="vg-panel" id="vg-panel-web" data-vg-sizes="desktop phone">
<div class="vg-bar"><h2 class="vg-group-title">Web</h2><div class="vg-controls"><div class="vg-seg" role="group" aria-label="Theme"><button type="button" data-vg-set-theme="light" aria-pressed="false">Light</button><button type="button" data-vg-set-theme="dark" aria-pressed="false">Dark</button></div><div class="vg-seg" role="group" aria-label="Screen size"><button type="button" data-vg-set-size="desktop" aria-pressed="false">Desktop</button><button type="button" data-vg-set-size="phone" aria-pressed="false">Phone</button></div></div></div>
<ul class="vg-grid">
<li class="vg-card" data-vg-screen="home" data-vg-sizes="desktop phone"><a class="vg-thumb" href="https://app.visualci.com/g/acme/web/home-light-1440.png" data-vg-open aria-label="Home: view full size"><img class="vg-img" data-vg-size="desktop" data-vg-theme="light" src="https://app.visualci.com/g/acme/web/home-light-1440.png" width="1440" height="900" alt="Home, desktop, light" loading="lazy" decoding="async"><img class="vg-img" data-vg-size="desktop" data-vg-theme="dark" src="https://app.visualci.com/g/acme/web/home-dark-1440.png" width="1440" height="900" alt="Home, desktop, dark" loading="lazy" decoding="async"><img class="vg-img" data-vg-size="phone" data-vg-theme="light" src="https://app.visualci.com/g/acme/web/home-light-0000000000000000000390.png" width="390" height="844" alt="Home, phone, light" loading="lazy" decoding="async"><img class="vg-img" data-vg-size="phone" data-vg-theme="dark" src="https://app.visualci.com/g/acme/web/home-dark-0000000000000000000390.png" width="390" height="844" alt="Home, phone, dark" loading="lazy" decoding="async"></a><h3 class="vg-card-title">Home</h3></li>
</ul>
</div>
<p class="vg-credit">Screenshot Gallery Powered by <a href="https://visualci.com">VisualCI.com</a></p>
<dialog class="vg-box" aria-labelledby="vg-box-title">
<div class="vg-box-bar"><h2 class="vg-box-title" id="vg-box-title"></h2><div class="vg-controls"><div class="vg-seg" role="group" aria-label="Theme"><button type="button" data-vg-set-theme="light" aria-pressed="false">Light</button><button type="button" data-vg-set-theme="dark" aria-pressed="false">Dark</button></div><div class="vg-seg vg-box-sizes" role="group" aria-label="Screen size"><button type="button" data-vg-set-size="desktop" aria-pressed="false">Desktop</button><button type="button" data-vg-set-size="phone" aria-pressed="false">Phone</button></div><button type="button" class="vg-icon" data-vg-step="-1" aria-label="Previous screen">‹</button><button type="button" class="vg-icon" data-vg-step="1" aria-label="Next screen">›</button><button type="button" class="vg-icon" data-vg-close aria-label="Close">×</button></div></div>
<div class="vg-box-view"></div>
</dialog>
</section>
46 changes: 46 additions & 0 deletions clients/gallery/contract/fixtures/widths/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"project": "acme/web",
"groups": [
{
"name": "Web",
"items": [
{
"name": "home-light-1440",
"platform": "",
"url": "https://app.visualci.com/g/acme/web/home-light-1440.png",
"width": 2880,
"height": 1800,
"sha256": "s-home-light-1440",
"since": "2026-12-01T09:00:00+00:00"
},
{
"name": "home-dark-1440",
"platform": "",
"url": "https://app.visualci.com/g/acme/web/home-dark-1440.png",
"width": 2880,
"height": 1800,
"sha256": "s-home-dark-1440",
"since": "2026-12-01T09:00:00+00:00"
},
{
"name": "home-light-0000000000000000000390",
"platform": "",
"url": "https://app.visualci.com/g/acme/web/home-light-0000000000000000000390.png",
"width": 780,
"height": 1688,
"sha256": "s-home-light-0000000000000000000390",
"since": "2026-12-01T09:00:00+00:00"
},
{
"name": "home-dark-0000000000000000000390",
"platform": "",
"url": "https://app.visualci.com/g/acme/web/home-dark-0000000000000000000390.png",
"width": 780,
"height": 1688,
"sha256": "s-home-dark-0000000000000000000390",
"since": "2026-12-01T09:00:00+00:00"
}
]
}
]
}
63 changes: 63 additions & 0 deletions clients/gallery/contract/fixtures/widths/model.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"layout": "grid",
"themeSwitch": true,
"seeAll": null,
"title": null,
"label": "Screenshots",
"headingLevel": 2,
"id": "vg",
"credit": true,
"groups": [
{
"name": "Web",
"title": "Web",
"slug": "web",
"fit": "cover",
"sizes": [
"desktop",
"phone"
],
"screens": [
{
"key": "home",
"title": "Home",
"caption": null,
"variants": [
{
"size": "desktop",
"theme": "light",
"url": "https://app.visualci.com/g/acme/web/home-light-1440.png",
"url2x": null,
"width": 1440,
"height": 900
},
{
"size": "desktop",
"theme": "dark",
"url": "https://app.visualci.com/g/acme/web/home-dark-1440.png",
"url2x": null,
"width": 1440,
"height": 900
},
{
"size": "phone",
"theme": "light",
"url": "https://app.visualci.com/g/acme/web/home-light-0000000000000000000390.png",
"url2x": null,
"width": 390,
"height": 844
},
{
"size": "phone",
"theme": "dark",
"url": "https://app.visualci.com/g/acme/web/home-dark-0000000000000000000390.png",
"url2x": null,
"width": 390,
"height": 844
}
]
}
]
}
]
}
1 change: 1 addition & 0 deletions clients/gallery/contract/fixtures/widths/options.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"title": null}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"seeAll": 5, "layout": "y", "themeSwitch": "x", "credit": "x", "groupOrder": 5, "order": 5, "id": "1", "screens": 5}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
gallery option id is invalid
6 changes: 4 additions & 2 deletions clients/gallery/js/src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,9 @@ function fail(message: string): never {
throw new Error(message);
}
const isObject = (v: unknown): v is Record<string, unknown> => typeof v === "object" && v !== null && !Array.isArray(v);
const isSize = (v: unknown) => typeof v === "number" && Number.isInteger(v) && v > 0;
/** A width or height: a whole number from 1 to MAX_SIZE, so the density maths stays exact in every language. */
export const MAX_SIZE = 1_000_000;
const isSize = (v: unknown) => typeof v === "number" && Number.isInteger(v) && v > 0 && v <= MAX_SIZE;
/** An option's value, with null meaning absent. */
function opt<T>(value: T | null | undefined, check: (v: T) => boolean, what: string): T | undefined {
if (value === null || value === undefined) return undefined;
Expand All @@ -232,7 +234,7 @@ function checkManifest(manifest: unknown): asserts manifest is Manifest {
const where = `gallery manifest group ${g.name}, item ${j}`;
if (!isObject(item) || typeof item.name !== "string" || item.name === "") fail(`${where} has no name`);
if (typeof item.url !== "string" || !ABSOLUTE.test(item.url)) fail(`${where} (${item.name}): its url isn't an http(s) URL`);
if (!isSize(item.width) || !isSize(item.height)) fail(`${where} (${item.name}): its width and height aren't positive integers`);
if (!isSize(item.width) || !isSize(item.height)) fail(`${where} (${item.name}): its width and height aren't whole numbers from 1 to 1000000`);
});
});
}
Expand Down
3 changes: 3 additions & 0 deletions clients/gallery/ruby/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
app/assets/
*.gem
/LICENSE
45 changes: 45 additions & 0 deletions clients/gallery/ruby/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# visualci-gallery (Ruby)

A screenshots page from a VisualCI [public gallery](https://visualci.com/docs/gallery/) manifest, rendered in Ruby as
the [gallery contract](../contract/SPEC.md)'s markup: byte for byte what the `visualci-gallery` JS library renders, so
the library's script hydrates it (tabs, light and dark, desktop and phone, the full-size view).

```ruby
require 'visualci/gallery'

manifest = VisualCI::Gallery.fetch('https://app.visualci.com/g/acme/web.json') # raises VisualCI::Gallery::Error
html = VisualCI::Gallery.render(manifest, title: nil, layout: 'strip', theme_switch: false,
screens: { 'screenshots/templates' => { title: 'Templates' } },
see_all: { href: '/screenshots' })
```

`fetch` raises when the manifest can't be read, and `render` raises when it has nothing to show or the options are
invalid. A site that mustn't fail at request time fetches the manifest when it builds (a Docker build step that
writes it to a file, failing the build if it can't) and renders from that file.

## Rails

The gem's engine adds a view helper and serves the library's files to the asset pipeline:

```erb
<%= stylesheet_link_tag 'visualci_gallery' %>
<%= visualci_gallery(JSON.parse(File.read(Rails.root.join('config/screenshots.json'))), title: nil) %>
<%= javascript_include_tag 'visualci_gallery' %>
<script nonce="<%= content_security_policy_nonce %>">
document.querySelectorAll('[data-vg]').forEach(function (el) { VisualCIGallery.hydrate(el); });
</script>
```

`visualci_gallery.js` is the library's ES5 build (it sets `window.VisualCIGallery`); `visualci_gallery.css` is its
stylesheet, styled through the `--vg-*` CSS variables.

## Options

Keyword arguments, the contract's options in Ruby spelling: `title` (default "Screenshots"; `nil` for no heading),
`heading_level`, `id`, `screens`, `order`, `groups` (`{ 'Mac approver' => { size: 'desktop', fit: 'contain' } }` for an app's windows), `group_order`, `credit`, `layout` (`'grid'` or `'strip'`),
`theme_switch`, `see_all`. Hash keys may be strings or symbols.

## Development

`ruby -Ilib test/gallery_test.rb` checks the contract's golden fixtures. `bin/assets` copies the JS library's build
into `app/assets` before `gem build`.
12 changes: 12 additions & 0 deletions clients/gallery/ruby/bin/assets
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh
# Copies the JS library's ES5 build and stylesheet into app/assets, where the Rails engine serves them, and the repo's
# LICENSE, which the gem carries. Run before `gem build` (the release workflow does), after `pnpm build` in
# clients/gallery.
set -eu
here=$(cd "$(dirname "$0")/.." && pwd)
dist=$here/../js/dist
[ -f "$dist/gallery.iife.js" ] || { echo "no $dist/gallery.iife.js: run pnpm build in clients/gallery first" >&2; exit 1; }
mkdir -p "$here/app/assets/javascripts" "$here/app/assets/stylesheets"
cp "$dist/gallery.iife.js" "$here/app/assets/javascripts/visualci_gallery.js"
cp "$dist/gallery.css" "$here/app/assets/stylesheets/visualci_gallery.css"
cp "$here/../../../LICENSE" "$here/LICENSE"
Loading
Loading