feat: per-tenant theming via runtime CSS-variable injection#1707
Merged
Conversation
Closes #1704. Adds a small framework primitive so multi-tenant apps stop reinventing the same per-tenant color-theming wiring: - ``vibetuner.models.TenantTheme`` — embedded pydantic model with eight optional ``#rrggbb`` fields for the four DaisyUI role colors and their ``*-content`` foreground variants. ``.overrides()`` returns the ``{css_var: hex}`` map. - ``vibetuner.register_tenant_theme_provider(getter)`` — opt-in helper that wraps a synchronous tenant getter and exposes ``theme_overrides`` in the template context. Fail-soft: getter / type errors log and render with no overrides. - ``base/theme.html.jinja`` — shipped partial that emits a CSP-noncified ``<style>:root { ... }</style>`` block when ``theme_overrides`` is non-empty. Wired into ``base/skeleton.html.jinja`` between the ``bundle.css`` link and ``{% block head %}``. - Docs: new ``theming.md`` page (added to the User Guide nav), feature entry in ``llms.txt``, detailed section in ``llms-full.txt`` covering the cascade ordering, footguns, and the per-tenant fonts carve-out (#1705). ``bundle.css`` stays tenant-agnostic and cached; theming happens at request time in HTML, not via per-tenant CSS rebuilds. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
davidpoblador
pushed a commit
that referenced
this pull request
Apr 28, 2026
🤖 I have created a release *beep* *boop* --- ## [10.6.0](v10.5.0...v10.6.0) (2026-04-28) ### Features * enforce CSP in debug by default with opt-out flag ([#1702](#1702)) ([2d939ea](2d939ea)) * per-tenant theming via runtime CSS-variable injection ([#1707](#1707)) ([6a44e6c](6a44e6c)) ### Miscellaneous Chores * add `vibetuner core-templates-path` CLI for setup-tw-sources ([#1708](#1708)) ([b095d32](b095d32)) * **deps:** bump gitpython from 3.1.46 to 3.1.47 ([#1689](#1689)) ([b44149d](b44149d)) * **deps:** bump gitpython from 3.1.46 to 3.1.47 in /vibetuner-py ([#1688](#1688)) ([14aaf96](14aaf96)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1704.
Summary
vibetuner.models.TenantThemewith eight optional#rrggbbfields for DaisyUI role / role-content colors plus.overrides()→{css_var: hex}.vibetuner.register_tenant_theme_provider(getter, *, attribute="theme")that registers a context provider exposingtheme_overridesper request. Fail-soft: getter/type errors log and render with no overrides.base/theme.html.jinjathat emits a CSP-noncified<style>:root { ... }</style>only whentheme_overridesis non-empty. Wired intobase/skeleton.html.jinjabetween thebundle.csslink and{% block head %}.theming.mdpage (added to User Guide nav), feature entry inllms.txt, detailed section inllms-full.txtcovering cascade ordering, the two color footguns (build-time literals in custom tokens, hardcoded scale shades), and the per-tenant fonts carve-out (feat: per-tenant fonts via curated @font-face catalogue #1705).bundle.cssstays tenant-agnostic and cached; theming happens at request time in HTML — no per-tenant CSS rebuilds.Backwards compatibility
register_tenant_theme_provider(...). Apps that don't multi-tenant pay zero overhead.theme: TenantTheme = Field(default_factory=TenantTheme)to an existing tenant document is a no-op for already-persisted records (MongoDB is schema-on-read;keep_nulls=Falsekeeps unset fields out of the database).base/skeleton.html.jinjanow includesbase/theme.html.jinja, which renders nothing whentheme_overridesis empty — apps that haven't registered a provider see no extra markup.Test plan
uv run python -m pytest tests/(full suite, 717 passed)uv run python -m pytest tests/unit/test_tenant_theme.py(22 new tests covering the model validator, the provider helper, the rendered partial output, and HTML-escape defenses)just format && just lint && just type-checkclean🤖 Generated with Claude Code