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: <client>.json + <client>/files/... + <client>/css/variant.css. build.php copies <client>/ 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 <vibe@mistral.ai>
This commit is contained in:
parent
d22abc8745
commit
dd8714b6a0
2 changed files with 49 additions and 4 deletions
14
README.md
14
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
|
so a theme cannot register a `font-*` package itself. Instead a variant ships
|
||||||
its own font files and css:
|
its own font files and css:
|
||||||
|
|
||||||
1. Put the font files in the variant's `files/fonts/` (e.g. `my-custom-font.woff2`).
|
1. Put the font files in the client folder of the PRIVATE variants repo:
|
||||||
2. Create `css/variant.css` in the variant with the `@font-face` and the body
|
`<client>_vanilla/files/fonts/` (e.g. `my-custom-font.woff2`). This folder
|
||||||
class rule (the selected font is applied as `font-<value>` on `<body>`):
|
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-<value>` on
|
||||||
|
`<body>`):
|
||||||
```css
|
```css
|
||||||
@font-face {
|
@font-face {
|
||||||
font-family: 'My Custom Font';
|
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`
|
"Custom (this theme)" optgroup of the font dropdown (`data-font-package`
|
||||||
stays `websafe`, so no nonexistent package is requested — the real font is
|
stays `websafe`, so no nonexistent package is requested — the real font is
|
||||||
loaded by the variant's own css).
|
loaded by the variant's own css).
|
||||||
4. Run `php variants/build.php <client>` and upload/reset as usual.
|
4. Run `php variants/build.php <client> <definitions-dir>` (or set
|
||||||
|
RESPONDAGE_VARIANTS_DIR) and upload/reset as usual. The `<client>/` assets
|
||||||
|
folder from the definitions dir is copied into `../<client>/` automatically.
|
||||||
|
|
||||||
## Client variants (house styles) without code duplication
|
## Client variants (house styles) without code duplication
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,12 @@
|
||||||
* point this script at that folder via the optional second argument or the
|
* point this script at that folder via the optional second argument or the
|
||||||
* RESPONDAGE_VARIANTS_DIR environment variable.
|
* RESPONDAGE_VARIANTS_DIR environment variable.
|
||||||
*
|
*
|
||||||
|
* Standard layout in that definitions dir per client:
|
||||||
|
* <variantName>.json house-style option values + fontOptions + files_add
|
||||||
|
* <variantName>/files/... client assets (logos, fonts in files/fonts/)
|
||||||
|
* <variantName>/css/... client css (e.g. css/variant.css with @font-face)
|
||||||
|
* The <variantName>/ folder is copied into the generated theme automatically.
|
||||||
|
*
|
||||||
* Example:
|
* Example:
|
||||||
* php variants/build.php <client> /path/to/private-variants
|
* php variants/build.php <client> /path/to/private-variants
|
||||||
*
|
*
|
||||||
|
|
@ -103,6 +109,28 @@ function setMetadata(DOMXPath $xpath, DOMDocument $doc, string $tag, string $val
|
||||||
$node->textContent = $value;
|
$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, 'name', $definition['name'] ?? $variantName);
|
||||||
setMetadata($xpath, $doc, 'title', $definition['title'] ?? ucfirst($variantName));
|
setMetadata($xpath, $doc, 'title', $definition['title'] ?? ucfirst($variantName));
|
||||||
if (isset($definition['description'])) {
|
if (isset($definition['description'])) {
|
||||||
|
|
@ -221,6 +249,17 @@ if (!is_dir($variantDir . DIRECTORY_SEPARATOR . 'files')) {
|
||||||
$out = $variantDir . DIRECTORY_SEPARATOR . 'config.xml';
|
$out = $variantDir . DIRECTORY_SEPARATOR . 'config.xml';
|
||||||
$doc->save($out);
|
$doc->save($out);
|
||||||
|
|
||||||
|
// --- copy the variant's own assets (fonts, css, images) from the definitions dir ---
|
||||||
|
// Standard layout in the private variants repo: <definitionsDir>/<variantName>/
|
||||||
|
// 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 "Variant '$variantName' built: $out\n";
|
||||||
echo 'Options overridden: ' . (empty($definition['options']) ? '(none)' : implode(', ', array_keys($definition['options']))) . "\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";
|
echo "Remember: upload the folder to upload/themes/survey/ and reset the theme in LimeSurvey.\n";
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue