// Command mockups renders docs/mockups/*.html from docs/mockups/src.
//
// The mockups are rendered with the SAME templates production uses —
// rastrillo's ui partials, its sidebar shell and this app's icon set —
// so a mockup can only be built from components that actually exist.
// That is the point: the first surface shipped with two invented
// attributes (rst-stack, rst-muted) that no stylesheet defines, and the
// browser's defaults showed through as a bullet and an underlined link.
//
// Anything the partials do not provide is in docs/mockups/proposed.css,
// under a fichas- prefix and never rst-, so that what is framework and
// what is this app's own addition can be told apart at a glance.
//
// Stylesheets are linked from the live app, so the output is standalone
// HTML that opens anywhere and looks exactly like production.
//
// go run ./scripts/mockups
package main
import (
"bytes"
"fmt"
"html/template"
"os"
"path/filepath"
"regexp"
"sort"
"strings"
"amadan.net/rastrillo/rastrillo/ui"
"amadan.net/oficina/fichas/internal/fichas/icons"
)
const live = "https://fichas.oficina.works/"
type field struct {
Key, Label, Kind, Tier string
OnFace bool
}
type call struct {
When, Ago, Body string
}
type record struct {
ID int
Name, Domain, Email, Phone, Stage string
Tone string
NextAction, NextActionAgo, LastCallAgo string
Owner, Updated, Notes string
Calls []call
}
func main() {
// Synthetic throughout, on the .example TLD RFC 2606 reserves: an
// invented company name once turned out to be a real business Paul
// was talking to.
fields := []field{
{"f_name", "Name", "Text", "Findable", true},
{"f_domain", "Domain", "Text", "Findable", false},
{"f_email", "Email", "Text", "Findable", true},
{"f_phone", "Phone", "Text", "Findable", false},
{"f_stage", "Stage", "Choice", "Private", true},
{"f_next_action", "Next action", "Date", "Private", true},
{"f_notes", "Notes", "Long text", "Private", false},
}
records := []record{
{1, "Brightwater Labs", "brightwater.example", "ana@brightwater.example", "+353 1 555 0142", "Proposal", "warning",
"2 October 2026", "in 3 days", "2 days ago", "Paul", "2 days ago",
"Renewal is tied to their grant cycle. Ana is the budget holder; Tom signs.",
[]call{
{"27 September 2026", "2 days ago", "Walked Ana through the proposal. She wants the pilot scoped to one department first."},
{"18 September 2026", "11 days ago", "Intro call. Current tool is a shared spreadsheet; they lose track of follow-ups."},
{"9 September 2026", "3 weeks ago", "Met at the conference. Asked for a follow-up after their board meets."},
}},
{2, "Cedar & Pike Architects", "cedarpike.example", "office@cedarpike.example", "", "Lead", "neutral",
"", "", "", "Paul", "5 days ago", "", nil},
{3, "Halden Robotics", "halden.example", "ops@halden.example", "+44 20 5550 1877", "Contacted", "neutral",
"30 September 2026", "tomorrow", "1 week ago", "Paul", "1 week ago", "",
[]call{{"22 September 2026", "1 week ago", "Left a voicemail; followed up by email."}}},
{4, "Oriel Housing Trust", "oriel.example", "it@oriel.example", "", "Won", "positive",
"", "", "3 weeks ago", "Paul", "3 weeks ago", "", nil},
}
pages := []struct{ file, title string }{
{"index", "fichas mockups"},
{"database", "Customers — table"},
{"field", "Add a field"},
{"cards", "Customers — cards"},
{"card-layout", "Arrange the card"},
{"show", "Brightwater Labs"},
{"edit", "Edit Brightwater Labs"},
}
if err := checkAttributes(); err != nil {
fail(err)
}
// icons.Icon returns "" for a slug it does not know, so an icon that
// is missing from the app's set renders as nothing and nobody notices.
// Six of the first seven in these mockups were missing. Refuse.
var missing []string
strictIcon := func(slug string) template.HTML {
h := icons.Icon(slug)
if h == "" {
missing = append(missing, slug)
}
return h
}
shell, ok := ui.Layout("sidebar")
if !ok {
fail(fmt.Errorf("rastrillo has no sidebar layout"))
}
for _, p := range pages {
t := template.Must(template.Must(template.Must(
template.New("layout").
Funcs(ui.Funcs(ui.WithIcons(strictIcon, icons.Assets))).
Funcs(template.FuncMap{"asset": func(s string) string { return live + s }, "add1": func(i int) int { return i + 1 }}).
ParseFS(ui.Templates(), "*.html")).
Parse(string(shell))).
ParseFiles("docs/mockups/src/_shared.html", "docs/mockups/src/"+p.file+".html"))
var buf bytes.Buffer
data := map[string]any{
"Title": p.title,
"Page": p.file,
"Fields": fields,
"Records": records,
"Record": records[0],
"Live": live,
}
if err := t.ExecuteTemplate(&buf, "layout", data); err != nil {
fail(fmt.Errorf("%s: %w", p.file, err))
}
out := filepath.Join("docs/mockups", p.file+".html")
if err := os.WriteFile(out, buf.Bytes(), 0o644); err != nil {
fail(err)
}
fmt.Println("wrote", out)
}
if len(missing) > 0 {
sort.Strings(missing)
fail(fmt.Errorf("icon slugs not in internal/fichas/icons: %s", strings.Join(missing, ", ")))
}
}
var (
tagRe = regexp.MustCompile(`<[a-zA-Z][^>]*>`)
attrRe = regexp.MustCompile(`\s((?:rst|fichas)-[a-z0-9-]+)`)
selectorRe = regexp.MustCompile(`\[((?:rst|fichas)-[a-z0-9-]+)`)
)
// checkAttributes refuses any rst-* or fichas-* attribute written in a
// mockup's OWN markup that no stylesheet defines.
//
// The first surface shipped rst-stack and rst-muted, which rastrillo
// does not have; with no rule behind them the browser's defaults showed
// through as a bullet and an underlined link. Only the mockup sources
// are checked, not what the ui partials emit: the partials are the
// framework's, and some of their attributes are script hooks rather than
// styles. The risk is invented vocabulary, and that lives in our markup.
func checkAttributes() error {
defined := map[string]bool{}
for _, css := range []string{
"internal/fichas/static/tokens.css",
"internal/fichas/static/theme.css",
"internal/fichas/static/brand/brand.css",
"docs/mockups/proposed.css",
} {
b, err := os.ReadFile(css)
if err != nil {
return err
}
for _, m := range selectorRe.FindAllStringSubmatch(string(b), -1) {
defined[m[1]] = true
}
}
srcs, _ := filepath.Glob("docs/mockups/src/*.html")
var bad []string
for _, f := range srcs {
b, err := os.ReadFile(f)
if err != nil {
return err
}
for _, tag := range tagRe.FindAllString(string(b), -1) {
for _, m := range attrRe.FindAllStringSubmatch(tag, -1) {
if !defined[m[1]] {
bad = append(bad, filepath.Base(f)+": "+m[1])
}
}
}
}
if len(bad) > 0 {
sort.Strings(bad)
return fmt.Errorf("attributes no stylesheet defines:\n %s", strings.Join(bad, "\n "))
}
return nil
}
func fail(err error) {
fmt.Fprintln(os.Stderr, "mockups:", err)
os.Exit(1)
}