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::variant;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. - build
- A theme rendered to files: every page whose URL has no parameter, at its URL, through the same render path the site serves, plus the theme’s text assets. The output is a plain directory for any static host.
- component
- Components: compiled units a page or layout attaches, each producing data a template reads under the alias it was attached as.
- engine
- Rendering: a theme’s templates compiled into one environment.
- maintenance
- Maintenance mode: the site answers every visitor with the theme’s
/maintenancepage, or a plain notice, with status 503, while an operator with the themes permission still sees the site. - markup
- Markup a module adds to every theme engine: functions, filters, tests and globals installed into the environment before the templates compile.
- page
- A page’s settings: its URL pattern, its layout and its meta fields.
- router
- Page URLs as patterns, matched against a request’s path and built back from a page and its parameters.
- site
- The public site: every URL the admin and the other public routes leave, served from the active theme’s pages.
- 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.
- media_
value - A media record as a template sees it: what a component hands over so
media(file),media(file, preset="card")andfile.url|variant("card")work, besidetitle,alt,width,height,kindandname. - 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.