pagetop/examples/intro-colors.rs
Manuel Cillero ab2677be44 ✨ (web): Exige el acceso de cada ruta al montarla
`configure_router()` recibe Routes, que no monta ninguna ruta sin su
Access: `route()`, `public_route()` y `admin_route()`, que toma el
permiso de la página del panel de la que cuelga.

Una ruta del panel montada de otra forma impide arrancar.

`configure_middleware()` recibe Layers y `configure_static_files()`
recibe StaticFiles, siempre públicos.
2026-11-07 13:52:04 +01:00

82 lines
3 KiB
Rust

use pagetop::prelude::*;
include_locales!(LOC from "examples/locale");
struct IntroColors;
#[async_trait]
impl Extension for IntroColors {
fn configure_router(&self, routes: Routes) -> Routes {
routes.public_route("/", web::get(intro_colors))
}
}
async fn intro_colors(request: HttpRequest) -> Result<Markup, ErrorPage> {
Page::new(request)
.with_child(
Intro::custom()
.with_title(Lc::n("PageTop"))
.with_slogan(Lc::t("colors_slogan", &LOC))
.with_child(
Block::new()
.with_title(Lc::t("colors_block", &LOC).with_arg("n", "1"))
.with_child(Html::with(|cx| {
html! {
p { (Lc::t("colors_val_1", &LOC).using(cx)) }
}
})),
)
.with_child(
Block::new()
.with_title(Lc::t("colors_block", &LOC).with_arg("n", "2"))
.with_child(Html::with(|cx| {
html! {
p { (Lc::t("colors_val_2", &LOC).using(cx)) }
}
})),
)
.with_child(
Block::new()
.with_title(Lc::t("colors_block", &LOC).with_arg("n", "3"))
.with_child(Html::with(|cx| {
html! {
p { (Lc::t("colors_val_3", &LOC).using(cx)) }
}
})),
)
.with_child(
Block::new()
.with_title(Lc::t("colors_block", &LOC).with_arg("n", "4"))
.with_child(Html::with(|cx| {
html! {
p { (Lc::t("colors_val_4", &LOC).using(cx)) }
}
})),
)
.with_child(
Block::new()
.with_title(Lc::t("colors_block", &LOC).with_arg("n", "5"))
.with_child(Html::with(|cx| {
html! {
p { (Lc::t("colors_val_5", &LOC).using(cx)) }
}
})),
)
.with_child(
Block::new()
.with_title(Lc::t("colors_block", &LOC).with_arg("n", "6"))
.with_child(Html::with(|cx| {
html! {
p { (Lc::t("colors_val_6", &LOC).using(cx)) }
}
})),
),
)
.render()
.await
}
#[pagetop::main]
async fn main() -> std::io::Result<()> {
Application::prepare(&IntroColors).await.run().await
}