docs: automated documentation pipeline (per-symbol source → pages)
Some checks failed
docs / build-and-deploy (push) Failing after 38s
Some checks failed
docs / build-and-deploy (push) Failing after 38s
Replace the hardcoded landing page and minimal reference with a generated documentation site driven by a single source of truth. - docs/language/**: one file per symbol (93 keywords/types/builtins/namespace methods/operators/annotations), each with front-matter (id, kind, tokens, sig, tip) + description + a ```ludic example. Seeded by exploding the former inline SECTIONS list; these files are now the source of truth. - docs/site/: site.json (editable hero/features/showcase/messaging, not hardcoded) + snippets/*.ludic (real programs shown on the landing page). - tools/docgen/gen.py: generates index.html, api.html, ludic-highlight.js and symbols.json. The highlighter's symbol tables, hover tips and jump anchors are GENERATED from the per-symbol files — add a symbol and it is recognized, tipped and linked in every snippet automatically. Python stdlib only. - tools/docgen/check.py: verifies the pages contract + that no snippet token links to a missing reference anchor. - .forgejo/workflows/docs.yml: rebuilds and publishes to the pages branch on every push to main touching the docs sources. Consumes the new Screen.*/Color.*/named-arg API and the 221-color palette. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
a3a1e4d160
commit
51ddfa3ce9
121 changed files with 3827 additions and 0 deletions
67
tools/docgen/README.md
Normal file
67
tools/docgen/README.md
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
# Ludic documentation generator
|
||||
|
||||
Generates the public documentation site (the `pages` branch) from a single
|
||||
source of truth, so the site can never drift from the language.
|
||||
|
||||
## Source of truth
|
||||
|
||||
```
|
||||
docs/
|
||||
language/<category>/<id>.md one file per symbol — keyword, type, builtin,
|
||||
namespace method, operator, annotation
|
||||
language/<category>/_section.md section title + blurb + order
|
||||
language/colors/palette.json the 221 named colors (generated by palette.py)
|
||||
site/site.json landing-page messaging (hero, features, …)
|
||||
site/snippets/*.ludic the code shown on the landing page (real programs)
|
||||
```
|
||||
|
||||
### A symbol file
|
||||
|
||||
```markdown
|
||||
---
|
||||
id: kw-handler # anchor in api.html (kw-*, type-*, fn-*, <ns>-*, op-*, annot-*)
|
||||
name: handler # display name / heading
|
||||
category: control # which section (matches the directory)
|
||||
kind: keyword # keyword | type | phase | namespace-method | builtin | annotation | operator
|
||||
tokens: handler # the literal token(s) the highlighter recognizes & links
|
||||
sig: handler Name phase P { … }
|
||||
tip: A block that runs each frame in a given phase. # one-line hover tip
|
||||
order: 3
|
||||
---
|
||||
|
||||
Full description — inline HTML (`<code>`, `<b>`) and `backtick code` both work.
|
||||
|
||||
```ludic
|
||||
handler Move phase Update { … }
|
||||
```
|
||||
```
|
||||
|
||||
Add such a file and it appears in the API Reference, is recognized + tipped +
|
||||
linked in **every** code snippet across the site, and lands in `symbols.json` —
|
||||
with no other file to edit.
|
||||
|
||||
## Build
|
||||
|
||||
```bash
|
||||
python3 tools/docgen/gen.py --out build/pages # generate the whole site
|
||||
python3 tools/docgen/check.py build/pages # sanity-check before publish
|
||||
```
|
||||
|
||||
Outputs into `--out`: `index.html`, `api.html`, `ludic-highlight.js`
|
||||
(its symbol tables generated from the sources above), `symbols.json`, `.nojekyll`.
|
||||
|
||||
No third-party dependencies — Python standard library only.
|
||||
|
||||
## Publish
|
||||
|
||||
`.forgejo/workflows/docs.yml` runs this on every push to `main` that touches
|
||||
`docs/**` or `tools/docgen/**`, and force-publishes the result to the `pages`
|
||||
branch root (which the pages-server serves). It needs a repo secret
|
||||
`PAGES_TOKEN` with write access (or the automatic Actions token enabled for
|
||||
pushes). `index.html` + `.nojekyll` always stay at the branch root.
|
||||
|
||||
## Colors
|
||||
|
||||
`palette.json` is generated by `tools/docgen/palette.py` from a single `PALETTE`
|
||||
table, which also generates `selfhost/emit_color.ludic`. Regenerate colors
|
||||
there; never hand-edit either output.
|
||||
83
tools/docgen/assets/api.css
Normal file
83
tools/docgen/assets/api.css
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
:root{
|
||||
--bg:#0a0d18; --bg2:#0d1122; --panel:#12172b; --panel2:#151b32;
|
||||
--line:#232b47; --line2:#2c3660; --text:#c9d2ea; --head:#f2f5ff; --muted:#8290b4;
|
||||
--mint:#7cf5c4; --coral:#ff5d73; --violet:#c792ea; --blue:#82aaff; --amber:#f6c177;
|
||||
--c-bg:#0b0f20; --c-comment:#5b6788; --c-key:#ff7eb6; --c-type:#7cf5c4;
|
||||
--c-str:#f6c177; --c-num:#a6b8ff; --c-annot:#c792ea; --c-fn:#82aaff; --c-punc:#9aa6cc;
|
||||
--radius:14px; --max:1180px;
|
||||
}
|
||||
*{box-sizing:border-box}
|
||||
html{scroll-behavior:smooth}
|
||||
body{margin:0;background:var(--bg);color:var(--text);
|
||||
font-family:"Space Grotesk",system-ui,-apple-system,Segoe UI,Roboto,sans-serif;line-height:1.6;
|
||||
-webkit-font-smoothing:antialiased}
|
||||
a{color:inherit;text-decoration:none}
|
||||
code,pre,.mono{font-family:"JetBrains Mono",ui-monospace,SFMono-Regular,Menlo,monospace}
|
||||
.wrap{max-width:var(--max);margin:0 auto;padding:0 24px}
|
||||
|
||||
header.nav{position:sticky;top:0;z-index:50;backdrop-filter:blur(10px);
|
||||
background:rgba(10,13,24,.78);border-bottom:1px solid var(--line)}
|
||||
.nav-in{display:flex;align-items:center;gap:22px;height:64px}
|
||||
.brand{display:flex;align-items:center;gap:10px;font-weight:700;color:var(--head);font-size:18px}
|
||||
.logo{width:26px;height:26px;border-radius:7px;display:grid;place-items:center;
|
||||
background:linear-gradient(135deg,var(--mint),#3fd7a6);color:#06231a;font-weight:700;font-size:15px}
|
||||
.nav-links{display:flex;gap:24px;margin-left:auto;align-items:center}
|
||||
.nav-links a{color:var(--muted);font-size:14.5px;font-weight:500;transition:color .15s}
|
||||
.nav-links a:hover{color:var(--head)}
|
||||
.nav-cta{border:1px solid var(--line2);padding:8px 15px;border-radius:9px;color:var(--head)!important;background:var(--panel)}
|
||||
.nav-cta:hover{border-color:var(--mint)}
|
||||
@media(max-width:760px){.nav-links a:not(.nav-cta){display:none}}
|
||||
|
||||
/* two-column reference layout */
|
||||
.ref-layout{display:grid;grid-template-columns:230px 1fr;gap:40px;align-items:start;padding-top:34px;padding-bottom:80px}
|
||||
@media(max-width:900px){.ref-layout{grid-template-columns:1fr}.side{display:none}}
|
||||
.side{position:sticky;top:88px;display:flex;flex-direction:column;gap:2px;max-height:calc(100vh - 110px);overflow:auto}
|
||||
.side a{color:var(--muted);font-size:13.5px;padding:6px 10px;border-radius:8px;border-left:2px solid transparent;transition:all .12s}
|
||||
.side a:hover{color:var(--head);background:var(--panel)}
|
||||
.side a.active{color:var(--mint);border-left-color:var(--mint);background:rgba(124,245,196,.06)}
|
||||
|
||||
.ref-intro{margin-bottom:44px}
|
||||
.ref-intro .kicker{font-size:13px;font-weight:600;letter-spacing:2px;text-transform:uppercase;color:var(--mint);margin-bottom:12px}
|
||||
.ref-intro h1{font-size:clamp(30px,5vw,46px);margin:0 0 12px;color:var(--head);letter-spacing:-1px;font-weight:700}
|
||||
.ref-intro p{font-size:17px;color:var(--muted);max-width:640px;margin:0}
|
||||
|
||||
.ref-sec{padding:26px 0 10px;border-top:1px solid var(--line);margin-top:26px}
|
||||
.ref-sec:first-of-type{border-top:none;margin-top:0}
|
||||
.ref-sec h2{font-size:24px;color:var(--head);margin:0 0 6px;letter-spacing:-.4px}
|
||||
.sec-blurb{color:var(--muted);font-size:15px;margin:0 0 22px;max-width:720px}
|
||||
.sec-blurb code{color:var(--mint);background:rgba(124,245,196,.08);padding:1px 5px;border-radius:5px;font-size:12.5px}
|
||||
|
||||
.entry{padding:16px 0;border-top:1px dashed var(--line)}
|
||||
.entry:first-of-type{border-top:none}
|
||||
.entry-head{display:flex;align-items:center;gap:10px}
|
||||
.entry h3{margin:0;font-size:16.5px;color:var(--head);font-weight:600;font-family:"JetBrains Mono",monospace}
|
||||
.entry .anchor{color:var(--line2);font-size:15px;opacity:0;transition:opacity .12s}
|
||||
.entry:hover .anchor{opacity:1}
|
||||
.entry .anchor:hover{color:var(--mint)}
|
||||
.entry .sig{display:inline-block;margin:8px 0 6px;color:var(--c-fn);background:var(--c-bg);
|
||||
border:1px solid var(--line);border-radius:8px;padding:5px 10px;font-size:13px}
|
||||
.entry p{margin:6px 0 0;color:var(--text);font-size:14.5px;max-width:720px}
|
||||
.entry p code{color:var(--amber);background:var(--panel);padding:1px 5px;border-radius:5px;font-size:12.5px}
|
||||
.entry p b{color:var(--head)}
|
||||
|
||||
pre{margin:10px 0 0;padding:14px 16px;overflow:auto;font-size:13px;line-height:1.7;tab-size:2;
|
||||
background:var(--c-bg);border:1px solid var(--line);border-radius:10px}
|
||||
pre.ex{max-width:720px}
|
||||
pre::-webkit-scrollbar{height:8px}
|
||||
pre::-webkit-scrollbar-thumb{background:var(--line2);border-radius:6px}
|
||||
.t-com{color:var(--c-comment);font-style:italic}
|
||||
.t-key{color:var(--c-key)}.t-type{color:var(--c-type)}.t-str{color:var(--c-str)}
|
||||
.t-num{color:var(--c-num)}.t-annot{color:var(--c-annot)}.t-fn{color:var(--c-fn)}.t-punc{color:var(--c-punc)}
|
||||
/* hover-jump links inside code */
|
||||
a.tok{border-radius:3px;transition:background .12s}
|
||||
a.tok:hover{background:rgba(124,245,196,.14);outline:1px solid rgba(124,245,196,.35)}
|
||||
|
||||
/* color swatches */
|
||||
.swatch-group{margin-bottom:22px}
|
||||
.swatch-group h4{margin:0 0 12px;font-size:13px;letter-spacing:1.5px;text-transform:uppercase;color:var(--muted);font-weight:600}
|
||||
.swatch-row{display:grid;grid-template-columns:repeat(auto-fill,minmax(190px,1fr));gap:10px}
|
||||
.swatch{display:flex;align-items:center;gap:10px;background:var(--panel);border:1px solid var(--line);
|
||||
border-radius:9px;padding:8px 10px}
|
||||
.chip{width:24px;height:24px;border-radius:6px;flex:none;box-shadow:inset 0 0 0 1px rgba(255,255,255,.12)}
|
||||
.cname{font-family:"JetBrains Mono",monospace;font-size:12px;color:var(--head);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
|
||||
.chex{margin-left:auto;font-family:"JetBrains Mono",monospace;font-size:11px;color:var(--muted)}
|
||||
132
tools/docgen/assets/ludic-highlight.tmpl.js
Normal file
132
tools/docgen/assets/ludic-highlight.tmpl.js
Normal file
|
|
@ -0,0 +1,132 @@
|
|||
/* ============================================================================
|
||||
* ludic-highlight.js — the Ludic syntax highlighter for the docs site.
|
||||
*
|
||||
* GENERATED FILE — do not edit by hand. The symbol tables below (keywords,
|
||||
* types, phases, namespace methods, builtins, annotations and their one-line
|
||||
* tips + anchors) are produced by tools/docgen/gen.py from the per-symbol
|
||||
* source files in docs/language/**. Add a symbol there and it is recognized,
|
||||
* colored, tipped and linked here automatically — nothing to maintain twice.
|
||||
*
|
||||
* Beyond coloring, every token the language defines becomes a link into the API
|
||||
* Reference (api.html): hover a keyword, a Screen.* call, a named color, a
|
||||
* builtin or a type and it points at the entry that explains it. Your own
|
||||
* symbols (functions, entities, fields) stay plain.
|
||||
* ========================================================================== */
|
||||
(function (global) {
|
||||
"use strict";
|
||||
|
||||
const SYMBOLS = /*__SYMBOLS__*/{};
|
||||
const KEYWORDS = SYMBOLS.keywords || {};
|
||||
const TYPES = SYMBOLS.types || {};
|
||||
const PHASES = SYMBOLS.phases || {};
|
||||
const BUILTINS = SYMBOLS.builtins || {};
|
||||
const NSMETHODS = SYMBOLS.nsmethods || {};
|
||||
const ANNOTS = SYMBOLS.annotations || {};
|
||||
const TIPS = SYMBOLS.tips || {};
|
||||
const NAMESPACES = new Set(SYMBOLS.namespaces || []);
|
||||
const COLORS_ANCHOR = SYMBOLS.colors_anchor || "colors";
|
||||
const ANNOT_ANCHOR = SYMBOLS.annotations_anchor || "annotations";
|
||||
|
||||
function esc(s) {
|
||||
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
||||
}
|
||||
const isIdStart = c => /[A-Za-z_]/.test(c);
|
||||
const isId = c => /[A-Za-z0-9_]/.test(c);
|
||||
|
||||
function link(href, tip, inner) {
|
||||
const t = tip ? ' title="' + esc(tip) + '"' : "";
|
||||
return '<a class="tok" href="' + href + '"' + t + ">" + inner + "</a>";
|
||||
}
|
||||
|
||||
function highlight(src) {
|
||||
let out = "", i = 0;
|
||||
const n = src.length;
|
||||
while (i < n) {
|
||||
const c = src[i];
|
||||
// comment
|
||||
if (c === "#") {
|
||||
let j = i; while (j < n && src[j] !== "\n") j++;
|
||||
out += '<span class="t-com">' + esc(src.slice(i, j)) + "</span>";
|
||||
i = j; continue;
|
||||
}
|
||||
// string / char / interpolation (backtick)
|
||||
if (c === '"' || c === "'" || c === "`") {
|
||||
const q = c; let j = i + 1;
|
||||
while (j < n && src[j] !== q) { if (src[j] === "\\") j++; j++; }
|
||||
j = Math.min(j + 1, n);
|
||||
out += '<span class="t-str">' + esc(src.slice(i, j)) + "</span>";
|
||||
i = j; continue;
|
||||
}
|
||||
// annotation @Name
|
||||
if (c === "@") {
|
||||
let j = i + 1; while (j < n && isId(src[j])) j++;
|
||||
const at = src.slice(i, j);
|
||||
const anchor = ANNOTS[at] || ANNOT_ANCHOR;
|
||||
const tip = TIPS[at] || "A compile-time annotation.";
|
||||
out += link("api.html#" + anchor, tip,
|
||||
'<span class="t-annot">' + esc(at) + "</span>");
|
||||
i = j; continue;
|
||||
}
|
||||
// number (incl 0x hex)
|
||||
if (/[0-9]/.test(c)) {
|
||||
let j = i; while (j < n && /[0-9a-fA-FxX._]/.test(src[j])) j++;
|
||||
out += '<span class="t-num">' + esc(src.slice(i, j)) + "</span>";
|
||||
i = j; continue;
|
||||
}
|
||||
// identifier / keyword / type / namespace.member / builtin
|
||||
if (isIdStart(c)) {
|
||||
let j = i; while (j < n && isId(src[j])) j++;
|
||||
const word = src.slice(i, j);
|
||||
|
||||
// Namespace.member (Screen.fill_rectangle, Color.Crimson, …)
|
||||
if (NAMESPACES.has(word) && src[j] === "." && j + 1 < n && isIdStart(src[j + 1])) {
|
||||
let k = j + 1; while (k < n && isId(src[k])) k++;
|
||||
const member = src.slice(j + 1, k);
|
||||
const key = word + "." + member;
|
||||
let href, tip;
|
||||
if (word === "Color") {
|
||||
href = "api.html#" + COLORS_ANCHOR; tip = "Named color " + key + ".";
|
||||
} else {
|
||||
href = "api.html#" + (NSMETHODS[key] || (word.toLowerCase() + "-" + member));
|
||||
tip = TIPS[key] || key;
|
||||
}
|
||||
const inner = '<span class="t-type">' + word + '</span><span class="t-punc">.</span><span class="t-fn">' + esc(member) + "</span>";
|
||||
out += link(href, tip, inner);
|
||||
i = k; continue;
|
||||
}
|
||||
|
||||
let k2 = j; while (k2 < n && src[k2] === " ") k2++;
|
||||
const callish = src[k2] === "(";
|
||||
if (KEYWORDS[word]) {
|
||||
out += link("api.html#" + KEYWORDS[word], TIPS[word], '<span class="t-key">' + word + "</span>");
|
||||
} else if (BUILTINS[word] && callish) {
|
||||
out += link("api.html#" + BUILTINS[word], TIPS[word], '<span class="t-fn">' + word + "</span>");
|
||||
} else if (TYPES[word]) {
|
||||
out += link("api.html#" + TYPES[word], TIPS[word] || ("The " + word + " type."), '<span class="t-type">' + word + "</span>");
|
||||
} else if (PHASES[word]) {
|
||||
out += link("api.html#" + PHASES[word], "The " + word + " phase.", '<span class="t-type">' + word + "</span>");
|
||||
} else if (callish) {
|
||||
out += '<span class="t-fn">' + esc(word) + "</span>";
|
||||
} else {
|
||||
out += esc(word);
|
||||
}
|
||||
i = j; continue;
|
||||
}
|
||||
// punctuation
|
||||
if (/[{}\[\]()=<>+\-*\/%,.:;!&|~]/.test(c)) {
|
||||
out += '<span class="t-punc">' + esc(c) + "</span>";
|
||||
i++; continue;
|
||||
}
|
||||
out += esc(c); i++;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
function highlightAll() {
|
||||
document.querySelectorAll('pre[data-lang="ludic"]').forEach(pre => {
|
||||
pre.innerHTML = highlight(pre.textContent);
|
||||
});
|
||||
}
|
||||
|
||||
global.Ludic = { highlight, highlightAll, SYMBOLS };
|
||||
})(window);
|
||||
194
tools/docgen/assets/site.css
Normal file
194
tools/docgen/assets/site.css
Normal file
|
|
@ -0,0 +1,194 @@
|
|||
:root{
|
||||
--bg:#0a0d18;
|
||||
--bg2:#0d1122;
|
||||
--panel:#12172b;
|
||||
--panel2:#151b32;
|
||||
--line:#232b47;
|
||||
--line2:#2c3660;
|
||||
--text:#c9d2ea;
|
||||
--head:#f2f5ff;
|
||||
--muted:#8290b4;
|
||||
--mint:#7cf5c4;
|
||||
--coral:#ff5d73;
|
||||
--violet:#c792ea;
|
||||
--blue:#82aaff;
|
||||
--amber:#f6c177;
|
||||
--peri:#a6b8ff;
|
||||
/* code theme */
|
||||
--c-bg:#0b0f20;
|
||||
--c-comment:#5b6788;
|
||||
--c-key:#ff7eb6;
|
||||
--c-type:#7cf5c4;
|
||||
--c-str:#f6c177;
|
||||
--c-num:#a6b8ff;
|
||||
--c-annot:#c792ea;
|
||||
--c-fn:#82aaff;
|
||||
--c-punc:#9aa6cc;
|
||||
--radius:14px;
|
||||
--max:1120px;
|
||||
}
|
||||
*{box-sizing:border-box}
|
||||
html{scroll-behavior:smooth}
|
||||
body{
|
||||
margin:0;
|
||||
background:
|
||||
radial-gradient(1100px 600px at 82% -8%, rgba(124,245,196,.10), transparent 60%),
|
||||
radial-gradient(900px 620px at 6% 4%, rgba(255,93,115,.09), transparent 55%),
|
||||
var(--bg);
|
||||
color:var(--text);
|
||||
font-family:"Space Grotesk", system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
|
||||
line-height:1.6;
|
||||
-webkit-font-smoothing:antialiased;
|
||||
text-rendering:optimizeLegibility;
|
||||
}
|
||||
a{color:inherit;text-decoration:none}
|
||||
code,pre,.mono{font-family:"JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace}
|
||||
.wrap{max-width:var(--max);margin:0 auto;padding:0 24px}
|
||||
|
||||
/* ---------- nav ---------- */
|
||||
header.nav{position:sticky;top:0;z-index:50;backdrop-filter:blur(10px);
|
||||
background:rgba(10,13,24,.72);border-bottom:1px solid var(--line)}
|
||||
.nav-in{display:flex;align-items:center;gap:22px;height:64px}
|
||||
.brand{display:flex;align-items:center;gap:10px;font-weight:700;color:var(--head);font-size:18px;letter-spacing:.2px}
|
||||
.logo{width:26px;height:26px;border-radius:7px;display:grid;place-items:center;
|
||||
background:linear-gradient(135deg,var(--mint),#3fd7a6);color:#06231a;font-weight:700;font-size:15px;
|
||||
box-shadow:0 0 0 1px rgba(124,245,196,.3), 0 6px 20px -6px rgba(124,245,196,.5)}
|
||||
.nav-links{display:flex;gap:24px;margin-left:auto;align-items:center}
|
||||
.nav-links a{color:var(--muted);font-size:14.5px;font-weight:500;transition:color .15s}
|
||||
.nav-links a:hover{color:var(--head)}
|
||||
.nav-cta{border:1px solid var(--line2);padding:8px 15px;border-radius:9px;color:var(--head)!important;
|
||||
background:var(--panel);transition:border-color .15s, background .15s}
|
||||
.nav-cta:hover{border-color:var(--mint);background:var(--panel2)}
|
||||
@media(max-width:760px){.nav-links a:not(.nav-cta){display:none}}
|
||||
|
||||
/* ---------- hero ---------- */
|
||||
.hero{padding:84px 0 56px;position:relative;overflow:hidden}
|
||||
.pill{display:inline-flex;align-items:center;gap:9px;font-size:13px;color:var(--mint);
|
||||
border:1px solid rgba(124,245,196,.28);background:rgba(124,245,196,.06);
|
||||
padding:6px 13px;border-radius:999px;font-weight:500;margin-bottom:26px}
|
||||
.pill .dot{width:7px;height:7px;border-radius:50%;background:var(--mint);box-shadow:0 0 8px var(--mint)}
|
||||
h1{font-size:clamp(38px,6vw,68px);line-height:1.04;margin:0 0 20px;color:var(--head);
|
||||
font-weight:700;letter-spacing:-1.5px}
|
||||
h1 .accent{background:linear-gradient(120deg,var(--mint),var(--blue));-webkit-background-clip:text;
|
||||
background-clip:text;-webkit-text-fill-color:transparent}
|
||||
.lead{font-size:clamp(17px,2.3vw,21px);color:var(--muted);max-width:640px;margin:0 0 34px}
|
||||
.lead b{color:var(--text);font-weight:600}
|
||||
.cta-row{display:flex;gap:14px;flex-wrap:wrap;align-items:center}
|
||||
.btn{display:inline-flex;align-items:center;gap:9px;font-weight:600;font-size:15.5px;
|
||||
padding:13px 22px;border-radius:11px;transition:transform .12s, box-shadow .15s, border-color .15s;font-family:inherit;cursor:pointer;border:1px solid transparent}
|
||||
.btn:active{transform:translateY(1px)}
|
||||
.btn-primary{background:linear-gradient(135deg,var(--mint),#43dcae);color:#06231a;
|
||||
box-shadow:0 10px 30px -10px rgba(124,245,196,.6)}
|
||||
.btn-primary:hover{box-shadow:0 14px 38px -10px rgba(124,245,196,.75)}
|
||||
.btn-ghost{border:1px solid var(--line2);color:var(--head);background:var(--panel)}
|
||||
.btn-ghost:hover{border-color:var(--mint)}
|
||||
.hero-grid{display:grid;grid-template-columns:1.02fr .98fr;gap:48px;align-items:center}
|
||||
@media(max-width:900px){.hero-grid{grid-template-columns:1fr;gap:36px}}
|
||||
|
||||
/* window chrome for code */
|
||||
.code-card{background:var(--c-bg);border:1px solid var(--line);border-radius:var(--radius);
|
||||
overflow:hidden;box-shadow:0 30px 60px -30px rgba(0,0,0,.7)}
|
||||
.code-top{display:flex;align-items:center;gap:8px;padding:12px 15px;border-bottom:1px solid var(--line);
|
||||
background:linear-gradient(180deg,var(--panel),rgba(18,23,43,.4))}
|
||||
.tl{width:11px;height:11px;border-radius:50%}
|
||||
.tl.r{background:#ff5f57}.tl.y{background:#febc2e}.tl.g{background:#28c840}
|
||||
.code-name{margin-left:8px;font-size:12.5px;color:var(--muted)}
|
||||
pre{margin:0;padding:20px 22px;overflow:auto;font-size:13.5px;line-height:1.72;tab-size:2}
|
||||
pre::-webkit-scrollbar{height:9px;width:9px}
|
||||
pre::-webkit-scrollbar-thumb{background:var(--line2);border-radius:6px}
|
||||
/* token colors */
|
||||
.t-com{color:var(--c-comment);font-style:italic}
|
||||
.t-key{color:var(--c-key)}
|
||||
.t-type{color:var(--c-type)}
|
||||
.t-str{color:var(--c-str)}
|
||||
.t-num{color:var(--c-num)}
|
||||
.t-annot{color:var(--c-annot)}
|
||||
.t-fn{color:var(--c-fn)}
|
||||
.t-punc{color:var(--c-punc)}
|
||||
/* hover-to-jump links inside code snippets */
|
||||
pre a.tok{border-radius:3px;transition:background .12s, outline-color .12s}
|
||||
pre a.tok:hover{background:rgba(124,245,196,.14);outline:1px solid rgba(124,245,196,.35)}
|
||||
|
||||
/* ---------- pipeline ---------- */
|
||||
.pipeline{display:flex;align-items:center;justify-content:center;gap:0;flex-wrap:wrap;
|
||||
margin:8px 0 0;padding:20px;border:1px dashed var(--line2);border-radius:var(--radius);
|
||||
background:rgba(18,23,43,.4)}
|
||||
.stage{font-family:"JetBrains Mono",monospace;font-size:13px;font-weight:500;color:var(--head);
|
||||
background:var(--panel);border:1px solid var(--line2);padding:8px 13px;border-radius:9px;white-space:nowrap}
|
||||
.stage.hl{color:var(--mint);border-color:rgba(124,245,196,.35)}
|
||||
.arrow{color:var(--muted);padding:0 12px;font-size:15px}
|
||||
|
||||
/* ---------- sections ---------- */
|
||||
section{padding:72px 0}
|
||||
.sec-head{max-width:680px;margin-bottom:44px}
|
||||
.kicker{font-size:13px;font-weight:600;letter-spacing:2px;text-transform:uppercase;color:var(--mint);margin-bottom:14px}
|
||||
h2{font-size:clamp(28px,4vw,40px);margin:0 0 14px;color:var(--head);letter-spacing:-.8px;font-weight:700;line-height:1.1}
|
||||
.sec-head p{font-size:17.5px;color:var(--muted);margin:0}
|
||||
|
||||
/* feature grid */
|
||||
.feat-grid{display:grid;grid-template-columns:repeat(3,1fr);gap:18px}
|
||||
@media(max-width:900px){.feat-grid{grid-template-columns:repeat(2,1fr)}}
|
||||
@media(max-width:600px){.feat-grid{grid-template-columns:1fr}}
|
||||
.feat{background:linear-gradient(180deg,var(--panel),var(--bg2));border:1px solid var(--line);
|
||||
border-radius:var(--radius);padding:24px 22px;transition:transform .16s, border-color .16s}
|
||||
.feat:hover{transform:translateY(-3px);border-color:var(--line2)}
|
||||
.feat .ico{width:40px;height:40px;border-radius:10px;display:grid;place-items:center;margin-bottom:16px;
|
||||
background:rgba(124,245,196,.09);border:1px solid rgba(124,245,196,.2);font-size:20px}
|
||||
.feat h3{margin:0 0 8px;font-size:17.5px;color:var(--head);font-weight:600}
|
||||
.feat p{margin:0;font-size:14.5px;color:var(--muted);line-height:1.6}
|
||||
.feat p code{color:var(--mint);font-size:12.5px;background:rgba(124,245,196,.08);padding:1px 5px;border-radius:5px}
|
||||
|
||||
/* showcase tabs */
|
||||
.tabs{display:flex;gap:8px;flex-wrap:wrap;margin-bottom:18px}
|
||||
.tab{font-family:"JetBrains Mono",monospace;font-size:13px;color:var(--muted);background:var(--panel);
|
||||
border:1px solid var(--line);padding:8px 15px;border-radius:9px;cursor:pointer;transition:all .14s;font-weight:500}
|
||||
.tab:hover{color:var(--text);border-color:var(--line2)}
|
||||
.tab.active{color:#06231a;background:var(--mint);border-color:var(--mint);font-weight:600}
|
||||
.panel-code{display:none}
|
||||
.panel-code.active{display:block}
|
||||
.showcase-note{margin-top:16px;font-size:14px;color:var(--muted);display:flex;gap:10px;align-items:flex-start}
|
||||
.showcase-note .b{color:var(--mint);font-weight:700}
|
||||
|
||||
/* steps */
|
||||
.steps{display:grid;grid-template-columns:1.1fr 1fr;gap:40px;align-items:start}
|
||||
@media(max-width:900px){.steps{grid-template-columns:1fr}}
|
||||
.step{display:flex;gap:16px;margin-bottom:26px}
|
||||
.step .n{flex:none;width:32px;height:32px;border-radius:9px;display:grid;place-items:center;font-weight:700;
|
||||
font-family:"JetBrains Mono",monospace;font-size:14px;color:var(--mint);
|
||||
background:rgba(124,245,196,.08);border:1px solid rgba(124,245,196,.25)}
|
||||
.step h4{margin:2px 0 6px;color:var(--head);font-size:16.5px;font-weight:600}
|
||||
.step p{margin:0;color:var(--muted);font-size:14.5px}
|
||||
.step p code{color:var(--text);background:var(--panel);padding:1px 6px;border-radius:5px;font-size:12.5px;border:1px solid var(--line)}
|
||||
|
||||
.term{background:var(--c-bg);border:1px solid var(--line);border-radius:var(--radius);overflow:hidden;position:sticky;top:88px}
|
||||
.term pre{font-size:13px}
|
||||
.term .prompt{color:var(--mint)}
|
||||
.term .out{color:var(--muted)}
|
||||
|
||||
/* editors strip */
|
||||
.editors{display:flex;flex-wrap:wrap;gap:12px}
|
||||
.ed{font-family:"JetBrains Mono",monospace;font-size:13.5px;color:var(--text);background:var(--panel);
|
||||
border:1px solid var(--line);border-radius:10px;padding:11px 16px;display:flex;align-items:center;gap:9px}
|
||||
.ed .k{color:var(--mint)}
|
||||
|
||||
/* callout / philosophy banner */
|
||||
.banner{background:linear-gradient(120deg,rgba(124,245,196,.08),rgba(130,170,255,.06));
|
||||
border:1px solid var(--line2);border-radius:18px;padding:38px 34px;display:grid;grid-template-columns:1.2fr 1fr;gap:34px;align-items:center}
|
||||
@media(max-width:860px){.banner{grid-template-columns:1fr}}
|
||||
.banner h2{font-size:clamp(24px,3.4vw,32px)}
|
||||
.banner p{color:var(--muted);margin:0 0 6px;font-size:15.5px}
|
||||
.stat-row{display:flex;gap:14px;flex-wrap:wrap}
|
||||
.stat{background:var(--c-bg);border:1px solid var(--line);border-radius:12px;padding:16px 18px;flex:1;min-width:130px}
|
||||
.stat .big{font-family:"JetBrains Mono",monospace;font-size:26px;color:var(--mint);font-weight:700;line-height:1}
|
||||
.stat .lbl{font-size:12.5px;color:var(--muted);margin-top:8px}
|
||||
|
||||
/* footer */
|
||||
footer{border-top:1px solid var(--line);padding:44px 0 60px;margin-top:20px}
|
||||
.foot-in{display:flex;justify-content:space-between;gap:24px;flex-wrap:wrap;align-items:center}
|
||||
.foot-in .muted{color:var(--muted);font-size:14px}
|
||||
.foot-links{display:flex;gap:22px;flex-wrap:wrap}
|
||||
.foot-links a{color:var(--muted);font-size:14px;transition:color .15s}
|
||||
.foot-links a:hover{color:var(--mint)}
|
||||
|
||||
.reveal{opacity:0;transform:translateY(16px);transition:opacity .6s ease, transform .6s ease}
|
||||
.reveal.in{opacity:1;transform:none}
|
||||
41
tools/docgen/check.py
Normal file
41
tools/docgen/check.py
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
#!/usr/bin/env python3
|
||||
"""check.py — sanity-check a generated docs site before it is published.
|
||||
|
||||
Verifies:
|
||||
* the pages-server contract: index.html + .nojekyll exist at the root;
|
||||
* api.html and ludic-highlight.js are present;
|
||||
* every anchor the highlighter links to actually exists in api.html
|
||||
(so no code-snippet token points at a missing entry).
|
||||
|
||||
Usage: python3 tools/docgen/check.py <site-dir>
|
||||
Exit code 1 on any failure.
|
||||
"""
|
||||
import json, os, re, sys
|
||||
|
||||
def main(site):
|
||||
problems = []
|
||||
need = ["index.html", "api.html", "ludic-highlight.js", ".nojekyll", "symbols.json"]
|
||||
for f in need:
|
||||
if not os.path.exists(os.path.join(site, f)):
|
||||
problems.append(f"missing required file: {f}")
|
||||
if os.path.exists(os.path.join(site, "symbols.json")) and os.path.exists(os.path.join(site, "api.html")):
|
||||
sym = json.load(open(os.path.join(site, "symbols.json")))
|
||||
ids = set(re.findall(r'id="([^"]+)"', open(os.path.join(site, "api.html")).read()))
|
||||
anchors = set()
|
||||
for grp in ("keywords", "types", "phases", "builtins", "nsmethods", "annotations"):
|
||||
anchors |= set(sym.get(grp, {}).values())
|
||||
anchors.add(sym.get("colors_anchor", "colors"))
|
||||
anchors.add(sym.get("annotations_anchor", "annotations"))
|
||||
for a in sorted(anchors):
|
||||
if a not in ids:
|
||||
problems.append(f"highlighter links to #{a} but api.html has no such anchor")
|
||||
if problems:
|
||||
print("docs check FAILED:")
|
||||
for p in problems:
|
||||
print(" -", p)
|
||||
return 1
|
||||
print("docs check OK:", site)
|
||||
return 0
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main(sys.argv[1] if len(sys.argv) > 1 else "build/pages"))
|
||||
525
tools/docgen/gen.py
Normal file
525
tools/docgen/gen.py
Normal file
|
|
@ -0,0 +1,525 @@
|
|||
#!/usr/bin/env python3
|
||||
"""gen.py — the Ludic documentation generator.
|
||||
|
||||
Single source of truth:
|
||||
docs/language/<category>/<id>.md one file per keyword / type / builtin /
|
||||
namespace method / operator / annotation
|
||||
docs/language/<category>/_section.md section title + blurb + order
|
||||
docs/language/colors/palette.json the named-color palette (from palette.py)
|
||||
docs/site/site.json landing-page messaging (hero, features, …)
|
||||
docs/site/snippets/*.ludic the code snippets shown on the landing page
|
||||
|
||||
Outputs (into --out, default build/pages) — the whole pages-branch payload:
|
||||
api.html the full API Reference, one entry per symbol
|
||||
index.html the landing page (hero + showcase from real .ludic files)
|
||||
ludic-highlight.js the highlighter, its symbol tables generated from the above
|
||||
symbols.json the machine-readable symbol index (also useful to editors)
|
||||
.nojekyll
|
||||
|
||||
Nothing here is hand-maintained twice: add a symbol file and it appears in the
|
||||
reference, is recognized + tipped + linked in every snippet, and lands in
|
||||
symbols.json — automatically. Zero third-party dependencies (stdlib only).
|
||||
"""
|
||||
import json, os, html, re, sys, argparse
|
||||
|
||||
ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
ASSETS = os.path.join(os.path.dirname(os.path.abspath(__file__)), "assets")
|
||||
LANG = os.path.join(ROOT, "docs", "language")
|
||||
SITE = os.path.join(ROOT, "docs", "site")
|
||||
|
||||
def esc(s): return html.escape(s, quote=False)
|
||||
|
||||
def fill(tmpl, mapping):
|
||||
"""Placeholder substitution that never collides with % or { } in CSS/JS."""
|
||||
for k, v in mapping.items():
|
||||
tmpl = tmpl.replace("@@" + k + "@@", str(v))
|
||||
return tmpl
|
||||
|
||||
def pct(tmpl, mapping):
|
||||
"""Substitute only %(name)s markers; leave bare % (CSS 100%, code % 2) alone.
|
||||
Replacement values are inserted literally and never re-scanned."""
|
||||
return re.sub(r"%\((\w+)\)s", lambda m: mapping[m.group(1)], tmpl)
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# front-matter + body parsing (no yaml dependency)
|
||||
# ---------------------------------------------------------------------------
|
||||
def parse_doc(path):
|
||||
text = open(path, encoding="utf-8").read()
|
||||
meta, body = {}, text
|
||||
if text.startswith("---"):
|
||||
end = text.find("\n---", 3)
|
||||
if end != -1:
|
||||
fm = text[3:end].strip("\n")
|
||||
body = text[end + 4:].lstrip("\n")
|
||||
for line in fm.split("\n"):
|
||||
if not line.strip() or ":" not in line:
|
||||
continue
|
||||
k, v = line.split(":", 1)
|
||||
meta[k.strip()] = v.strip()
|
||||
return meta, body
|
||||
|
||||
FENCE = re.compile(r"```ludic\n(.*?)\n```", re.S)
|
||||
|
||||
def split_body(body):
|
||||
"""Return (description_html, [examples]) — fences pulled out as examples."""
|
||||
examples = FENCE.findall(body)
|
||||
desc = FENCE.sub("", body).strip()
|
||||
# author convenience: `code` -> <code>code</code> (leaves existing tags alone)
|
||||
desc = re.sub(r"`([^`]+)`", r"<code>\1</code>", desc)
|
||||
paras = [p.strip() for p in re.split(r"\n\s*\n", desc) if p.strip()]
|
||||
desc_html = "</p><p>".join(paras)
|
||||
return desc_html, examples
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# load the symbol model
|
||||
# ---------------------------------------------------------------------------
|
||||
def load_sections():
|
||||
sections = []
|
||||
for cat in sorted(os.listdir(LANG)):
|
||||
cdir = os.path.join(LANG, cat)
|
||||
if not os.path.isdir(cdir):
|
||||
continue
|
||||
smeta, sblurb = {}, ""
|
||||
secpath = os.path.join(cdir, "_section.md")
|
||||
if os.path.exists(secpath):
|
||||
smeta, sbody = parse_doc(secpath)
|
||||
sblurb = re.sub(r"`([^`]+)`", r"<code>\1</code>", sbody.strip())
|
||||
entries = []
|
||||
for fn in os.listdir(cdir):
|
||||
if not fn.endswith(".md") or fn == "_section.md":
|
||||
continue
|
||||
meta, body = parse_doc(os.path.join(cdir, fn))
|
||||
desc, examples = split_body(body)
|
||||
meta["desc_html"] = desc
|
||||
meta["examples"] = examples
|
||||
meta["tokens_list"] = meta.get("tokens", "").split() if meta.get("tokens") else []
|
||||
entries.append(meta)
|
||||
entries.sort(key=lambda e: (int(e.get("order", 999)), e.get("name", "")))
|
||||
sections.append({
|
||||
"id": smeta.get("id", cat),
|
||||
"title": smeta.get("title", cat.title()),
|
||||
"order": int(smeta.get("order", 999)),
|
||||
"blurb": sblurb,
|
||||
"entries": entries,
|
||||
})
|
||||
sections.sort(key=lambda s: (s["order"], s["title"]))
|
||||
return sections
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# build the highlighter symbol tables from the model
|
||||
# ---------------------------------------------------------------------------
|
||||
def build_symbols(sections):
|
||||
sym = {"keywords": {}, "types": {}, "phases": {}, "builtins": {},
|
||||
"nsmethods": {}, "annotations": {}, "tips": {},
|
||||
"namespaces": [], "colors_anchor": "colors", "annotations_anchor": "annotations"}
|
||||
namespaces = set()
|
||||
for s in sections:
|
||||
for e in s["entries"]:
|
||||
kind = e.get("kind", "")
|
||||
anchor = e["id"]
|
||||
tip = e.get("tip", "")
|
||||
for tok in e["tokens_list"]:
|
||||
if kind == "keyword":
|
||||
sym["keywords"][tok] = anchor
|
||||
elif kind == "type":
|
||||
sym["types"][tok] = anchor
|
||||
elif kind == "phase":
|
||||
sym["phases"][tok] = anchor
|
||||
elif kind == "builtin":
|
||||
sym["builtins"][tok] = anchor
|
||||
elif kind == "namespace-method":
|
||||
sym["nsmethods"][tok] = anchor
|
||||
if "." in tok:
|
||||
namespaces.add(tok.split(".", 1)[0])
|
||||
elif kind == "annotation":
|
||||
sym["annotations"][tok] = anchor
|
||||
if tip:
|
||||
sym["tips"][tok] = tip
|
||||
if s["id"] == "colors":
|
||||
sym["colors_anchor"] = "colors"
|
||||
if s["id"] == "annotations":
|
||||
sym["annotations_anchor"] = "annotations"
|
||||
namespaces.add("Color") # Color.* is recognized and linked to the palette
|
||||
sym["namespaces"] = sorted(namespaces)
|
||||
return sym
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# render the API Reference
|
||||
# ---------------------------------------------------------------------------
|
||||
def render_entry(e):
|
||||
ex = ""
|
||||
for code in e.get("examples", []):
|
||||
ex += '<pre data-lang="ludic" class="ex">' + esc(code) + "</pre>"
|
||||
desc = e.get("desc_html", "")
|
||||
return (
|
||||
'<div class="entry" id="{id}">'
|
||||
'<div class="entry-head"><h3>{name}</h3><a class="anchor" href="#{id}">#</a></div>'
|
||||
'<code class="sig">{sig}</code>'
|
||||
'<p>{desc}</p>{ex}</div>'
|
||||
).format(id=e["id"], name=esc(e.get("name", "")), sig=esc(e.get("sig", "")),
|
||||
desc=desc, ex=ex)
|
||||
|
||||
def render_palette(palette):
|
||||
out = ['<div class="swatches">']
|
||||
for grp in palette["groups"]:
|
||||
out.append('<div class="swatch-group"><h4>' + esc(grp["name"]) + '</h4><div class="swatch-row">')
|
||||
for col in grp["colors"]:
|
||||
h = col["hex"]
|
||||
out.append(
|
||||
'<div class="swatch"><span class="chip" style="background:#{h}"></span>'
|
||||
'<span class="cname">Color.{n}</span><span class="chex">#{h}</span></div>'
|
||||
.format(h=h, n=esc(col["name"])))
|
||||
out.append("</div></div>")
|
||||
out.append("</div>")
|
||||
return "\n".join(out)
|
||||
|
||||
def render_section(s, palette):
|
||||
if s["id"] == "colors":
|
||||
body = render_palette(palette)
|
||||
else:
|
||||
body = "\n".join(render_entry(e) for e in s["entries"])
|
||||
return ('<section class="ref-sec" id="{id}"><h2>{title}</h2>'
|
||||
'<p class="sec-blurb">{blurb}</p>{body}</section>').format(
|
||||
id=s["id"], title=esc(s["title"]), blurb=s["blurb"], body=body)
|
||||
|
||||
def render_api(sections, palette, cfg):
|
||||
css = open(os.path.join(ASSETS, "api.css")).read()
|
||||
nav = '<nav class="side">' + "".join(
|
||||
'<a href="#{i}">{t}</a>'.format(i=s["id"], t=esc(s["title"])) for s in sections) + "</nav>"
|
||||
content = "\n".join(render_section(s, palette) for s in sections)
|
||||
navlinks = "".join(
|
||||
'<a {cls}href="{h}">{l}</a>'.format(
|
||||
h=n["href"], l=esc(n["label"]),
|
||||
cls='class="nav-cta" ' if n.get("href") == "api.html" else "")
|
||||
for n in cfg["nav_links"])
|
||||
tmpl = """<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Ludic — API Reference</title>
|
||||
<meta name="description" content="The complete Ludic API Reference: every keyword, type, builtin, the Screen/Color/Input/Random/Map namespaces, and the full named-color palette.">
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;700&display=swap" rel="stylesheet">
|
||||
<style>
|
||||
@@CSS@@
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<header class="nav">
|
||||
<div class="wrap nav-in">
|
||||
<a class="brand" href="index.html"><span class="logo">L</span> @@BRAND@@</a>
|
||||
<nav class="nav-links">@@NAVLINKS@@</nav>
|
||||
</div>
|
||||
</header>
|
||||
<div class="wrap ref-layout">
|
||||
@@NAV@@
|
||||
<main class="ref-main">
|
||||
<div class="ref-intro">
|
||||
<div class="kicker">Reference</div>
|
||||
<h1>API Reference</h1>
|
||||
<p>Every keyword, type, builtin, namespace and color in Ludic. In any code sample across this site, hover a token and click to jump straight to its entry here.</p>
|
||||
</div>
|
||||
@@CONTENT@@
|
||||
</main>
|
||||
</div>
|
||||
<script src="ludic-highlight.js"></script>
|
||||
<script>
|
||||
Ludic.highlightAll();
|
||||
const secs = [...document.querySelectorAll('.ref-sec')];
|
||||
const navlinks = [...document.querySelectorAll('.side a')];
|
||||
const spy = new IntersectionObserver((entries)=>{
|
||||
entries.forEach(e=>{ if(e.isIntersecting){
|
||||
navlinks.forEach(a=>a.classList.toggle('active', a.getAttribute('href')==='#'+e.target.id));
|
||||
}});
|
||||
},{rootMargin:'-10% 0px -80% 0px'});
|
||||
secs.forEach(s=>spy.observe(s));
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
return fill(tmpl, dict(CSS=css, BRAND=esc(cfg["brand"]), NAVLINKS=navlinks, NAV=nav, CONTENT=content))
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# render the landing page
|
||||
# ---------------------------------------------------------------------------
|
||||
def read_snippet(rel):
|
||||
return open(os.path.join(ROOT, rel), encoding="utf-8").read().rstrip("\n")
|
||||
|
||||
def render_index(cfg):
|
||||
css = open(os.path.join(ASSETS, "site.css")).read()
|
||||
hero = cfg["hero"]
|
||||
navlinks = "".join(
|
||||
'<a {cls}href="{h}">{l}</a>'.format(
|
||||
h=n["href"], l=esc(n["label"]),
|
||||
cls='class="nav-cta" ' if n.get("href") == "api.html" else "")
|
||||
for n in cfg["nav_links"])
|
||||
# hero snippet
|
||||
hero_code = esc(read_snippet(hero["snippet"]))
|
||||
# pipeline
|
||||
stages = ""
|
||||
for st in hero["pipeline"]:
|
||||
hl = " hl" if st == "ludicc" else ""
|
||||
stages += '<span class="stage%s">%s</span>' % (hl, esc(st))
|
||||
if st != hero["pipeline"][-1]:
|
||||
stages += '<span class="arrow">→</span>'
|
||||
# features
|
||||
feats = ""
|
||||
for c in cfg["features"]["cards"]:
|
||||
feats += ('<div class="feat reveal"><div class="ico">%s</div>'
|
||||
'<h3>%s</h3><p>%s</p></div>') % (c["icon"], c["title"], c["html"])
|
||||
# philosophy
|
||||
phil = cfg["philosophy"]
|
||||
phil_paras = "".join("<p>%s</p>" % p for p in phil["paras"])
|
||||
phil_stats = "".join('<div class="stat"><div class="big">%s</div><div class="lbl">%s</div></div>'
|
||||
% (s["big"], esc(s["lbl"])) for s in phil["stats"])
|
||||
# get-started steps + terminal
|
||||
start = cfg["start"]
|
||||
steps = ""
|
||||
for i, s in enumerate(start["steps"], 1):
|
||||
steps += ('<div class="step reveal"><div class="n">%d</div>'
|
||||
'<div><h4>%s</h4><p>%s</p></div></div>') % (i, s["title"], s["html"])
|
||||
term = ""
|
||||
for t in start["terminal"]:
|
||||
if t.get("blank"):
|
||||
term += "\n"
|
||||
elif "comment" in t:
|
||||
term += '<span class="t-com"># %s</span>\n' % esc(t["comment"])
|
||||
elif "cmd" in t:
|
||||
term += '<span class="prompt">$</span> %s\n' % esc(t["cmd"])
|
||||
elif "out" in t:
|
||||
term += '<span class="out">%s</span>\n' % esc(t["out"])
|
||||
# editors
|
||||
ed = cfg["editors"]
|
||||
eds = "".join('<div class="ed"><span class="k">◆</span> %s</div>' % esc(x) for x in ed["list"])
|
||||
# showcase samples -> JS array, code read from real files
|
||||
samples = []
|
||||
for s in cfg["showcase"]["samples"]:
|
||||
samples.append({"name": s["name"], "label": s["label"],
|
||||
"note": s["note"], "code": read_snippet(s["file"])})
|
||||
samples_json = json.dumps(samples)
|
||||
# footer links
|
||||
footlinks = "".join('<a href="%s">%s</a>' % (n["href"], esc(n["label"])) for n in cfg["nav_links"])
|
||||
footlinks += '<a href="%s">Source ↗</a>' % cfg["repo_url"]
|
||||
m = cfg["meta"]
|
||||
|
||||
tmpl = """<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>%(title)s</title>
|
||||
<meta name="description" content="%(desc)s">
|
||||
<meta property="og:title" content="%(ogt)s">
|
||||
<meta property="og:description" content="%(ogd)s">
|
||||
<meta property="og:type" content="website">
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;700&display=swap" rel="stylesheet">
|
||||
<style>
|
||||
%(css)s
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<header class="nav">
|
||||
<div class="wrap nav-in">
|
||||
<a class="brand" href="#top"><span class="logo">L</span> %(brand)s</a>
|
||||
<nav class="nav-links">%(navlinks)s
|
||||
<a class="nav-cta" href="%(repo)s">Source ↗</a>
|
||||
</nav>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<a id="top"></a>
|
||||
<section class="hero">
|
||||
<div class="wrap hero-grid">
|
||||
<div>
|
||||
<span class="pill"><span class="dot"></span> %(pill)s</span>
|
||||
<h1>%(title_pre)s <span class="accent">%(title_accent)s</span></h1>
|
||||
<p class="lead">%(lead)s</p>
|
||||
<div class="cta-row">
|
||||
<a class="btn btn-primary" href="%(pcta_h)s">%(pcta_l)s</a>
|
||||
<a class="btn btn-ghost" href="%(scta_h)s">%(scta_l)s</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="code-card reveal">
|
||||
<div class="code-top">
|
||||
<span class="tl r"></span><span class="tl y"></span><span class="tl g"></span>
|
||||
<span class="code-name">%(hero_name)s</span>
|
||||
</div>
|
||||
<pre data-lang="ludic">%(hero_code)s</pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="wrap" style="margin-top:52px">
|
||||
<div class="pipeline reveal">%(stages)s</div>
|
||||
<p style="text-align:center;color:var(--muted);font-size:13.5px;margin:14px 0 0">%(pipenote)s</p>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section id="features">
|
||||
<div class="wrap">
|
||||
<div class="sec-head reveal">
|
||||
<div class="kicker">%(feat_kicker)s</div>
|
||||
<h2>%(feat_title)s</h2>
|
||||
<p>%(feat_intro)s</p>
|
||||
</div>
|
||||
<div class="feat-grid">%(feats)s</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section id="showcase" style="padding-top:24px">
|
||||
<div class="wrap">
|
||||
<div class="sec-head reveal">
|
||||
<div class="kicker">%(sc_kicker)s</div>
|
||||
<h2>%(sc_title)s</h2>
|
||||
<p>%(sc_intro)s</p>
|
||||
</div>
|
||||
<div class="tabs reveal" id="tabs"></div>
|
||||
<div id="panels"></div>
|
||||
<div class="showcase-note reveal"><span class="b">↳</span><span id="note"></span></div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section style="padding-top:24px">
|
||||
<div class="wrap">
|
||||
<div class="banner reveal">
|
||||
<div>
|
||||
<div class="kicker" style="color:var(--blue)">%(phil_kicker)s</div>
|
||||
<h2>%(phil_title)s</h2>
|
||||
%(phil_paras)s
|
||||
</div>
|
||||
<div class="stat-row">%(phil_stats)s</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section id="start">
|
||||
<div class="wrap">
|
||||
<div class="sec-head reveal">
|
||||
<div class="kicker">%(start_kicker)s</div>
|
||||
<h2>%(start_title)s</h2>
|
||||
<p>%(start_intro)s</p>
|
||||
</div>
|
||||
<div class="steps">
|
||||
<div>%(steps)s</div>
|
||||
<div class="term reveal">
|
||||
<div class="code-top">
|
||||
<span class="tl r"></span><span class="tl y"></span><span class="tl g"></span>
|
||||
<span class="code-name">%(term_name)s</span>
|
||||
</div>
|
||||
<pre>%(term)s</pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section id="editors" style="padding-top:24px">
|
||||
<div class="wrap">
|
||||
<div class="sec-head reveal">
|
||||
<div class="kicker">%(ed_kicker)s</div>
|
||||
<h2>%(ed_title)s</h2>
|
||||
<p>%(ed_intro)s</p>
|
||||
</div>
|
||||
<div class="editors reveal">%(eds)s</div>
|
||||
<p style="margin-top:22px;color:var(--muted);font-size:14.5px">%(ed_note)s</p>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<footer>
|
||||
<div class="wrap foot-in">
|
||||
<div>
|
||||
<div class="brand" style="margin-bottom:8px"><span class="logo">L</span> %(brand)s</div>
|
||||
<div class="muted">%(tagline)s</div>
|
||||
</div>
|
||||
<nav class="foot-links">%(footlinks)s</nav>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<script src="ludic-highlight.js"></script>
|
||||
<script>
|
||||
Ludic.highlightAll();
|
||||
const SAMPLES = %(samples)s;
|
||||
const tabsEl = document.getElementById("tabs");
|
||||
const panelsEl = document.getElementById("panels");
|
||||
const noteEl = document.getElementById("note");
|
||||
SAMPLES.forEach((s, idx)=>{
|
||||
const t = document.createElement("button");
|
||||
t.className = "tab" + (idx===0 ? " active" : "");
|
||||
t.textContent = s.label;
|
||||
t.onclick = ()=>select(idx);
|
||||
tabsEl.appendChild(t);
|
||||
const card = document.createElement("div");
|
||||
card.className = "code-card panel-code" + (idx===0 ? " active" : "");
|
||||
card.innerHTML =
|
||||
'<div class="code-top"><span class="tl r"></span><span class="tl y"></span><span class="tl g"></span><span class="code-name">'
|
||||
+ s.name + '</span></div><pre>' + Ludic.highlight(s.code) + '</pre>';
|
||||
panelsEl.appendChild(card);
|
||||
});
|
||||
function select(idx){
|
||||
[...tabsEl.children].forEach((t,i)=>t.classList.toggle("active", i===idx));
|
||||
[...panelsEl.children].forEach((p,i)=>p.classList.toggle("active", i===idx));
|
||||
noteEl.textContent = SAMPLES[idx].note;
|
||||
}
|
||||
noteEl.textContent = SAMPLES[0].note;
|
||||
const io = new IntersectionObserver((entries)=>{
|
||||
entries.forEach(e=>{ if(e.isIntersecting){ e.target.classList.add("in"); io.unobserve(e.target); } });
|
||||
},{threshold:.12});
|
||||
document.querySelectorAll(".reveal").forEach(el=>io.observe(el));
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
return pct(tmpl, dict(
|
||||
css=css, brand=esc(cfg["brand"]), tagline=esc(cfg["tagline"]), repo=cfg["repo_url"],
|
||||
title=esc(m["title"]), desc=esc(m["description"]), ogt=esc(m["og_title"]), ogd=esc(m["og_description"]),
|
||||
navlinks=navlinks,
|
||||
pill=esc(hero["pill"]), title_pre=esc(hero["title_pre"]), title_accent=esc(hero["title_accent"]),
|
||||
lead=hero["lead"], pcta_h=hero["primary_cta"]["href"], pcta_l=esc(hero["primary_cta"]["label"]),
|
||||
scta_h=hero["secondary_cta"]["href"], scta_l=esc(hero["secondary_cta"]["label"]),
|
||||
hero_name=esc(hero["snippet_name"]), hero_code=hero_code, stages=stages, pipenote=hero["pipeline_note"],
|
||||
feat_kicker=esc(cfg["features"]["kicker"]), feat_title=esc(cfg["features"]["title"]),
|
||||
feat_intro=cfg["features"]["intro"], feats=feats,
|
||||
sc_kicker=esc(cfg["showcase"]["kicker"]), sc_title=esc(cfg["showcase"]["title"]),
|
||||
sc_intro=cfg["showcase"]["intro"],
|
||||
phil_kicker=esc(phil["kicker"]), phil_title=esc(phil["title"]), phil_paras=phil_paras, phil_stats=phil_stats,
|
||||
start_kicker=esc(start["kicker"]), start_title=esc(start["title"]), start_intro=esc(start["intro"]),
|
||||
steps=steps, term_name=esc(start["terminal_name"]), term=term,
|
||||
ed_kicker=esc(cfg["editors"]["kicker"]), ed_title=esc(cfg["editors"]["title"]),
|
||||
ed_intro=cfg["editors"]["intro"], eds=eds, ed_note=cfg["editors"]["note"],
|
||||
footlinks=footlinks, samples=samples_json,
|
||||
))
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
def render_highlighter(symbols):
|
||||
tmpl = open(os.path.join(ASSETS, "ludic-highlight.tmpl.js")).read()
|
||||
return tmpl.replace("/*__SYMBOLS__*/{}", json.dumps(symbols, ensure_ascii=False))
|
||||
|
||||
def main():
|
||||
ap = argparse.ArgumentParser()
|
||||
ap.add_argument("--out", default=os.path.join(ROOT, "build", "pages"))
|
||||
args = ap.parse_args()
|
||||
out = args.out
|
||||
os.makedirs(out, exist_ok=True)
|
||||
|
||||
sections = load_sections()
|
||||
palette = json.load(open(os.path.join(LANG, "colors", "palette.json")))
|
||||
symbols = build_symbols(sections)
|
||||
cfg = json.load(open(os.path.join(SITE, "site.json")))
|
||||
|
||||
open(os.path.join(out, "api.html"), "w").write(render_api(sections, palette, cfg))
|
||||
open(os.path.join(out, "index.html"), "w").write(render_index(cfg))
|
||||
open(os.path.join(out, "ludic-highlight.js"), "w").write(render_highlighter(symbols))
|
||||
open(os.path.join(out, "symbols.json"), "w").write(json.dumps(symbols, indent=2, ensure_ascii=False))
|
||||
open(os.path.join(out, ".nojekyll"), "w").write("")
|
||||
|
||||
n_entries = sum(len(s["entries"]) for s in sections)
|
||||
print("docs generated -> %s" % out)
|
||||
print(" sections: %d symbols: %d colors: %d"
|
||||
% (len(sections), n_entries, palette["count"]))
|
||||
print(" highlighter tokens: %d kw / %d type / %d builtin / %d ns-method / %d annot"
|
||||
% (len(symbols["keywords"]), len(symbols["types"]), len(symbols["builtins"]),
|
||||
len(symbols["nsmethods"]), len(symbols["annotations"])))
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
298
tools/docgen/palette.py
Normal file
298
tools/docgen/palette.py
Normal file
|
|
@ -0,0 +1,298 @@
|
|||
#!/usr/bin/env python3
|
||||
# Single source of truth for Ludic's named color palette.
|
||||
# Emits: selfhost/emit_color.ludic (compiler lookup) and palette.json (docs).
|
||||
import json, sys, os
|
||||
|
||||
# (Name, 0xRRGGBB, group). Names are PascalCase, unique. >200 entries.
|
||||
PALETTE = [
|
||||
# ---- Whites & off-whites ----
|
||||
("White", 0xFFFFFF, "Whites"),
|
||||
("Snow", 0xFFFAFA, "Whites"),
|
||||
("Ivory", 0xFFFFF0, "Whites"),
|
||||
("EggShellWhite", 0xF0EAD6, "Whites"),
|
||||
("FloralWhite", 0xFFFAF0, "Whites"),
|
||||
("SeaShell", 0xFFF5EE, "Whites"),
|
||||
("Linen", 0xFAF0E6, "Whites"),
|
||||
("AntiqueWhite", 0xFAEBD7, "Whites"),
|
||||
("OldLace", 0xFDF5E6, "Whites"),
|
||||
("Beige", 0xF5F5DC, "Whites"),
|
||||
("Cream", 0xFFFDD0, "Whites"),
|
||||
("Honeydew", 0xF0FFF0, "Whites"),
|
||||
("MintCream", 0xF5FFFA, "Whites"),
|
||||
("Azure", 0xF0FFFF, "Whites"),
|
||||
("AliceBlue", 0xF0F8FF, "Whites"),
|
||||
("GhostWhite", 0xF8F8FF, "Whites"),
|
||||
("WhiteSmoke", 0xF5F5F5, "Whites"),
|
||||
("Lavender", 0xE6E6FA, "Whites"),
|
||||
("Bone", 0xE3DAC9, "Whites"),
|
||||
("Parchment", 0xF1E9D2, "Whites"),
|
||||
|
||||
# ---- Grays & neutrals ----
|
||||
("Gainsboro", 0xDCDCDC, "Grays"),
|
||||
("LightGray", 0xD3D3D3, "Grays"),
|
||||
("Silver", 0xC0C0C0, "Grays"),
|
||||
("Ash", 0xB2BEB5, "Grays"),
|
||||
("DarkGray", 0xA9A9A9, "Grays"),
|
||||
("Gray", 0x808080, "Grays"),
|
||||
("DimGray", 0x696969, "Grays"),
|
||||
("Nickel", 0x727472, "Grays"),
|
||||
("Slate", 0x708090, "Grays"),
|
||||
("SlateGray", 0x708090, "Grays"),
|
||||
("LightSlateGray", 0x778899, "Grays"),
|
||||
("Gunmetal", 0x2A3439, "Grays"),
|
||||
("Charcoal", 0x36454F, "Grays"),
|
||||
("Graphite", 0x1C1C1C, "Grays"),
|
||||
("Onyx", 0x353839, "Grays"),
|
||||
("Jet", 0x343434, "Grays"),
|
||||
("Black", 0x000000, "Grays"),
|
||||
("EerieBlack", 0x1B1B1B, "Grays"),
|
||||
("RaisinBlack", 0x242124, "Grays"),
|
||||
("Ebony", 0x555D50, "Grays"),
|
||||
|
||||
# ---- Reds ----
|
||||
("Red", 0xFF0000, "Reds"),
|
||||
("Crimson", 0xDC143C, "Reds"),
|
||||
("Scarlet", 0xFF2400, "Reds"),
|
||||
("Vermilion", 0xE34234, "Reds"),
|
||||
("FireBrick", 0xB22222, "Reds"),
|
||||
("Cinnabar", 0xE44D2E, "Reds"),
|
||||
("DarkRed", 0x8B0000, "Reds"),
|
||||
("Maroon", 0x800000, "Reds"),
|
||||
("Ruby", 0xE0115F, "Reds"),
|
||||
("Cardinal", 0xC41E3A, "Reds"),
|
||||
("IndianRed", 0xCD5C5C, "Reds"),
|
||||
("Rust", 0xB7410E, "Reds"),
|
||||
("Sangria", 0x92000A, "Reds"),
|
||||
("Redwood", 0xA45A52, "Reds"),
|
||||
("Cerise", 0xDE3163, "Reds"),
|
||||
("Amaranth", 0xE52B50, "Reds"),
|
||||
("Carmine", 0x960018, "Reds"),
|
||||
("Chestnut", 0x954535, "Reds"),
|
||||
("Brick", 0xCB4154, "Reds"),
|
||||
("TerraCotta", 0xE2725B, "Reds"),
|
||||
|
||||
# ---- Pinks ----
|
||||
("Pink", 0xFFC0CB, "Pinks"),
|
||||
("LightPink", 0xFFB6C1, "Pinks"),
|
||||
("HotPink", 0xFF69B4, "Pinks"),
|
||||
("DeepPink", 0xFF1493, "Pinks"),
|
||||
("PaleVioletRed", 0xDB7093, "Pinks"),
|
||||
("Rose", 0xFF007F, "Pinks"),
|
||||
("Blush", 0xDE5D83, "Pinks"),
|
||||
("Salmon", 0xFA8072, "Pinks"),
|
||||
("LightSalmon", 0xFFA07A, "Pinks"),
|
||||
("DarkSalmon", 0xE9967A, "Pinks"),
|
||||
("Coral", 0xFF7F50, "Pinks"),
|
||||
("Watermelon", 0xFC6C85, "Pinks"),
|
||||
("Flamingo", 0xFC8EAC, "Pinks"),
|
||||
("Bubblegum", 0xFFC1CC, "Pinks"),
|
||||
("Fuchsia", 0xFF00FF, "Pinks"),
|
||||
("Magenta", 0xFF00FF, "Pinks"),
|
||||
("Mauve", 0xE0B0FF, "Pinks"),
|
||||
("Puce", 0xCC8899, "Pinks"),
|
||||
("Thistle", 0xD8BFD8, "Pinks"),
|
||||
("Orchid", 0xDA70D6, "Pinks"),
|
||||
|
||||
# ---- Oranges ----
|
||||
("Orange", 0xFFA500, "Oranges"),
|
||||
("DarkOrange", 0xFF8C00, "Oranges"),
|
||||
("Tangerine", 0xF28500, "Oranges"),
|
||||
("Pumpkin", 0xFF7518, "Oranges"),
|
||||
("Apricot", 0xFBCEB1, "Oranges"),
|
||||
("Peach", 0xFFE5B4, "Oranges"),
|
||||
("Cantaloupe", 0xFFA62B, "Oranges"),
|
||||
("Amber", 0xFFBF00, "Oranges"),
|
||||
("Bronze", 0xCD7F32, "Oranges"),
|
||||
("Copper", 0xB87333, "Oranges"),
|
||||
("Marigold", 0xEAA221, "Oranges"),
|
||||
("Carrot", 0xED9121, "Oranges"),
|
||||
("Persimmon", 0xEC5800, "Oranges"),
|
||||
("Papaya", 0xFF9E2C, "Oranges"),
|
||||
("Sunset", 0xFAD6A5, "Oranges"),
|
||||
|
||||
# ---- Yellows ----
|
||||
("Yellow", 0xFFFF00, "Yellows"),
|
||||
("LightYellow", 0xFFFFE0, "Yellows"),
|
||||
("Gold", 0xFFD700, "Yellows"),
|
||||
("Goldenrod", 0xDAA520, "Yellows"),
|
||||
("Lemon", 0xFFF700, "Yellows"),
|
||||
("Canary", 0xFFEF00, "Yellows"),
|
||||
("Mustard", 0xFFDB58, "Yellows"),
|
||||
("Flax", 0xEEDC82, "Yellows"),
|
||||
("Wheat", 0xF5DEB3, "Yellows"),
|
||||
("Corn", 0xFBEC5D, "Yellows"),
|
||||
("Dandelion", 0xF0E130, "Yellows"),
|
||||
("Saffron", 0xF4C430, "Yellows"),
|
||||
("Khaki", 0xF0E68C, "Yellows"),
|
||||
("DarkKhaki", 0xBDB76B, "Yellows"),
|
||||
("Straw", 0xE4D96F, "Yellows"),
|
||||
|
||||
# ---- Browns ----
|
||||
("Brown", 0x8B4513, "Browns"),
|
||||
("SaddleBrown", 0x8B4513, "Browns"),
|
||||
("Sienna", 0xA0522D, "Browns"),
|
||||
("Chocolate", 0xD2691E, "Browns"),
|
||||
("Peru", 0xCD853F, "Browns"),
|
||||
("Tan", 0xD2B48C, "Browns"),
|
||||
("BurlyWood", 0xDEB887, "Browns"),
|
||||
("Sand", 0xC2B280, "Browns"),
|
||||
("Coffee", 0x6F4E37, "Browns"),
|
||||
("Espresso", 0x4B3621, "Browns"),
|
||||
("Mahogany", 0xC04000, "Browns"),
|
||||
("Walnut", 0x773F1A, "Browns"),
|
||||
("Umber", 0x635147, "Browns"),
|
||||
("Sepia", 0x704214, "Browns"),
|
||||
("Taupe", 0x483C32, "Browns"),
|
||||
("Fawn", 0xE5AA70, "Browns"),
|
||||
("Caramel", 0xC68E17, "Browns"),
|
||||
("Cocoa", 0xD2691E, "Browns"),
|
||||
("Hazel", 0x8E7618, "Browns"),
|
||||
("Wenge", 0x645452, "Browns"),
|
||||
|
||||
# ---- Greens ----
|
||||
("Green", 0x008000, "Greens"),
|
||||
("Lime", 0x00FF00, "Greens"),
|
||||
("LimeGreen", 0x32CD32, "Greens"),
|
||||
("LawnGreen", 0x7CFC00, "Greens"),
|
||||
("Chartreuse", 0x7FFF00, "Greens"),
|
||||
("GreenYellow", 0xADFF2F, "Greens"),
|
||||
("SpringGreen", 0x00FF7F, "Greens"),
|
||||
("MintGreen", 0x98FF98, "Greens"),
|
||||
("SeaGreen", 0x2E8B57, "Greens"),
|
||||
("MediumSeaGreen", 0x3CB371, "Greens"),
|
||||
("ForestGreen", 0x228B22, "Greens"),
|
||||
("DarkGreen", 0x006400, "Greens"),
|
||||
("OliveDrab", 0x6B8E23, "Greens"),
|
||||
("Olive", 0x808000, "Greens"),
|
||||
("Moss", 0x8A9A5B, "Greens"),
|
||||
("Fern", 0x4F7942, "Greens"),
|
||||
("Emerald", 0x50C878, "Greens"),
|
||||
("Jade", 0x00A86B, "Greens"),
|
||||
("Malachite", 0x0BDA51, "Greens"),
|
||||
("Shamrock", 0x009E60, "Greens"),
|
||||
("Pistachio", 0x93C572, "Greens"),
|
||||
("Avocado", 0x568203, "Greens"),
|
||||
("Pine", 0x01796F, "Greens"),
|
||||
("Sage", 0x9CAF88, "Greens"),
|
||||
("Kelly", 0x4CBB17, "Greens"),
|
||||
("Hunter", 0x355E3B, "Greens"),
|
||||
("Basil", 0x579229, "Greens"),
|
||||
("Clover", 0x2E8B57, "Greens"),
|
||||
("Juniper", 0x6D9A79, "Greens"),
|
||||
("Neon", 0x39FF14, "Greens"),
|
||||
|
||||
# ---- Cyans / teals ----
|
||||
("Cyan", 0x00FFFF, "Cyans"),
|
||||
("Aqua", 0x00FFFF, "Cyans"),
|
||||
("LightCyan", 0xE0FFFF, "Cyans"),
|
||||
("PaleTurquoise", 0xAFEEEE, "Cyans"),
|
||||
("Aquamarine", 0x7FFFD4, "Cyans"),
|
||||
("Turquoise", 0x40E0D0, "Cyans"),
|
||||
("MediumTurquoise",0x48D1CC, "Cyans"),
|
||||
("DarkTurquoise", 0x00CED1, "Cyans"),
|
||||
("Teal", 0x008080, "Cyans"),
|
||||
("DarkCyan", 0x008B8B, "Cyans"),
|
||||
("CadetBlue", 0x5F9EA0, "Cyans"),
|
||||
("Lagoon", 0x018E8E, "Cyans"),
|
||||
("Seafoam", 0x93E9BE, "Cyans"),
|
||||
("Cerulean", 0x007BA7, "Cyans"),
|
||||
("SkyBlueLight", 0x80DAEB, "Cyans"),
|
||||
("Robin", 0x00CCCC, "Cyans"),
|
||||
("Verdigris", 0x43B3AE, "Cyans"),
|
||||
("Celadon", 0xACE1AF, "Cyans"),
|
||||
|
||||
# ---- Blues ----
|
||||
("Blue", 0x0000FF, "Blues"),
|
||||
("LightBlue", 0xADD8E6, "Blues"),
|
||||
("PowderBlue", 0xB0E0E6, "Blues"),
|
||||
("SkyBlue", 0x87CEEB, "Blues"),
|
||||
("LightSkyBlue", 0x87CEFA, "Blues"),
|
||||
("DeepSkyBlue", 0x00BFFF, "Blues"),
|
||||
("DodgerBlue", 0x1E90FF, "Blues"),
|
||||
("CornflowerBlue", 0x6495ED, "Blues"),
|
||||
("SteelBlue", 0x4682B4, "Blues"),
|
||||
("RoyalBlue", 0x4169E1, "Blues"),
|
||||
("MediumBlue", 0x0000CD, "Blues"),
|
||||
("DarkBlue", 0x00008B, "Blues"),
|
||||
("Navy", 0x000080, "Blues"),
|
||||
("MidnightBlue", 0x191970, "Blues"),
|
||||
("Cobalt", 0x0047AB, "Blues"),
|
||||
("Sapphire", 0x0F52BA, "Blues"),
|
||||
("Denim", 0x1560BD, "Blues"),
|
||||
("Indigo", 0x4B0082, "Blues"),
|
||||
("Prussian", 0x003153, "Blues"),
|
||||
("Ultramarine", 0x3F00FF, "Blues"),
|
||||
("Periwinkle", 0xCCCCFF, "Blues"),
|
||||
("Iris", 0x5A4FCF, "Blues"),
|
||||
("Glaucous", 0x6082B6, "Blues"),
|
||||
("Zaffre", 0x0014A8, "Blues"),
|
||||
("Berry", 0x2E2D88, "Blues"),
|
||||
|
||||
# ---- Purples ----
|
||||
("Purple", 0x800080, "Purples"),
|
||||
("Violet", 0xEE82EE, "Purples"),
|
||||
("DarkViolet", 0x9400D3, "Purples"),
|
||||
("BlueViolet", 0x8A2BE2, "Purples"),
|
||||
("MediumPurple", 0x9370DB, "Purples"),
|
||||
("Amethyst", 0x9966CC, "Purples"),
|
||||
("Plum", 0x8E4585, "Purples"),
|
||||
("Eggplant", 0x614051, "Purples"),
|
||||
("Grape", 0x6F2DA8, "Purples"),
|
||||
("Wine", 0x722F37, "Purples"),
|
||||
("Mulberry", 0xC54B8C, "Purples"),
|
||||
("Lilac", 0xC8A2C8, "Purples"),
|
||||
("Wisteria", 0xC9A0DC, "Purples"),
|
||||
("Heliotrope", 0xDF73FF, "Purples"),
|
||||
("Byzantium", 0x702963, "Purples"),
|
||||
("Tyrian", 0x66023C, "Purples"),
|
||||
("RebeccaPurple", 0x663399, "Purples"),
|
||||
("Orchid2", 0xAF69EF, "Purples"),
|
||||
]
|
||||
|
||||
def guard_check():
|
||||
names = [p[0] for p in PALETTE]
|
||||
dup = set(n for n in names if names.count(n) > 1)
|
||||
if dup:
|
||||
print("DUPLICATE NAMES:", dup, file=sys.stderr); sys.exit(1)
|
||||
return names
|
||||
|
||||
def emit_ludic(path):
|
||||
lines = []
|
||||
lines.append("# ============================================================================")
|
||||
lines.append("# emit_color.ludic — the named-color palette, resolved at compile time.")
|
||||
lines.append("#")
|
||||
lines.append("# `Color.Name` in a game lowers to a plain 0xRRGGBB int here: no runtime cost,")
|
||||
lines.append("# no allocation, identical codegen to writing the hex by hand. Unknown names are")
|
||||
lines.append("# a compile error (color_lookup returns -1, which emit_expr reports).")
|
||||
lines.append("#")
|
||||
lines.append("# GENERATED by scratchpad/palette.py from the single source-of-truth palette.")
|
||||
lines.append("# Edit the palette there and regenerate; do not hand-edit this file.")
|
||||
lines.append("# ============================================================================")
|
||||
lines.append("")
|
||||
lines.append("fn color_lookup(name: ptr) -> int {")
|
||||
for (nm, hexv, grp) in PALETTE:
|
||||
lines.append(f' if (name == "{nm}") {{ return 0x{hexv:06X} }}')
|
||||
lines.append(" return -1")
|
||||
lines.append("}")
|
||||
lines.append("")
|
||||
with open(path, "w") as f:
|
||||
f.write("\n".join(lines) + "\n")
|
||||
|
||||
def emit_json(path):
|
||||
groups = {}
|
||||
order = []
|
||||
for (nm, hexv, grp) in PALETTE:
|
||||
if grp not in groups:
|
||||
groups[grp] = []; order.append(grp)
|
||||
groups[grp].append({"name": nm, "hex": f"{hexv:06X}"})
|
||||
out = {"count": len(PALETTE), "groups": [{"name": g, "colors": groups[g]} for g in order]}
|
||||
with open(path, "w") as f:
|
||||
json.dump(out, f, indent=2)
|
||||
|
||||
if __name__ == "__main__":
|
||||
names = guard_check()
|
||||
root = os.path.dirname(os.path.abspath(__file__))
|
||||
repo = "/Users/orkuncakilkaya/workspace/gpp"
|
||||
emit_ludic(os.path.join(repo, "selfhost", "emit_color.ludic"))
|
||||
emit_json(os.path.join(root, "palette.json"))
|
||||
print(f"OK {len(PALETTE)} colors ({len(set(names))} unique names)")
|
||||
Loading…
Add table
Add a link
Reference in a new issue