feat(variants): document value format per option key in variant jsons

Every variants/<client>.json now carries a "_formats" map: behind each
option key, the form the value should take ("on|off", "hex color, e.g.
#123456", "plain px number, e.g. 15", "off | ./files/logo.png", font
slug, chooser mode + <key>custom, ...), derived from the mother config.xml
by variants/option_formats.php. variants/document_options.php refreshes the
map in every json (--check for staleness); build.php adds a hint when it
auto-adds a NEW option key to a json. _formats is documentation only and
never read by the build or the drift check.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
Tammo ter Hark 2026-11-30 16:57:44 +01:00
commit f3d3912c2f

View file

@ -63,6 +63,11 @@
* Row 246: when the mother config.xml gains NEW option keys, they are added to
* the json automatically as "" and a NOTE is printed listing them, so the user
* is informed about every new settable key (existing values are never touched).
* Row 264: the "_formats" map in the json documents, per option key, in which
* FORM the value should be filled in (e.g. "on|off", "hex color, e.g. #123456",
* "plain px number, e.g. 15"). It is generated from the mother config.xml by
* variants/document_options.php; new auto-added keys get their hint here too.
* "_formats" is documentation only and is never read back by the build.
*
* Output:
* ../<variantName>/config.xml (next to this theme, in upload/themes/survey)
@ -140,6 +145,7 @@ foreach ($motherOptionKeys as $k) {
}
}
if (!empty($newKeys)) {
require_once __DIR__ . '/option_formats.php';
$ordered = [];
foreach ($motherOptionKeys as $k) {
$ordered[$k] = $definition['options'][$k];
@ -150,8 +156,18 @@ if (!empty($newKeys)) {
}
}
$definition['options'] = $ordered;
// row 264: document the expected value format per new key in "_formats"
// (documentation only — never read back by the build)
if (!isset($definition['_formats']) || !is_array($definition['_formats'])) {
$definition['_formats'] = [];
}
foreach ($xpath->query('//options/*') as $opt) {
if ($opt instanceof DOMElement && in_array($opt->nodeName, $newKeys, true)) {
$definition['_formats'][$opt->nodeName] = option_format_hint($opt);
}
}
file_put_contents($definitionFile, json_encode($definition, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . "\n");
echo "NOTE: " . count($newKeys) . " NEW option key(s) in the mother config.xml were added to $definitionFile as \"\" (inherit default) — review them: " . implode(', ', $newKeys) . "\n";
echo "NOTE: " . count($newKeys) . " NEW option key(s) in the mother config.xml were added to $definitionFile as \"\" (inherit default) with a format hint in \"_formats\" — review them: " . implode(', ', $newKeys) . "\n";
}
$motherName = (string) $xpath->query('//metadata/name')->item(0)->textContent;