diff --git a/.gitignore b/.gitignore index bf22d7a..ecaf2b3 100644 --- a/.gitignore +++ b/.gitignore @@ -32,10 +32,15 @@ # Export zips, if an output dir inside the theme is ever used. /dist/ -# Work-in-progress artwork sources (logo/preview SVGs) — local only, never -# commit/publish. LimeSurvey's image validator rejects SVG for theme images -# anyway, so only the exported PNG is ever committed (e.g. files/preview.png). -/files/*.svg +# Work-in-progress logo artwork — local only, never commit/publish. +/files/logos.svg + +# NOTE: files/preview.svg is deliberately NOT ignored (standing rule, row 235): +# it is the editable source of files/preview.png and is meant to be committed — +# in a variant (private variants repo) build.php adds it only once, at first +# creation, and never overwrites it afterwards. The public export still excludes +# all files/*.svg (see variants/export_public.sh): LimeSurvey's image validator +# rejects SVG for theme images, so only the exported PNG ships. # Session prompt log (prompts used + results). Internal working notes — never # commit, never publish. diff --git a/variants/build.php b/variants/build.php index 2053763..99aac73 100644 --- a/variants/build.php +++ b/variants/build.php @@ -39,6 +39,14 @@ * /css/... client css (e.g. css/variant.css with @font-face) * The / folder is copied into the generated theme automatically. * + * PREVIEW RULE (standing rule, row 235): every variant must have a preview that + * DIFFERS from the mother's (files/preview.png). files/preview.svg is the + * editable source of that png: it is NOT gitignored, it is added to the variant + * only ONCE at first creation (seeded from the mother if the definitions dir has + * none) and is NEVER overwritten on later builds — the user may edit it. After + * editing preview.svg, export files/preview.png from it (Inkscape: PNG export). + * The build warns when the variant's preview.png is identical to the mother's. + * * Example: * php variants/build.php /path/to/private-variants * @@ -114,8 +122,15 @@ function setMetadata(DOMXPath $xpath, DOMDocument $doc, string $tag, string $val $node->textContent = $value; } -/** Recursively copy a directory (used for the variant's own assets). */ -function copyDirRecursive(string $src, string $dst): void +/** + * Recursively copy a directory (used for the variant's own assets). + * + * $neverOverwrite lists destination-relative paths (with '/' separators) that + * are copied ONLY when they do not exist yet in $dst — used for + * files/preview.svg: added to a variant once, at first creation, and never + * overwritten afterwards, because the user may have edited it (row 235). + */ +function copyDirRecursive(string $src, string $dst, array $neverOverwrite = [], string $prefix = ''): void { if (!is_dir($dst)) { mkdir($dst, 0775, true); @@ -128,8 +143,12 @@ function copyDirRecursive(string $src, string $dst): void $s = $src . DIRECTORY_SEPARATOR . $entry; $d = $dst . DIRECTORY_SEPARATOR . $entry; if (is_dir($s)) { - copyDirRecursive($s, $d); + copyDirRecursive($s, $d, $neverOverwrite, $prefix . $entry . '/'); } else { + $rel = $prefix . $entry; // relative to the top-level $src, '/' separators + if (in_array($rel, $neverOverwrite, true) && file_exists($d)) { + continue; // first-creation-only file already present: never overwrite + } copy($s, $d); } } @@ -352,11 +371,43 @@ $doc->save($out); // folder is copied into the generated theme, so a client-specific font or css is // part of the variant by default (no manual copying needed). $variantAssets = rtrim($definitionsDir, '/\\') . DIRECTORY_SEPARATOR . $variantName; +// Row 235: files/preview.svg is added to a variant only at FIRST creation and is +// never overwritten afterwards (the user may have edited it in the variant), so +// it is passed in $neverOverwrite. Everything else is overwritten as before. +$neverOverwrite = ['files/preview.svg']; if (is_dir($variantAssets)) { - copyDirRecursive($variantAssets, $variantDir); + copyDirRecursive($variantAssets, $variantDir, $neverOverwrite); echo "Copied variant assets: $variantAssets -> $variantDir\n"; } +// --- row 235: seed files/preview.svg at first creation only --- +// The variant's preview must DIFFER from the mother's (standing rule), so the +// developer defines a variant-specific preview.svg (editable source of +// files/preview.png) in //files/. If neither the +// definitions dir nor the variant itself has one yet (first creation), seed it +// from the mother's files/preview.svg as a starting point to edit. +$variantPreviewSvg = $variantDir . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR . 'preview.svg'; +if (!is_file($variantPreviewSvg)) { + $motherPreviewSvg = $motherDir . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR . 'preview.svg'; + if (is_file($motherPreviewSvg)) { + if (!is_dir(dirname($variantPreviewSvg))) { + mkdir(dirname($variantPreviewSvg), 0775, true); + } + copy($motherPreviewSvg, $variantPreviewSvg); + echo "Seeded files/preview.svg from the mother (first creation) — EDIT IT so the variant preview differs from vanilla_respondage, then export files/preview.png\n"; + } else { + fwrite(STDERR, "NOTE: no files/preview.svg found for this variant (neither in $variantAssets nor in the mother). Create one and export files/preview.png — the variant preview must differ from the mother's (row 235).\n"); + } +} + +// --- row 235 standing rule: a variant preview must differ from the mother's --- +$variantPreviewPng = $variantDir . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR . 'preview.png'; +$motherPreviewPng = $motherDir . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR . 'preview.png'; +if (is_file($variantPreviewPng) && is_file($motherPreviewPng) + && md5_file($variantPreviewPng) === md5_file($motherPreviewPng)) { + fwrite(STDERR, "WARNING: $variantName files/preview.png is IDENTICAL to the mother's — standing rule (row 235): each variant must have its own preview. Define files/preview.svg in the definitions dir, edit it, export files/preview.png.\n"); +} + // --- footer override: variants show NO Respondage theme footer to respondents --- // The mother's views/subviews/footer/footer.twig renders a "proudly developed by // Respondage" credit; in a variant that must not appear (the Respondage footer on @@ -376,7 +427,8 @@ if (!is_file($variantFooterFile)) { echo "Variant '$variantName' built: $out\n"; echo 'Options overridden: ' . (empty($definition['options']) ? '(none)' : implode(', ', array_keys($definition['options']))) . "\n"; -echo "Note: existing files in $variantDir were OVERWRITTEN from the definitions dir.\n"; +echo "Note: existing files in $variantDir were OVERWRITTEN from the definitions dir,\n"; +echo " EXCEPT files/preview.svg: added only at first creation, never overwritten (row 235).\n"; echo "REBUILD RULE: re-run this build after EVERY change to $variantName.json or to the\n"; echo " /$variantName/ assets — a variant folder that is not rebuilt after\n"; echo " a definitions change is stale (fonts/logo/css then don't match the definitions).\n";