| 1 | // Command mockups renders docs/mockups/*.html from docs/mockups/src. |
| 2 | // |
| 3 | // The mockups are rendered with the SAME templates production uses — |
| 4 | // rastrillo's ui partials, its sidebar shell and this app's icon set — |
| 5 | // so a mockup can only be built from components that actually exist. |
| 6 | // That is the point: the first surface shipped with two invented |
| 7 | // attributes (rst-stack, rst-muted) that no stylesheet defines, and the |
| 8 | // browser's defaults showed through as a bullet and an underlined link. |
| 9 | // |
| 10 | // Anything the partials do not provide is in docs/mockups/proposed.css, |
| 11 | // under a fichas- prefix and never rst-, so that what is framework and |
| 12 | // what is this app's own addition can be told apart at a glance. |
| 13 | // |
| 14 | // Stylesheets are linked from the live app, so the output is standalone |
| 15 | // HTML that opens anywhere and looks exactly like production. |
| 16 | // |
| 17 | // go run ./scripts/mockups |
| 18 | package main |
| 19 | |
| 20 | import ( |
| 21 | "bytes" |
| 22 | "fmt" |
| 23 | "html/template" |
| 24 | "os" |
| 25 | "path/filepath" |
| 26 | "regexp" |
| 27 | "sort" |
| 28 | "strings" |
| 29 | |
| 30 | "amadan.net/rastrillo/rastrillo/ui" |
| 31 | |
| 32 | "amadan.net/oficina/fichas/internal/fichas/icons" |
| 33 | ) |
| 34 | |
| 35 | const live = "https://fichas.oficina.works/" |
| 36 | |
| 37 | type field struct { |
| 38 | Key, Label, Kind, Tier string |
| 39 | OnFace bool |
| 40 | } |
| 41 | |
| 42 | type call struct { |
| 43 | When, Ago, Body string |
| 44 | } |
| 45 | |
| 46 | type record struct { |
| 47 | ID int |
| 48 | Name, Domain, Email, Phone, Stage string |
| 49 | Tone string |
| 50 | NextAction, NextActionAgo, LastCallAgo string |
| 51 | Owner, Updated, Notes string |
| 52 | Calls []call |
| 53 | } |
| 54 | |
| 55 | func main() { |
| 56 | // Synthetic throughout, on the .example TLD RFC 2606 reserves: an |
| 57 | // invented company name once turned out to be a real business Paul |
| 58 | // was talking to. |
| 59 | fields := []field{ |
| 60 | {"f_name", "Name", "Text", "Findable", true}, |
| 61 | {"f_domain", "Domain", "Text", "Findable", false}, |
| 62 | {"f_email", "Email", "Text", "Findable", true}, |
| 63 | {"f_phone", "Phone", "Text", "Findable", false}, |
| 64 | {"f_stage", "Stage", "Choice", "Private", true}, |
| 65 | {"f_next_action", "Next action", "Date", "Private", true}, |
| 66 | {"f_notes", "Notes", "Long text", "Private", false}, |
| 67 | } |
| 68 | records := []record{ |
| 69 | {1, "Brightwater Labs", "brightwater.example", "ana@brightwater.example", "+353 1 555 0142", "Proposal", "warning", |
| 70 | "2 October 2026", "in 3 days", "2 days ago", "Paul", "2 days ago", |
| 71 | "Renewal is tied to their grant cycle. Ana is the budget holder; Tom signs.", |
| 72 | []call{ |
| 73 | {"27 September 2026", "2 days ago", "Walked Ana through the proposal. She wants the pilot scoped to one department first."}, |
| 74 | {"18 September 2026", "11 days ago", "Intro call. Current tool is a shared spreadsheet; they lose track of follow-ups."}, |
| 75 | {"9 September 2026", "3 weeks ago", "Met at the conference. Asked for a follow-up after their board meets."}, |
| 76 | }}, |
| 77 | {2, "Cedar & Pike Architects", "cedarpike.example", "office@cedarpike.example", "", "Lead", "neutral", |
| 78 | "", "", "", "Paul", "5 days ago", "", nil}, |
| 79 | {3, "Halden Robotics", "halden.example", "ops@halden.example", "+44 20 5550 1877", "Contacted", "neutral", |
| 80 | "30 September 2026", "tomorrow", "1 week ago", "Paul", "1 week ago", "", |
| 81 | []call{{"22 September 2026", "1 week ago", "Left a voicemail; followed up by email."}}}, |
| 82 | {4, "Oriel Housing Trust", "oriel.example", "it@oriel.example", "", "Won", "positive", |
| 83 | "", "", "3 weeks ago", "Paul", "3 weeks ago", "", nil}, |
| 84 | } |
| 85 | |
| 86 | pages := []struct{ file, title string }{ |
| 87 | {"index", "fichas mockups"}, |
| 88 | {"database", "Customers — table"}, |
| 89 | {"field", "Add a field"}, |
| 90 | {"cards", "Customers — cards"}, |
| 91 | {"card-layout", "Arrange the card"}, |
| 92 | {"show", "Brightwater Labs"}, |
| 93 | {"edit", "Edit Brightwater Labs"}, |
| 94 | } |
| 95 | |
| 96 | if err := checkAttributes(); err != nil { |
| 97 | fail(err) |
| 98 | } |
| 99 | |
| 100 | // icons.Icon returns "" for a slug it does not know, so an icon that |
| 101 | // is missing from the app's set renders as nothing and nobody notices. |
| 102 | // Six of the first seven in these mockups were missing. Refuse. |
| 103 | var missing []string |
| 104 | strictIcon := func(slug string) template.HTML { |
| 105 | h := icons.Icon(slug) |
| 106 | if h == "" { |
| 107 | missing = append(missing, slug) |
| 108 | } |
| 109 | return h |
| 110 | } |
| 111 | |
| 112 | shell, ok := ui.Layout("sidebar") |
| 113 | if !ok { |
| 114 | fail(fmt.Errorf("rastrillo has no sidebar layout")) |
| 115 | } |
| 116 | |
| 117 | for _, p := range pages { |
| 118 | t := template.Must(template.Must(template.Must( |
| 119 | template.New("layout"). |
| 120 | Funcs(ui.Funcs(ui.WithIcons(strictIcon, icons.Assets))). |
| 121 | Funcs(template.FuncMap{"asset": func(s string) string { return live + s }, "add1": func(i int) int { return i + 1 }}). |
| 122 | ParseFS(ui.Templates(), "*.html")). |
| 123 | Parse(string(shell))). |
| 124 | ParseFiles("docs/mockups/src/_shared.html", "docs/mockups/src/"+p.file+".html")) |
| 125 | |
| 126 | var buf bytes.Buffer |
| 127 | data := map[string]any{ |
| 128 | "Title": p.title, |
| 129 | "Page": p.file, |
| 130 | "Fields": fields, |
| 131 | "Records": records, |
| 132 | "Record": records[0], |
| 133 | "Live": live, |
| 134 | } |
| 135 | if err := t.ExecuteTemplate(&buf, "layout", data); err != nil { |
| 136 | fail(fmt.Errorf("%s: %w", p.file, err)) |
| 137 | } |
| 138 | out := filepath.Join("docs/mockups", p.file+".html") |
| 139 | if err := os.WriteFile(out, buf.Bytes(), 0o644); err != nil { |
| 140 | fail(err) |
| 141 | } |
| 142 | fmt.Println("wrote", out) |
| 143 | } |
| 144 | if len(missing) > 0 { |
| 145 | sort.Strings(missing) |
| 146 | fail(fmt.Errorf("icon slugs not in internal/fichas/icons: %s", strings.Join(missing, ", "))) |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | var ( |
| 151 | tagRe = regexp.MustCompile(`<[a-zA-Z][^>]*>`) |
| 152 | attrRe = regexp.MustCompile(`\s((?:rst|fichas)-[a-z0-9-]+)`) |
| 153 | selectorRe = regexp.MustCompile(`\[((?:rst|fichas)-[a-z0-9-]+)`) |
| 154 | ) |
| 155 | |
| 156 | // checkAttributes refuses any rst-* or fichas-* attribute written in a |
| 157 | // mockup's OWN markup that no stylesheet defines. |
| 158 | // |
| 159 | // The first surface shipped rst-stack and rst-muted, which rastrillo |
| 160 | // does not have; with no rule behind them the browser's defaults showed |
| 161 | // through as a bullet and an underlined link. Only the mockup sources |
| 162 | // are checked, not what the ui partials emit: the partials are the |
| 163 | // framework's, and some of their attributes are script hooks rather than |
| 164 | // styles. The risk is invented vocabulary, and that lives in our markup. |
| 165 | func checkAttributes() error { |
| 166 | defined := map[string]bool{} |
| 167 | for _, css := range []string{ |
| 168 | "internal/fichas/static/tokens.css", |
| 169 | "internal/fichas/static/theme.css", |
| 170 | "internal/fichas/static/brand/brand.css", |
| 171 | "docs/mockups/proposed.css", |
| 172 | } { |
| 173 | b, err := os.ReadFile(css) |
| 174 | if err != nil { |
| 175 | return err |
| 176 | } |
| 177 | for _, m := range selectorRe.FindAllStringSubmatch(string(b), -1) { |
| 178 | defined[m[1]] = true |
| 179 | } |
| 180 | } |
| 181 | srcs, _ := filepath.Glob("docs/mockups/src/*.html") |
| 182 | var bad []string |
| 183 | for _, f := range srcs { |
| 184 | b, err := os.ReadFile(f) |
| 185 | if err != nil { |
| 186 | return err |
| 187 | } |
| 188 | for _, tag := range tagRe.FindAllString(string(b), -1) { |
| 189 | for _, m := range attrRe.FindAllStringSubmatch(tag, -1) { |
| 190 | if !defined[m[1]] { |
| 191 | bad = append(bad, filepath.Base(f)+": "+m[1]) |
| 192 | } |
| 193 | } |
| 194 | } |
| 195 | } |
| 196 | if len(bad) > 0 { |
| 197 | sort.Strings(bad) |
| 198 | return fmt.Errorf("attributes no stylesheet defines:\n %s", strings.Join(bad, "\n ")) |
| 199 | } |
| 200 | return nil |
| 201 | } |
| 202 | |
| 203 | func fail(err error) { |
| 204 | fmt.Fprintln(os.Stderr, "mockups:", err) |
| 205 | os.Exit(1) |
| 206 | } |
| 207 | |