diff --git a/README.md b/README.md index 3ed2fbe..8100418 100644 --- a/README.md +++ b/README.md @@ -351,28 +351,33 @@ its own font files and css: House-style-specific values are ONLY: colors, fonts, and font sizes/colors/weights (plus logo files). Everything else lives once, here. -### Theme preview image per variant (`files/preview.png`) +### Theme preview image per variant (`files/preview.png` + `files/preview.svg`) The theme list shows `files/preview.png` of each theme (hard-coded in core, -`TemplateConfiguration::getPreview()` — `preview.svg` is NOT picked up; a feature -request for SVG support and starter-theme fallback has been prepared for the -LimeSurvey developers). The preview is read -from the theme's OWN files folder — there is no starter-theme fallback — so every -variant should ship its own `files/preview.png`: put it in -`/files/preview.png` in the private variants repo; `build.php` copies -the whole `/` asset folder into the generated variant automatically. -A variant without its own preview shows "No preview available" in the theme -list. +`TemplateConfiguration::getPreview()` — `preview.svg` is NOT picked up by core; +a feature request for SVG support has been prepared for the LimeSurvey +developers). The preview is read from the theme's OWN files folder — there is no +starter-theme fallback — so every variant must ship its own +`files/preview.png`. Standing rule: **a variant's preview must differ from the +mother theme's** — when defining a variant, create a variant-specific +`files/preview.svg` (the editable source, committed and synced publicly) and +export `files/preview.png` from it (Inkscape → PNG export). `build.php` adds +`files/preview.svg` to a variant only ONCE, at first creation (seeded from the +mother if the definitions dir has none), and NEVER overwrites it afterwards — +after that you edit it in the variant folder. `build.php` prints a WARNING when +the variant's `preview.png` is identical to the mother's. -Workflow: +### Build process (defining a NEW variant) 1. In `config.xml`, the house-style options are marked with `HOUSE-STYLE` comments (colors, fonts, font sizes/weights, logo files, logo top margin, background image/color). Only those values belong in a variant json — never hardcode house-style values in shared files (`views/`, `css/`, `scripts/`), because those are inherited by all variants. -2. Create `variants/.json` with the variant name/title/description and - only the house-style option keys with the client values: +2. In the private variants repo, create `variants/.json` with the + variant name/title/description and only the house-style option keys with the + client values, plus a `/` asset folder (logos, `files/fonts/`, + `css/variant.css`, `files/preview.svg`/`preview.png`): ```json { "name": "respondage_client", @@ -380,7 +385,7 @@ Workflow: "options": { "primarycolor": "#123456", "fontsize": "18px" } } ``` -2. Run `php variants/build.php `. This generates +3. Run `php variants/build.php `. This generates `..//config.xml`: a copy of this theme's config.xml with only those option values replaced, `` set to this theme, and the `` section emptied except `` (same as LimeSurvey's own "extend @@ -388,25 +393,36 @@ Workflow: kept: LimeSurvey resolves each listed file in the variant first and then in the starter theme, so the starter theme's css/js keep loading until a variant ships its own file with the same name. Unknown option keys make the build fail - loudly, so drift is caught at build time. -3. The `/` assets (logos, `files/fonts/`, `css/variant.css`, - `files/preview.png`) from the definitions dir are copied into `..//` - automatically — every build OVERWRITES existing files there, so never edit the - generated folder by hand. Upload the folder to `upload/themes/survey/` and - install/reset the theme in LimeSurvey, then FLUSH the LimeSurvey asset cache and - hard-refresh the browser (Ctrl+F5) — after a rebuild the asset hash changes, and a - stale cached css is exactly how an old placeholder font keeps showing. - REBUILD RULE: after every change to `.json` or `/` in the - private definitions repo, re-run `php variants/build.php ` and reset - the variant theme in LimeSurvey — a variant folder that is not rebuilt after - a definitions change is stale (fonts/logo/css then don't match, e.g. an old - placeholder `css/variant.css` keeps loading instead of the client font). - IMPORTANT: a variant only works when the starter theme `vanilla_respondage` - is also present in `upload/themes/survey/` on the server — the variant - extends it and inherits all views/css/js/options from it. The core theme - `vanilla` (which this starter theme extends) ships with LimeSurvey itself, - so that one is always there. So deploy: `vanilla_respondage` + each - `respondage_` you use. + loudly, so drift is caught at build time. The whole `/` asset folder + is copied into `..//` automatically. +4. Deploy and activate: upload `..//` to `upload/themes/survey/` (the + mother theme `vanilla_respondage` must be present there too — the variant + extends it; the core theme `vanilla` ships with LimeSurvey itself), then + install/reset the variant theme in the LimeSurvey admin (Theme options → + `` → Reset, which imports the new config.xml into the DB), FLUSH the + asset cache (`php application/commands/console.php flushassets`) and + hard-refresh the browser (Ctrl+F5) — a stale cached css is exactly how an + old placeholder font keeps showing. + +### Rebuild process (after a change in THIS mother theme or in a definitions file) + +- Views/css/js changes in this theme apply to all variants immediately via + `` — no rebuild needed (but do flush assets + Ctrl+F5 on the server). +- After a `config.xml` change (new/renamed options) or a change to a + `.json` / `/` in the definitions repo, rebuild ALL variants + in one go: + ``` + bash variants/build_all.sh + ``` + (`` defaults to `variants/` or `$RESPONDAGE_VARIANTS_DIR`; + set `PHP_BIN=/path/to/php` if `php` is not on PATH.) It loops over every + `*.json` in the definitions dir, calls `build.php` per variant, and fails + non-zero if any variant fails. Then, per rebuilt variant: reset the theme in + the LimeSurvey admin (Theme options → Reset), flush assets, Ctrl+F5. + Never edit the generated `..//` folder by hand — every build + OVERWRITES its files from the definitions dir, EXCEPT `files/preview.svg` + (first-creation-only, see above). A variant folder that is not rebuilt after + a definitions change is stale (fonts/logo/css then don't match). Because of the native `` mechanism: - changes to any file (twig/css/js) in this starter theme apply to all diff --git a/variants/build_all.sh b/variants/build_all.sh new file mode 100644 index 0000000..fa6a6ce --- /dev/null +++ b/variants/build_all.sh @@ -0,0 +1,75 @@ +#!/usr/bin/env bash +# --------------------------------------------------------------------------- +# REBUILD process: rebuild ALL variants of this theme from their json +# definitions in one go (see README.md, "Client variants (house styles)"). +# +# Usage: +# bash variants/build_all.sh [definitions-dir] +# +# definitions-dir defaults to the variants/ folder next to this script, or to +# $RESPONDAGE_VARIANTS_DIR (the private variants repository, which holds the +# confidential .json files and / asset folders). Every +# .json in that dir is built with variants/build.php . +# +# Environment: +# PHP_BIN php binary to use (default: "php"; e.g. PHP_BIN=/usr/bin/php) +# +# Per-variant rules enforced by build.php itself: +# - unknown option keys fail the build loudly (drift check); +# - files/preview.svg is added only at FIRST creation and never overwritten +# (row 235) — edit it in the variant, not here; +# - a WARNING is printed when the variant's preview.png is identical to the +# mother's (standing rule: each variant has its own preview). +# +# After a successful run, the OWNER actions in the LimeSurvey admin UI are: +# 1. reset every rebuilt variant theme (Theme options -> -> Reset), +# so the new config.xml is imported into lime_template_configuration; +# 2. flush the asset cache: php application/commands/console.php flushassets +# (or the button in the admin UI); +# 3. hard-refresh the browser (Ctrl+F5). +# --------------------------------------------------------------------------- +set -u + +HERE="$(cd "$(dirname "$0")" && pwd)" +DEFS="${1:-${RESPONDAGE_VARIANTS_DIR:-$HERE}}" +PHP_BIN="${PHP_BIN:-php}" + +if [ ! -d "$DEFS" ]; then + echo "ERROR: definitions dir not found: $DEFS" >&2 + echo "Usage: bash variants/build_all.sh [definitions-dir]" >&2 + exit 1 +fi + +shopt -s nullglob +jsons=("$DEFS"/*.json) +if [ ${#jsons[@]} -eq 0 ]; then + echo "ERROR: no *.json variant definitions found in $DEFS" >&2 + exit 1 +fi + +built=0 +failed=0 +for json in "${jsons[@]}"; do + name="$(basename "$json" .json)" + echo "==================================================================" + echo "=== building variant: $name (from $json)" + echo "==================================================================" + if "$PHP_BIN" "$HERE/build.php" "$name" "$DEFS"; then + built=$((built + 1)) + else + failed=$((failed + 1)) + echo "!!! BUILD FAILED: $name (see output above)" >&2 + fi +done + +echo "==================================================================" +echo "Rebuild summary: $built built, $failed failed (definitions dir: $DEFS)" +if [ "$failed" -gt 0 ]; then + echo "Fix the failing definitions and re-run this script." >&2 + exit 1 +fi +echo +echo "Next — owner actions in the LimeSurvey admin UI:" +echo " 1. reset every rebuilt variant theme (Theme options -> -> Reset)" +echo " 2. flush the asset cache (php application/commands/console.php flushassets)" +echo " 3. hard-refresh the browser (Ctrl+F5)"