feat(variants): json definitions may list ALL option keys — empty value means inherit the mother default
- build.php: an option value of "" or null in the variant json is skipped, so it inherits the default from vanilla_respondage's config.xml (previously an empty value would have been written as-is). The legacy logotopmargin migration now also ignores an empty value, and the fontOptions default-font rule treats "font": "" as unset. Header comment documents the convention. - Regenerated the three local variant definitions (variants/respondage_defensie, respondage_erasmus, respondage_respondage — gitignored) with all 109 option keys: known values filled in (legacy keys modernized: logotopmargin -> per-logo keys, brandlogo off -> brandlogofile off, hex chooser values -> mode "other" + *custom), everything else "". respondage_respondage's known values were derived from the tracked example output config.xml. - README build process documents the all-keys/empty-inherits convention. Verified in a /tmp sandbox: all three jsons build cleanly (4 built, 0 failed); defensie/erasmus/respondage configs carry the known values and inherit the mother defaults for empty keys (e.g. erasmus centerlogofile stays ./files/logo.png, centerlogotopmargin 30); php -l clean; export exit 0. Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
parent
98cf23e999
commit
28f6b0f9c1
2 changed files with 22 additions and 5 deletions
15
README.md
15
README.md
|
|
@ -381,9 +381,18 @@ the variant's `preview.png` is identical to the mother's.
|
|||
never hardcode house-style values in shared files (`views/`, `css/`,
|
||||
`scripts/`), because those are inherited by all variants.
|
||||
2. In the private variants repo, create `variants/<client>.json` with the
|
||||
variant name/title/description and only the house-style option keys with the
|
||||
client values, plus a `<client>/` asset folder (logos, `files/fonts/`,
|
||||
`css/variant.css`, `files/preview.svg`/`preview.png`).
|
||||
variant name/title/description and the option values, plus a `<client>/`
|
||||
asset folder (logos, `files/fonts/`, `css/variant.css`,
|
||||
`files/preview.svg`/`preview.png`). The json may list **ALL option keys**
|
||||
of the mother `config.xml` (109 at the time of writing) so it is visible what
|
||||
CAN be set per variant: an **empty value (`""`) means "inherit the default
|
||||
from vanilla_respondage"** — `build.php` skips empty values, so only the
|
||||
filled-in keys are written into the variant config. Fill in the house-style
|
||||
values you know (keys marked `HOUSE-STYLE` in `config.xml`: colors, fonts,
|
||||
font sizes/colors/weights, logo files/margins, background image/color);
|
||||
leave the rest empty. Legacy keys (e.g. `logotopmargin`, `<pos>logo`,
|
||||
hex values in chooser options) are still accepted and migrated by
|
||||
`build.php`, but writing the new-model keys directly is recommended.
|
||||
Naming convention: folder/json `respondage_<client>`, metadata `name`
|
||||
`respondage_<client>` (must equal the file name), `title`
|
||||
`"<Client> LimeSurvey theme"` (e.g. `respondage_acme` →
|
||||
|
|
|
|||
|
|
@ -56,6 +56,11 @@
|
|||
* "fontOptions": [{"value": "my_custom_font", "label": "My Custom Font"}] custom fonts,
|
||||
* appended to the "Custom (this theme)" optgroup of the font dropdown
|
||||
*
|
||||
* The json may list ALL option keys of the mother config.xml (row 245): an EMPTY
|
||||
* value ("" or null) means "inherit the mother theme's default" and is skipped —
|
||||
* only non-empty values are written into the variant config. So a variant json
|
||||
* can show every key the user CAN set, while leaving unknown ones to inherit.
|
||||
*
|
||||
* Output:
|
||||
* ../<variantName>/config.xml (next to this theme, in upload/themes/survey)
|
||||
*
|
||||
|
|
@ -244,7 +249,7 @@ if (!empty($definition['options']) && !is_array($definition['options'])) {
|
|||
// the DEFAULT value of the "font" option (so it is pre-selected in the options page
|
||||
// dropdown), unless the json sets options.font explicitly.
|
||||
if (!empty($definition['fontOptions'])
|
||||
&& (empty($definition['options']) || !isset($definition['options']['font']))) {
|
||||
&& (empty($definition['options']) || !isset($definition['options']['font']) || $definition['options']['font'] === '')) {
|
||||
$definition['options']['font'] = preg_replace('/[^a-z0-9_]/i', '_', (string) $definition['fontOptions'][0]['value']);
|
||||
}
|
||||
// --- Prompt M migration: map the OLD logo json keys to the NEW per-logo keys ---
|
||||
|
|
@ -258,7 +263,7 @@ $logoPositions = ['brand', 'center', 'right'];
|
|||
if (!isset($definition['options']) || !is_array($definition['options'])) {
|
||||
$definition['options'] = [];
|
||||
}
|
||||
if (isset($definition['options']['logotopmargin'])) {
|
||||
if (isset($definition['options']['logotopmargin']) && $definition['options']['logotopmargin'] !== '') {
|
||||
$margin = preg_replace('/[^0-9]/', '', (string) $definition['options']['logotopmargin']);
|
||||
if ($margin === '') {
|
||||
$margin = '15';
|
||||
|
|
@ -337,6 +342,9 @@ if ($optionsNode === null) {
|
|||
exit(1);
|
||||
}
|
||||
foreach (($definition['options'] ?? []) as $key => $value) {
|
||||
if ($value === '' || $value === null) {
|
||||
continue; // row 245: empty value = inherit the mother theme's default
|
||||
}
|
||||
$matches = $xpath->query('//options/' . $key);
|
||||
if ($matches->length === 0) {
|
||||
fwrite(STDERR, "Option '$key' from $definitionFile does not exist in the mother config.xml.\n");
|
||||
|
|
|
|||
Loading…
Reference in a new issue