# Lumina Theming The web client of Lumina is a themed shell: every page is rendered inside the templates of an active theme. A theme is a self contained ZIP archive with a manifest, HTML templates and static assets. This document explains how themes are structured, how the template engine works, and how to create, install and manage a theme. - [Lumina Theming](#lumina-theming) - [Overview](#overview) - [Theme Pack Structure](#theme-pack-structure) - [The Manifest (theme.json)](#the-manifest-themejson) - [Pack Validation Rules](#pack-validation-rules) - [Templates](#templates) - [Template Syntax](#template-syntax) - [Expressions](#expressions) - [Safety Limits](#safety-limits) - [Template Resolution](#template-resolution) - [The Layout Template (shared/layout)](#the-layout-template-sharedlayout) - [The Navigation Template (shared/nav-menu)](#the-navigation-template-sharednav-menu) - [Page Templates](#page-templates) - [The Scripts Section](#the-scripts-section) - [Assets](#assets) - [Configuration Options](#configuration-options) - [Creating a Theme](#creating-a-theme) - [Installing a Theme](#installing-a-theme) - [Bundled Themes](#bundled-themes) - [Selecting the Current Theme](#selecting-the-current-theme) - [Managing Themes from the Administration Page](#managing-themes-from-the-administration-page) - [Security Notes](#security-notes) ## Overview The application stores installed themes on the API server and serves their templates and assets. The web client fetches the templates of the active theme and renders them locally with a small, non-executable Mustache-style template engine. Theme templates can interpolate values, iterate collections and test truthiness, but they cannot run code. Because the templates are HTML, a theme can restyle the whole application, rearrange the layout and navigation, and provide custom pages for the built-in routes. A theme cannot extend the functionality of the application: it only shapes how the existing pages look and are structured. ## Theme Pack Structure A theme pack is a directory that is shipped as a ZIP archive with `theme.json` at its root: ``` my-theme/ theme.json assets/ preview.svg site.css templates/ index.html shared/ layout.html nav-menu.html not-found.html library/ written-content-library/ book-library/ books/ index.html ``` Only three locations may exist inside a pack: - `theme.json`, the manifest, at the root of the archive. - `templates/`, holding the HTML templates. - `assets/`, holding any static file served to the browser (stylesheets, images, fonts, scripts). The bundled reference theme `editorial-paper` follows exactly this layout and is the best starting point when authoring a new theme. ## The Manifest (theme.json) The manifest is a JSON object describing the theme. The example below is the manifest of the bundled `editorial-paper` theme: ```json { "schemaVersion": 1, "id": "editorial-paper", "name": "Editorial Paper", "description": "A clean, readable proof of concept theme.", "author": "Lumina", "version": "1.4.0", "preview": "assets/preview.svg", "templates": { "default": "templates/index.html" } } ``` | Field | Required | Rule | | --- | --- | --- | | `schemaVersion` | yes | Must be `1`. | | `id` | yes | A lowercase kebab-case value, up to 64 characters, used to reference the theme. For example `editorial-paper` or `my-dark-theme`. | | `name` | yes | Display name, up to 80 characters. | | `description` | yes | Description of the theme, up to 300 characters. | | `author` | yes | Author of the theme, up to 80 characters. | | `version` | yes | Semantic version form, for example `1.0.0`. Up to 40 characters. | | `preview` | no | Path to a preview image, relative to the pack root and under `assets/`. Shown on the administration page. | | `templates` | no | An optional mapping from template key to a file under `templates/`, with up to 32 entries. Templates can also be provided as mirrored files under `templates/` without a manifest entry. | All text fields must be non-empty and must not contain control characters. Template keys follow the same lowercase kebab-case rule as the theme id and are at most 40 characters. Template paths are normalized and must point to an existing file under `templates/`. ## Pack Validation Rules A theme archive is validated on install: - `theme.json` must exist at the root of the archive and be at most 64 KB. - Only `theme.json`, files under `templates/` and files under `assets/` are allowed. Anything else makes the archive invalid. - Paths are normalized and any path that would escape the pack is rejected. - `theme.json` must contain a valid manifest object that satisfies the rules in the previous section. Installing a theme is an atomic operation: an invalid pack is rejected entirely and nothing is left behind. ## Templates Templates are rendered with the built-in template engine. The engine is intentionally small and safe: it parses Mustache-style tags and renders them against a model. It never executes arbitrary code. ### Template Syntax | Syntax | Meaning | | --- | --- | | `{{name}}` | Outputs the value of `name`, HTML-escaped. | | `{{{name}}}` | Outputs the value of `name` without escaping. | | `{{&name}}` | Outputs the value of `name` without escaping. | | `{{!comment}}` | A comment, produces no output. | | `{{#name}}...{{/name}}` | A section. Renders its children when the value is truthy. When the value is a collection, the children are rendered once per item. | | `{{^name}}...{{/name}}` | An inverted section. Renders its children when the value is falsy. | ### Expressions Expressions resolve against the model and support: - Dotted property paths, for example `{{user.name}}`. Dictionary keys and public properties are matched case-insensitively. - Parent traversal, for example `{{../title}}`, to reach values outside the current section scope. - The current value, for example `{{.}}`. - `{{#count}}` on a collection, where `Count` is exposed for collections. Values that do not exist resolve to an empty string for variables, or to falsy for sections. Truthiness follows these rules: `null`, `false`, empty strings and empty collections are falsy; everything else is truthy. ### Safety Limits The template engine enforces hard limits so a single theme cannot exhaust the server: | Limit | Value | | --- | --- | | Maximum section nesting depth | 32 levels | | Maximum expression length | 120 characters | | Maximum rendered output | 4 MB per page | A template that exceeds any of these limits is rejected with a template error and the page falls back to the application layout. ### Template Resolution Every themed page is identified by a page key that mirrors the path of the corresponding Razor view. When a page is rendered, its template is selected in this order: 1. An explicit mapping in `templates` when the manifest declares the page key. 2. A mirrored template file at `templates/{pageKey}.html`, walking up the scope of the path when the exact mirror does not exist. When neither an explicit mapping nor a mirrored file exists, the theme has no template for that page, and the application renders its own fallback unstylied Razor view instead. For example, the books index page has the page key `library/written-content-library/book-library/books/index`. The engine tries, in order: the explicit `templates` entry for that key, `templates/library/written-content-library/book-library/books/index.html`, then the parent scopes such as `templates/library/written-content-library/book-library/books.html`. When none exists, the application renders the books page view itself. Known page keys: | Page key | Purpose | | --- | --- | | `shared/layout` | The layout that wraps the shell of every page. | | `shared/nav-menu` | The navigation menu of the theme. | | `shared/not-found` | The 404 page. | | `library/written-content-library/book-library/books/index` | The books browsing page. | ### The Layout Template (shared/layout) Every page is rendered inside the layout template. The layout receives a model with the following fields: | Field | Content | | --- | --- | | `title` | The title of the page. | | `assetBase` | The base URL of the theme assets, for example `/theme-assets/editorial-paper/assets`. | | `appHead` | The head links of the application, such as its global stylesheets. | | `nav` | The fully rendered navigation menu HTML. | | `content` | The fully rendered content section of the page. | | `audioPlayer` | The rendered audio player when the user is authenticated, empty otherwise. | | `appScripts` | The global scripts of the application. | | `scripts` | The rendered script section of the page. | | `mainStyle` | An inline style for the main content area, `bottom: 0px;` when the user is not authenticated and empty otherwise. | The layout template of the bundled theme shows the intended shape: ```html
No title available.
{{/title}} {{#sections}}