diff options
| author | Craig Jennings <c@cjennings.net> | 2026-07-11 23:52:49 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-07-11 23:52:49 -0500 |
| commit | b0ca38bc98f240e208edd08009856ab6de62c227 (patch) | |
| tree | 0412890e4480ade5e954104d428178bba3f4e64c | |
| parent | b137223e76c75217b594bc5e46e7625b10e31b0f (diff) | |
| download | archsetup-b0ca38bc98f240e208edd08009856ab6de62c227.tar.gz archsetup-b0ca38bc98f240e208edd08009856ab6de62c227.zip | |
refactor(gallery): rename generated tokens.el to gallery-tokens.el
The generated file declares (provide 'gallery-tokens), but `require` resolves a feature by filename, so as tokens.el it could never load from a load-path. The name now matches the feature. gen_tokens.py, the renderer's load, and the README follow.
| -rw-r--r-- | docs/prototypes/README.org | 4 | ||||
| -rw-r--r-- | docs/prototypes/gallery-tokens.el (renamed from docs/prototypes/tokens.el) | 0 | ||||
| -rw-r--r-- | docs/prototypes/gallery-widget.el | 6 | ||||
| -rw-r--r-- | docs/prototypes/gen_tokens.py | 8 | ||||
| -rw-r--r-- | tests/gallery-tokens/test_gen_tokens.py | 12 | ||||
| -rw-r--r-- | tests/gallery-widgets/test-gallery-widget.el | 2 |
6 files changed, 23 insertions, 9 deletions
diff --git a/docs/prototypes/README.org b/docs/prototypes/README.org index 3f2e3be..674a45d 100644 --- a/docs/prototypes/README.org +++ b/docs/prototypes/README.org @@ -28,10 +28,10 @@ family, glows, pulse rate). [[file:gen_tokens.py][gen_tokens.py]] regenerates al - the =:root= block inside the gallery HTML (web CSS custom properties) - [[file:tokens-waybar.css][tokens-waybar.css]] — GTK =@define-color= declarations for the waybar panels -- [[file:tokens.el][tokens.el]] — an elisp alist for svg.el renderers +- [[file:gallery-tokens.el][gallery-tokens.el]] — an elisp alist for svg.el renderers [[file:gallery-widget.el][gallery-widget.el]] is the Emacs renderer (proof widget: the needle gauge, -gallery card 10) — it reads tokens.el and emits the widget as SVG via +gallery card 10) — it reads gallery-tokens.el and emits the widget as SVG via svg.el, so the same look renders inside Emacs. Tests: =tests/gallery-tokens/= (generator, unittest) and =tests/gallery-widgets/= (renderer, ERT), both in =make test-unit=. diff --git a/docs/prototypes/tokens.el b/docs/prototypes/gallery-tokens.el index 1fb6e52..1fb6e52 100644 --- a/docs/prototypes/tokens.el +++ b/docs/prototypes/gallery-tokens.el diff --git a/docs/prototypes/gallery-widget.el b/docs/prototypes/gallery-widget.el index 61cd78a..1c96f45 100644 --- a/docs/prototypes/gallery-widget.el +++ b/docs/prototypes/gallery-widget.el @@ -3,8 +3,8 @@ ;;; Commentary: ;; Proof-of-concept Emacs target for the panel widget gallery. The web ;; gallery (panel-widget-gallery.html) is the visual spec; tokens.json is -;; the shared source of truth, and gen_tokens.py emits tokens.el (the -;; `gallery-tokens' alist this file reads). Same tokens, same geometry, +;; the shared source of truth, and gen_tokens.py emits gallery-tokens.el +;; (the `gallery-tokens' alist this file reads). Same tokens, same geometry, ;; different renderer — that's the reuse model: shared values and shared ;; SVG shapes, per-target code. ;; @@ -25,7 +25,7 @@ (require 'svg) (require 'dom) -(load (expand-file-name "tokens.el" +(load (expand-file-name "gallery-tokens.el" (file-name-directory (or load-file-name buffer-file-name))) nil t) diff --git a/docs/prototypes/gen_tokens.py b/docs/prototypes/gen_tokens.py index f966451..9f011e9 100644 --- a/docs/prototypes/gen_tokens.py +++ b/docs/prototypes/gen_tokens.py @@ -29,7 +29,7 @@ Usage: The web CSS is written into panel-widget-gallery.html between the `/* @tokens:start */` and `/* @tokens:end */` markers; the waybar and elisp -targets are written to tokens-waybar.css and tokens.el beside it. +targets are written to tokens-waybar.css and gallery-tokens.el beside it. """ import json @@ -39,6 +39,10 @@ HERE = os.path.dirname(os.path.abspath(__file__)) TOKENS_START = "/* @tokens:start */" TOKENS_END = "/* @tokens:end */" +# The elisp target's filename must match its (provide 'gallery-tokens) so +# `require` resolves it from a load-path. +DEFAULT_ELISP_NAME = "gallery-tokens.el" + # sections whose values are plain colors (searched by resolve_color, and the # ones that become @define-color / alist color entries) COLOR_SECTIONS = ("palette", "amber") @@ -152,7 +156,7 @@ def main(tokens_path=None, html_path=None, waybar_path=None, elisp_path=None): tokens_path = tokens_path or os.path.join(HERE, "tokens.json") html_path = html_path or os.path.join(HERE, "panel-widget-gallery.html") waybar_path = waybar_path or os.path.join(HERE, "tokens-waybar.css") - elisp_path = elisp_path or os.path.join(HERE, "tokens.el") + elisp_path = elisp_path or os.path.join(HERE, DEFAULT_ELISP_NAME) with open(tokens_path) as f: tokens = json.load(f) diff --git a/tests/gallery-tokens/test_gen_tokens.py b/tests/gallery-tokens/test_gen_tokens.py index 414194e..b9fbb50 100644 --- a/tests/gallery-tokens/test_gen_tokens.py +++ b/tests/gallery-tokens/test_gen_tokens.py @@ -210,6 +210,16 @@ class RealTokensJson(unittest.TestCase): self.assertIn("pulse-rate", self.tokens["timing"]) +class DefaultElispFilename(unittest.TestCase): + """The default elisp target must be gallery-tokens.el so that the file's + (provide 'gallery-tokens) matches its name and `require` can resolve it + from a load-path. A tokens.el/gallery-tokens feature mismatch is a trap.""" + + def test_default_elisp_path_matches_provided_feature(self): + self.assertEqual( + os.path.basename(gt.DEFAULT_ELISP_NAME), "gallery-tokens.el") + + class MainIntegration(unittest.TestCase): """main() rewrites the html :root and writes the waybar + elisp files.""" @@ -218,7 +228,7 @@ class MainIntegration(unittest.TestCase): self.html = os.path.join(self.tmp, "gallery.html") self.tokens_path = os.path.join(self.tmp, "tokens.json") self.waybar = os.path.join(self.tmp, "tokens-waybar.css") - self.elisp = os.path.join(self.tmp, "tokens.el") + self.elisp = os.path.join(self.tmp, "gallery-tokens.el") with open(self.tokens_path, "w") as f: json.dump(FIXTURE, f) with open(self.html, "w") as f: diff --git a/tests/gallery-widgets/test-gallery-widget.el b/tests/gallery-widgets/test-gallery-widget.el index ec484bb..166cd59 100644 --- a/tests/gallery-widgets/test-gallery-widget.el +++ b/tests/gallery-widgets/test-gallery-widget.el @@ -2,7 +2,7 @@ ;;; Commentary: ;; Tests for the svg.el proof-of-concept renderer in docs/prototypes/. -;; gallery-widget.el reads the generated tokens.el (same source of truth as +;; gallery-widget.el reads the generated gallery-tokens.el (same source of truth as ;; the web gallery and the waybar CSS) and renders gallery widgets as SVG. ;; These tests exercise the REAL module (loaded by path, not a copy): ;; token resolution, needle-angle math (normal/boundary/error), and the |
