diff options
| -rw-r--r-- | scripts/theme-studio/Makefile | 2 | ||||
| -rw-r--r-- | scripts/theme-studio/build-theme.el | 10 | ||||
| -rw-r--r-- | tests/test-build-theme.el | 19 |
3 files changed, 26 insertions, 5 deletions
diff --git a/scripts/theme-studio/Makefile b/scripts/theme-studio/Makefile index d98478aef..374c7fb1b 100644 --- a/scripts/theme-studio/Makefile +++ b/scripts/theme-studio/Makefile @@ -99,5 +99,5 @@ ifndef JSON endif @$(MAKE) theme JSON='$(JSON)' OUT='$(OUT)' EMACS='$(EMACS)' @theme_name='$(THEME)'; \ - if [ -z "$$theme_name" ]; then theme_name="$$(python3 -c 'import json,sys; print(json.load(open(sys.argv[1]))["name"])' '$(JSON)')"; fi; \ + if [ -z "$$theme_name" ]; then theme_name="$$(basename '$(JSON)' .json)"; fi; \ $(MAKE) theme-load THEME="$$theme_name" OUT='$(OUT)' EMACSCLIENT='$(EMACSCLIENT)' diff --git a/scripts/theme-studio/build-theme.el b/scripts/theme-studio/build-theme.el index 786a3d960..827129976 100644 --- a/scripts/theme-studio/build-theme.el +++ b/scripts/theme-studio/build-theme.el @@ -246,11 +246,13 @@ Signal a `file-missing' error when JSON-FILE does not exist." (defun build-theme/convert-file (json-file &optional out-dir) "Convert JSON-FILE (a theme.json export) into a deftheme file. -Write themes/<name>-theme.el, where <name> is the JSON name field, into -OUT-DIR (default: the themes/ directory of this repo). Return the written -path." +Write themes/<name>-theme.el, where <name> is JSON-FILE's basename, into +OUT-DIR (default: the themes/ directory of this repo). The basename names the +theme so each export lands under its own file (sterling.json -> sterling-theme.el), +rather than colliding on whatever the JSON's internal name field happens to be. +Return the written path." (let* ((data (build-theme/--parse json-file)) - (name (build-theme/--obj-get data 'name)) + (name (file-name-base json-file)) (specs (build-theme/--all-specs data)) (dir (or out-dir (expand-file-name diff --git a/tests/test-build-theme.el b/tests/test-build-theme.el index bf45f3807..9221946e6 100644 --- a/tests/test-build-theme.el +++ b/tests/test-build-theme.el @@ -320,6 +320,25 @@ including an inherit+height package face." (test-build-theme--with-sandbox out (should-error (build-theme/convert-file (expand-file-name "does-not-exist.json" out) out)))) +(ert-deftest test-build-theme-name-from-filename-not-json-field () + "Normal/Regression: the output name comes from the JSON file's basename, not +its internal name field, so each draft exports under its own name (a WIP.json +becomes WIP-theme.el, never theme-theme.el)." + (test-build-theme--with-sandbox out + ;; The fixture's internal name field is \"dupre-fixture\"; the file is sterling.json. + (let ((in (expand-file-name "sterling.json" out))) + (with-temp-file in (insert test-build-theme--fixture-json)) + (let ((path (build-theme/convert-file in out))) + (should (string-suffix-p "sterling-theme.el" path)) + (should-not (string-match-p "dupre-fixture" path)) + (let ((custom-theme-load-path (cons out custom-theme-load-path)) + (load-path (cons out load-path))) + (unwind-protect + (progn + (load-theme 'sterling t) + (should (string= (face-attribute 'default :background nil t) "#000000"))) + (disable-theme 'sterling))))))) + (ert-deftest test-build-theme-generated-default-meets-wcag-aa () "Error/Regression: the generated default face stays legible. A WCAG-AA (>= 4.5:1) assertion on the round-tripped result -- proves the whole |
