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_themespermission. - archive
- A theme as a zip:
theme.yaml,settings.jsonwhen 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§
- Edit
Theme - 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.
- Theme
Config - A theme’s config: the YAML an operator edits, parsed on every save.
- Theme
Module - The theme module: its tables migrate with the application’s, and it
registers the Themes screen under
web.manage_themes. - Theme
Settings - The site’s theme settings: which theme is active.
Enums§
- Kind
- What a template is to the site.
- Theme
Error - What the theme store can refuse or fail on.
Constants§
- RESERVED_
KEYS - The keys of the
themevalue 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
codethe site’s theme. The theme must exist. - set_
edit_ theme - Sets, or with
Noneclears, 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.