Skip to main content

tablo/
lib.rs

1//! Tablo — an admin toolkit for Rust, server-rendered on Topcoat and persisted
2//! with Toasty.
3//!
4//! This crate is the one Tablo dependency an app names, beside `topcoat` and
5//! `toasty` at the versions Tablo uses:
6#![doc = concat!(
7    "```toml\n",
8    "[dependencies]\n",
9    "tablo = { version = \"", env!("CARGO_PKG_VERSION"), "\", features = [\"sqlite\"] }\n",
10    "```\n",
11)]
12//!
13//! It re-exports [`tablo_core`] at its root, the UI components as [`ui`], the
14//! in-memory HTTP client as `testing` with the `testing` feature, the audit log
15//! as `audit` with the `audit` feature, and the durable job queue as `jobs` with the `jobs`
16//! feature; the driver
17//! features (`sqlite`, `postgresql`, `mysql`, `turso`) turn on Toasty's driver of the same
18//! name, and the toolkit itself enables none. The `rust_decimal` and `bigdecimal` features make
19//! those crates' decimal types typed values and numeric amounts, and turn on Toasty's feature of
20//! the same name. Two features are on by default: `rich-text`, the rich text field and column, and
21//! `two-factor`, [`Auth::two_factor`] and its `AuthFactor` model. A panel that never asks for a
22//! second factor, such as one on [`Auth::external`], turns `two-factor` off and drops its cipher,
23//! QR code and one-time code crates.
24//!
25//! A minimal app is one model, the record form [`ModelForm`](derive@ModelForm)
26//! derives from it, one [`Resource`], and the [`Panel`] that serves it — the
27//! full version lives in `examples/quickstart`:
28//!
29//! ```rust
30//! # use tablo::prelude::*;
31//! #[derive(Debug, Clone, toasty::Model, tablo::PanelModel, tablo::ModelForm)]
32//! pub struct Book {
33//!     #[key]
34//!     #[auto]
35//!     pub id: uuid::Uuid,
36//!     pub title: String,
37//! }
38//!
39//! pub struct BookResource;
40//!
41//! impl Resource for BookResource {
42//!     type Model = Book;
43//!     type Form = BookForm;
44//!
45//!     fn declare() -> ResourceDef<Self> {
46//!         ResourceDef::new().policy(Allow)
47//!     }
48//! }
49//! ```
50//!
51//! Mounting serves it on the app's router:
52//!
53//! ```rust,no_run
54//! # use tablo::prelude::*;
55//! # use topcoat::router::{Router, RouterBuilderDiscoverExt};
56//! # #[derive(Debug, Clone, toasty::Model, tablo::PanelModel, tablo::ModelForm)]
57//! # pub struct Book {
58//! #     #[key]
59//! #     #[auto]
60//! #     pub id: uuid::Uuid,
61//! #     pub title: String,
62//! # }
63//! # pub struct BookResource;
64//! # impl Resource for BookResource {
65//! #     type Model = Book;
66//! #     type Form = BookForm;
67//! # }
68//! # fn main() -> topcoat::Result<()> {
69//! # let db: toasty::Db = todo!();
70//! let mut builder = Router::builder().discover().with(db);
71//! builder.panel(Panel::new("admin").resource::<BookResource>())?;
72//! let router = builder.build();
73//! # let _ = router;
74//! # Ok(())
75//! # }
76//! ```
77//!
78//! The user guide starts at "Your first panel".
79
80#[cfg(feature = "audit")]
81pub use tablo_audit as audit;
82pub use tablo_core::*;
83#[cfg(feature = "jobs")]
84pub use tablo_jobs as jobs;
85#[cfg(feature = "testing")]
86pub use tablo_test as testing;
87pub use tablo_ui as ui;
88
89/// The items a resource module names most: `use tablo::prelude::*;`.
90pub mod prelude {
91    pub use tablo_core::{
92        Abilities, Ability, Action, ActionDef, ActionLayout, Alignment, Allow, Area, Auth,
93        BooleanColumn, Brand, Change, Chart, ChoiceField, Color, ColorColumn, ColumnWidth,
94        ComputedColumn, CountColumn, Currency, CustomField, DateColumn, DateFilter, DateValue,
95        Deny, Detail, EmbeddedColumn, EmbeddedForm, Environment, Field, FieldAccess, FieldErrors,
96        FileColumn, FileField, FontWeight, FormInput, FormValues, GlobalSearch, Grid, Group,
97        HeaderAction, HeaderActionDef, HeaderActions, IconColumn, ImageColumn, IntoOptions, Lens,
98        ListTab, Look, ModelForm, NavigationItem, NoForm, NumberFilter, Options, Outcome, Page,
99        PageDef, PageFilter, PageFilters, Pagination, Panel, PanelModel, Places, Policy, Posted,
100        PresenceFilter, PublicLink, QueryFilter, Radius, ReadOnly, Reads, RecordForm, RecordPage,
101        RecordPageDef, RecordTable, Relation, RelationColumn, RepeaterColumn, Resource,
102        ResourceDef, ResourcePage, RouterBuilderPanelExt, RowLink, Schema, Section, SelectColumn,
103        SelectFilter, Series, SidebarFrame, Sort, Stat, Step, Submits, Summary, Tab, Table, Tabs,
104        Tenancy, TenantId, TernaryFilter, Text, TextColumn, TextField, TextFilter, TextInputColumn,
105        TextMatch, Theme, Toggle, ToggleColumn, Trend, Widget, WidgetDef, Wizard, WriteError, can,
106        can_list, can_open, can_view_field, filter_keys, lens, list_query, page_filters, relation,
107        scoped_query, t, tenant_id, text, when,
108    };
109    #[cfg(feature = "rich-text")]
110    pub use tablo_core::{RichTextColumn, RichTextField, Tool};
111}