rastrillo / fiesta Public

Clone
git clone https://amadan.net/rastrillo/fiesta

Plain git — no account needed to clone.

Download

Download this file

1package fiesta
2
3import (
4 _ "embed"
5 "encoding/json"
6 "maps"
7 "sync"
8)
9
10// Source says where one example state came from when the examples were
11// seeded: the kind of thing it was in the gallery it was taken from (a
12// partial, an idiom, a shell, a format or a screen), that thing's name,
13// which of its states, the locale it was rendered in, and, for a shell,
14// which view of it (index or page). A server whose templates render the
15// same parts can hold its output to the example a Source names.
16type Source struct {
17 Kind string `json:"kind"`
18 Source string `json:"source"`
19 State int `json:"state"`
20 Locale string `json:"locale"`
21 View string `json:"view,omitempty"`
22}
23
24// sourcesJSON is the seed's record, kept where the seeding wrote it.
25//
26//go:embed hack/seed/sources.json
27var sourcesJSON []byte
28
29// sources is sourcesJSON read once. The file is embedded, so a record
30// that does not read is a broken build rather than a condition to
31// report: the panic says so.
32var sources = sync.OnceValue(func() map[string]Source {
33 var out map[string]Source
34 if err := json.Unmarshal(sourcesJSON, &out); err != nil {
35 panic("fiesta: hack/seed/sources.json does not read: " + err.Error())
36 }
37 return out
38})
39
40// Sources returns where every seeded example state came from, keyed by
41// its path under examples/ without the .html: "badge/positive" for
42// examples/badge/positive.html. The returned map is a copy, so a caller
43// that edits it cannot change the next caller's.
44func Sources() map[string]Source { return maps.Clone(sources()) }
45