From dd8714b6a02a95089d76070db35f33f7a20d7700 Mon Sep 17 00:00:00 2001 From: Tammo ter Hark Date: Mon, 16 Nov 2026 21:09:02 +0100 Subject: [PATCH] feat(variants): copy per-client assets (fonts/css/images) automatically in build.php The definitions dir (private variants repo) now has a standard layout per client: .json + /files/... + /css/variant.css. build.php copies / into the generated theme folder, so a client-specific font or css is part of the variant by default. README updated accordingly. Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe --- README.md | 14 ++++++++++---- variants/build.php | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 877713a..b529ff4 100644 --- a/README.md +++ b/README.md @@ -48,9 +48,13 @@ LimeSurvey only knows its core font packages (`application/config/fonts.php`), so a theme cannot register a `font-*` package itself. Instead a variant ships its own font files and css: -1. Put the font files in the variant's `files/fonts/` (e.g. `my-custom-font.woff2`). -2. Create `css/variant.css` in the variant with the `@font-face` and the body - class rule (the selected font is applied as `font-` on ``): +1. Put the font files in the client folder of the PRIVATE variants repo: + `_vanilla/files/fonts/` (e.g. `my-custom-font.woff2`). This folder + is standard per client and is copied into the generated theme automatically + by `build.php` (together with e.g. `files/*.png` logos and `css/variant.css`). +2. Create `css/variant.css` in that same client folder with the `@font-face` + and the body class rule (the selected font is applied as `font-` on + ``): ```css @font-face { font-family: 'My Custom Font'; @@ -73,7 +77,9 @@ its own font files and css: "Custom (this theme)" optgroup of the font dropdown (`data-font-package` stays `websafe`, so no nonexistent package is requested — the real font is loaded by the variant's own css). -4. Run `php variants/build.php ` and upload/reset as usual. +4. Run `php variants/build.php ` (or set + RESPONDAGE_VARIANTS_DIR) and upload/reset as usual. The `/` assets + folder from the definitions dir is copied into `..//` automatically. ## Client variants (house styles) without code duplication diff --git a/variants/build.php b/variants/build.php index 145697e..f5e9ab3 100644 --- a/variants/build.php +++ b/variants/build.php @@ -28,6 +28,12 @@ * point this script at that folder via the optional second argument or the * RESPONDAGE_VARIANTS_DIR environment variable. * + * Standard layout in that definitions dir per client: + * .json house-style option values + fontOptions + files_add + * /files/... client assets (logos, fonts in files/fonts/) + * /css/... client css (e.g. css/variant.css with @font-face) + * The / folder is copied into the generated theme automatically. + * * Example: * php variants/build.php /path/to/private-variants * @@ -103,6 +109,28 @@ 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 +{ + if (!is_dir($dst)) { + mkdir($dst, 0775, true); + } + $dir = opendir($src); + while (($entry = readdir($dir)) !== false) { + if ($entry === '.' || $entry === '..') { + continue; + } + $s = $src . DIRECTORY_SEPARATOR . $entry; + $d = $dst . DIRECTORY_SEPARATOR . $entry; + if (is_dir($s)) { + copyDirRecursive($s, $d); + } else { + copy($s, $d); + } + } + closedir($dir); +} + setMetadata($xpath, $doc, 'name', $definition['name'] ?? $variantName); setMetadata($xpath, $doc, 'title', $definition['title'] ?? ucfirst($variantName)); if (isset($definition['description'])) { @@ -221,6 +249,17 @@ if (!is_dir($variantDir . DIRECTORY_SEPARATOR . 'files')) { $out = $variantDir . DIRECTORY_SEPARATOR . 'config.xml'; $doc->save($out); +// --- copy the variant's own assets (fonts, css, images) from the definitions dir --- +// Standard layout in the private variants repo: // +// with e.g. files/fonts/*.woff2, files/*.png, css/variant.css. Everything in that +// 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; +if (is_dir($variantAssets)) { + copyDirRecursive($variantAssets, $variantDir); + echo "Copied variant assets: $variantAssets -> $variantDir\n"; +} + echo "Variant '$variantName' built: $out\n"; echo 'Options overridden: ' . (empty($definition['options']) ? '(none)' : implode(', ', array_keys($definition['options']))) . "\n"; echo "Remember: upload the folder to upload/themes/survey/ and reset the theme in LimeSurvey.\n";