Crate teensy_cms

Crate teensy_cms 

Source
Expand description

TeensyCMS is the smallest CMS possible that allows admins running your application to add custom pages that are accessible from a nav bar.

An implementation of TeensyCMS with actix-web can be found in the source code’s example directory.

use teensy_cms::{TeensyCms, DefaultPage};

let my_config = MyConfig::from_env();
let cms = TeensyCms::<DefaultPage>::from_config_path(
    "/page",
    &my_config.pages_config_path
).unwrap();

/* -- server initialization here -- */

fn handle_page_request(req: Request) -> String {
    // something like "contact" or "about"
    let page = &req.path_args()["page"];
    req.data::<TeensyCms<DefaultPage>>().unwrap()
        .render(&format!("{page}.html")).unwrap()
}

Pages use YAML frontmatter followed by HTML. The frontmatter MUST be delimited by --- both before and after. Only a single YAML document is permitted in the frontmatter.

---
title: My Page
cats: [Scruffles, Mx. Clawz]
---
<h1>{{ page.title }}</h1>
<ul>
  {% for cat in page.cats %}
    <li>{{ cat }}</li>
  {% endfor %}
</ul>

Structs§

Config
Configuration for the application.
DefaultPage
A struct that collects all values and makes them available to the page or templates.
Menu
Contains the nested menu items after loading all pages.
TeensyCms
The main CMS struct.

Enums§

Error
Error type
MenuItem
A menu item.
MenuItemConfig
Configurations for menu items.
Visibility
Enum for a page’s visiblity in menus.

Traits§

Page
Trait for a page’s frontmatter that loaded from a template.

Type Aliases§

Result
Wrapper type of std::result::Result with Err as Error.