Skip to main content

pagetop_aliner/
lib.rs

1/*!
2<div align="center">
3
4<h1>PageTop Aliner</h1>
5
6<p>Tema para <strong>PageTop</strong> que muestra esquemáticamente la composición de las páginas HTML.</p>
7
8[![Doc API](https://img.shields.io/docsrs/pagetop-aliner?label=Doc%20API&style=for-the-badge&logo=Docs.rs)](https://docs.rs/pagetop-aliner)
9[![Crates.io](https://img.shields.io/crates/v/pagetop-aliner.svg?style=for-the-badge&logo=ipfs)](https://crates.io/crates/pagetop-aliner)
10[![Descargas](https://img.shields.io/crates/d/pagetop-aliner.svg?label=Descargas&style=for-the-badge&logo=transmission)](https://crates.io/crates/pagetop-aliner)
11[![Licencia](https://img.shields.io/badge/license-MIT%2FApache-blue.svg?label=Licencia&style=for-the-badge)](https://git.cillero.es/manuelcillero/pagetop/src/branch/main/extensions/pagetop-aliner#licencia)
12
13<br>
14</div>
15
16## Sobre PageTop
17
18[PageTop](https://docs.rs/pagetop) es un entorno de desarrollo que reivindica la esencia de la web
19clásica para crear soluciones web SSR (*renderizadas en el servidor*) modulares, extensibles y
20configurables, basadas en HTML, CSS y JavaScript.
21
22
23# ⚡️ Guía rápida
24
25Igual que con otras extensiones, **añade la dependencia** a tu `Cargo.toml`:
26
27```toml
28[dependencies]
29pagetop-aliner = { ... }
30```
31
32**Declara la extensión** en tu aplicación (o extensión que la requiera). Recuerda que el orden en
33`dependencies()` determina la prioridad relativa frente a las otras extensiones:
34
35```rust,no_run
36use pagetop::prelude::*;
37
38struct MyApp;
39
40impl Extension for MyApp {
41    fn dependencies(&self) -> Vec<ExtensionRef> {
42        vec![
43            // ...
44            &pagetop_aliner::Aliner,
45            // ...
46        ]
47    }
48}
49
50#[pagetop::main]
51async fn main() -> std::io::Result<()> {
52    Application::prepare(&MyApp).run()?.await
53}
54```
55
56Y **selecciona el tema en la configuración** de la aplicación:
57
58```toml
59[app]
60theme = "Aliner"
61```
62
63o **fuerza el tema por código** en una página concreta:
64
65```rust,no_run
66use pagetop::prelude::*;
67use pagetop_aliner::Aliner;
68
69async fn homepage(request: HttpRequest) -> ResultPage<Markup, ErrorPage> {
70    Page::new(request)
71        .with_theme(&Aliner)
72        .with_child(
73            Block::new()
74                .with_title(L10n::l("sample_title"))
75                .with_child(Html::with(|cx| html! {
76                    p { (L10n::l("sample_content").using(cx)) }
77                })),
78        )
79        .render()
80}
81```
82*/
83
84use pagetop::prelude::*;
85
86/// Implementa el tema para usar en pruebas que muestran el esquema de páginas HTML.
87///
88/// Define un tema mínimo útil para:
89///
90/// - Comprobar el funcionamiento de temas, plantillas y regiones.
91/// - Verificar integración de componentes y composiciones (*layouts*) sin estilos complejos.
92/// - Realizar pruebas de renderizado rápido con salida estable y predecible.
93/// - Preparar ejemplos y documentación, sin dependencias visuales (CSS/JS) innecesarias.
94pub struct Aliner;
95
96impl Extension for Aliner {
97    fn theme(&self) -> Option<ThemeRef> {
98        Some(&Self)
99    }
100
101    fn configure_service(&self, scfg: &mut service::web::ServiceConfig) {
102        static_files_service!(scfg, [aliner] => "/aliner");
103    }
104}
105
106impl Theme for Aliner {
107    fn before_render_page_body(&self, page: &mut Page) {
108        page.alter_assets(AssetsOp::AddStyleSheet(
109            StyleSheet::from("/css/normalize.css")
110                .with_version("8.0.1")
111                .with_weight(-99),
112        ))
113        .alter_assets(AssetsOp::AddStyleSheet(
114            StyleSheet::from("/css/basic.css")
115                .with_version(PAGETOP_VERSION)
116                .with_weight(-99),
117        ))
118        .alter_assets(AssetsOp::AddStyleSheet(
119            StyleSheet::from("/aliner/css/styles.css")
120                .with_version(env!("CARGO_PKG_VERSION"))
121                .with_weight(-99),
122        ))
123        .alter_child_in(
124            &DefaultRegion::Footer,
125            ChildOp::AddIfEmpty(PoweredBy::new().into()),
126        );
127    }
128}