Skip to main content

Module theme

Module theme 

Source
Expand description

Themes: the public site’s templates, stored as rows and edited from the admin.

A theme is a code, a YAML config (ThemeConfig) and a set of templates (Template), each a kind (Kind), a path, a settings bag and markup. A theme may name a parent; a path its own rows lack is looked up through the parent chain (store::resolve_template). One theme is active for the site (ThemeSettings); an operator may hold a different one to edit and preview (EditTheme). Every save of a template keeps what it replaced as a Revision, so an edit can be undone.

Register ThemeModule with the bootstrap and its tables migrate with the application’s.

use laterite_web::theme::{self, Kind, ThemeModule};
let site = theme::store::create_theme(&db, "acme", "name: Acme\nauthor: Acme\n").await?;
theme::store::save_template(&db, site.id, Kind::Layout, "default.htm", None, "<html>{% block body %}{% endblock %}</html>", None).await?;
theme::set_active_theme(&db, "acme").await?;

Re-exports§

pub use engine::check;
pub use engine::Engine;
pub use engine::EngineCache;
pub use engine::RenderError;

Modules§

admin
The Themes screen: every theme, its config and its templates, edited from the admin under the web.manage_themes permission.
archive
A theme as a zip: theme.yaml, settings.json when the theme has values, and one file per template under its kind’s folder (layouts/default.htm, pages/home.htm, partials/nav.htm, content/intro.md, assets/css/site.css). A template with settings carries them as YAML above a == line, the markup below it; one without is the markup alone.
engine
Rendering: a theme’s templates compiled into one environment.
store
Queries over the theme tables.

Structs§

EditTheme
An operator’s own choice of theme to edit and preview.
Revision
What a template held before a save replaced it.
Template
A template row.
Theme
A theme row, with its config parsed.
ThemeConfig
A theme’s config: the YAML an operator edits, parsed on every save.
ThemeModule
The theme module: its tables migrate with the application’s, and it registers the Themes screen under web.manage_themes.
ThemeSettings
The site’s theme settings: which theme is active.

Enums§

Kind
What a template is to the site.
ThemeError
What the theme store can refuse or fail on.

Constants§

RESERVED_KEYS
The keys of the theme value a template reads that belong to the theme itself; a settings field cannot take one.

Functions§

active_theme
The active theme, or none when no theme is set or the set one is gone.
edit_theme
The theme an operator edits: their own choice when it still exists, else the active theme.
set_active_theme
Makes code the site’s theme. The theme must exist.
set_edit_theme
Sets, or with None clears, the theme an operator edits.
valid_code
A theme code: lowercase letters, digits and hyphens, starting with a letter or digit, at most 64 characters.
valid_path
A template path: /-separated segments of lowercase letters, digits, dots, hyphens and underscores, no empty, . or .. segment, at most 255 characters.