diff options
| author | Craig Jennings <c@cjennings.net> | 2026-06-09 05:00:53 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-06-09 05:00:53 -0500 |
| commit | eaf169045a1106935dd887d8d795d0138ad2b8a5 (patch) | |
| tree | c343dcc34227f62f0272733d79059e68e39ec20f /scripts/theme-studio/test_generate.py | |
| parent | d04f44ddbb213d7b443ca4432b3db13ab1a68e38 (diff) | |
| download | dotemacs-eaf169045a1106935dd887d8d795d0138ad2b8a5.tar.gz dotemacs-eaf169045a1106935dd887d8d795d0138ad2b8a5.zip | |
refactor(theme-studio): extract CSS and JS to files, inline at generate time
generate.py was 1378 lines, ~1300 of them a single triple-quoted string holding the whole app. Moved the <style> block to styles.css and the <script> body to app.js, and generate.py now inlines both through placeholders the same way it already inlines colormath.js, then fills the data placeholders. It drops to ~500 lines (the remaining bulk is the package face-data dicts, a later stage).
The generated page is byte-identical to before — every hash gate, the node suite, the spliced-script parse, and the new #locktest stay green. Two integrity tests guard the splice: styles.css inlines verbatim, and app.js reaches the page exactly as fill_data renders it. Both go red if the splice wiring is dropped.
Living in real files instead of a Python string kills the backslash-doubling bug class (str.replace is literal, so escapes survive), gives the CSS and JS real editor tooling, and opens the app logic to unit testing — the point of the whole refactor.
Diffstat (limited to 'scripts/theme-studio/test_generate.py')
| -rw-r--r-- | scripts/theme-studio/test_generate.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/scripts/theme-studio/test_generate.py b/scripts/theme-studio/test_generate.py index e76acdad..7a9079ac 100644 --- a/scripts/theme-studio/test_generate.py +++ b/scripts/theme-studio/test_generate.py @@ -62,6 +62,7 @@ class ColormathInlining(unittest.TestCase): class AssembledPage(unittest.TestCase): PLACEHOLDERS = [ + "STYLES_CSS", "APP_JS", "COLORMATH_J", "SAMPLES_J", "PALETTE_J", "CATS_J", "UIFACES_J", "UIMAP_J", "APPS_J", "BOLD_J", "MAP_J", ] @@ -75,6 +76,17 @@ class AssembledPage(unittest.TestCase): # checked at the point the page is built rather than after a round-trip. self.assertIn(generate.COLORMATH_BODY, generate.HTML) + def test_page_carries_the_stylesheet_verbatim(self): + # styles.css has no placeholders, so it inlines verbatim: the inlined copy + # and the source file cannot drift. + self.assertIn(generate.STYLES, generate.HTML) + + def test_page_carries_the_app_script_faithfully(self): + # app.js does carry placeholders, so the page holds it as fill_data renders + # it (APP_FILLED), not the raw file. This guards the splice: the script + # reaches the page intact, with its data placeholders correctly filled. + self.assertIn(generate.APP_FILLED, generate.HTML) + def test_page_is_a_single_script_document(self): self.assertEqual(generate.HTML.count("<script>"), 1) self.assertEqual(generate.HTML.count("</script>"), 1) |
