📱 Actualiza el funcionamiento de temas
This commit is contained in:
parent
18c141aeb9
commit
a669608783
10 changed files with 117 additions and 51 deletions
|
|
@ -59,7 +59,7 @@ pub async fn summary(request: server::HttpRequest) -> ResultPage<Markup, FatalEr
|
|||
.with_title(L10n::text("Admin"))
|
||||
.with_this_in("top-menu", top_menu)
|
||||
.with_this_in(
|
||||
"region-content",
|
||||
"content",
|
||||
grid::Row::new()
|
||||
.with_column(grid::Column::new().with_component(side_menu))
|
||||
.with_column(grid::Column::new().with_component(L10n::html(html! {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use pagetop::prelude::*;
|
|||
|
||||
define_handle!(THEME_BOOTSIER);
|
||||
|
||||
define_locale!(LOCALE_BOOTSIER, "src/locales");
|
||||
define_locale!(LOCALE_BOOTSIER, "static/locales");
|
||||
|
||||
include!(concat!(env!("OUT_DIR"), "/bootsier.rs"));
|
||||
|
||||
|
|
@ -27,6 +27,21 @@ impl ModuleTrait for Bootsier {
|
|||
}
|
||||
|
||||
impl ThemeTrait for Bootsier {
|
||||
#[rustfmt::skip]
|
||||
fn regions(&self) -> Vec<(&'static str, L10n)> {
|
||||
vec![
|
||||
("header", L10n::t("header", &LOCALE_BOOTSIER)),
|
||||
("nav_branding", L10n::t("nav_branding", &LOCALE_BOOTSIER)),
|
||||
("nav_main", L10n::t("nav_main", &LOCALE_BOOTSIER)),
|
||||
("nav_additional", L10n::t("nav_additional", &LOCALE_BOOTSIER)),
|
||||
("breadcrumb", L10n::t("breadcrumb", &LOCALE_BOOTSIER)),
|
||||
("content", L10n::t("breadcrumb", &LOCALE_BOOTSIER)),
|
||||
("sidebar_first", L10n::t("sidebar_first", &LOCALE_BOOTSIER)),
|
||||
("sidebar_second", L10n::t("sidebar_second", &LOCALE_BOOTSIER)),
|
||||
("footer", L10n::t("footer", &LOCALE_BOOTSIER)),
|
||||
]
|
||||
}
|
||||
|
||||
fn before_render_page(&self, page: &mut Page) {
|
||||
page.alter_favicon(Some(Favicon::new().with_icon("/theme/favicon.ico")))
|
||||
.alter_context(ContextOp::AddStyleSheet(
|
||||
|
|
@ -42,6 +57,66 @@ impl ThemeTrait for Bootsier {
|
|||
pagetop_jquery::JQuery::add_jquery(page.context());
|
||||
}
|
||||
|
||||
fn render_page_body(&self, page: &mut Page) -> Markup {
|
||||
match page.template() {
|
||||
"admin" => html! {
|
||||
body class=[page.body_classes().get()] {
|
||||
@for region in &[
|
||||
"top-menu",
|
||||
"side-menu",
|
||||
"content"
|
||||
] {
|
||||
@if let Some(content) = page.render_region(region) {
|
||||
#(region) { (content) }
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
_ => {
|
||||
let header = page.render_region("header");
|
||||
let nav_branding = page.render_region("nav_branding");
|
||||
let nav_main = page.render_region("nav_main");
|
||||
let nav_additional = page.render_region("nav_additional");
|
||||
let breadcrumb = page.render_region("breadcrumb");
|
||||
let content = page.render_region("content");
|
||||
let sidebar_first = page.render_region("sidebar_first");
|
||||
let sidebar_second = page.render_region("sidebar_second");
|
||||
let footer = page.render_region("footer");
|
||||
html! {
|
||||
body class=[page.body_classes().get()] {
|
||||
@if header.is_some() {
|
||||
#header { (header.unwrap()) }
|
||||
}
|
||||
@if nav_branding.is_some() {
|
||||
#nav_branding { (nav_branding.unwrap()) }
|
||||
}
|
||||
@if nav_main.is_some() {
|
||||
#nav_main { (nav_main.unwrap()) }
|
||||
}
|
||||
@if nav_additional.is_some() {
|
||||
#nav_additional { (nav_additional.unwrap()) }
|
||||
}
|
||||
@if breadcrumb.is_some() {
|
||||
#breadcrumb { (breadcrumb.unwrap()) }
|
||||
}
|
||||
@if content.is_some() {
|
||||
#content { (content.unwrap()) }
|
||||
}
|
||||
@if sidebar_first.is_some() {
|
||||
#sidebar_first { (sidebar_first.unwrap()) }
|
||||
}
|
||||
@if sidebar_second.is_some() {
|
||||
#sidebar_second { (sidebar_second.unwrap()) }
|
||||
}
|
||||
@if footer.is_some() {
|
||||
#footer { (footer.unwrap()) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn render_component(
|
||||
&self,
|
||||
component: &dyn ComponentTrait,
|
||||
|
|
|
|||
|
|
@ -1,13 +1,9 @@
|
|||
header = Header
|
||||
primary_menu = Primary menu
|
||||
secondary_menu = Secondary menu
|
||||
hero = Hero (full width)
|
||||
highlighted = Highlighted
|
||||
nav_branding = Navigation branding region
|
||||
nav_main = Main navigation region
|
||||
nav_additional = Additional navigation region (eg search form, social icons, etc)
|
||||
breadcrumb = Breadcrumb
|
||||
social = Social Bar
|
||||
content_above = Content Above
|
||||
content = Content
|
||||
sidebar = Sidebar
|
||||
content_below = Content Below
|
||||
footer_top = Footer Top
|
||||
footer_bottom = Footer Bottom
|
||||
content = Main content
|
||||
sidebar_first = Sidebar first
|
||||
sidebar_second = Sidebar second
|
||||
footer = Footer
|
||||
|
|
|
|||
|
|
@ -1,13 +1,9 @@
|
|||
header = Cabecera
|
||||
primary_menu = Menú principal
|
||||
secondary_menu = Menú secundario
|
||||
hero = Hero (ancho completo)
|
||||
highlighted = Destacado
|
||||
breadcrumb = Ruta de navegación
|
||||
social = Enlaces sociales
|
||||
content_above = Antes del contenido
|
||||
content = Contenido
|
||||
sidebar = Barra lateral
|
||||
content_below = Después del contenido
|
||||
footer_top = Pie de página (superior)
|
||||
footer_bottom = Pie de página (inferior)
|
||||
nav_branding = Navegación y marca
|
||||
nav_main = Navegación principal
|
||||
nav_additional = Navegación adicional (p.e. formulario de búsqueda, iconos sociales, etc.)
|
||||
breadcrumb = Ruta de posicionamiento
|
||||
content = Contenido principal
|
||||
sidebar_first = Barra lateral primera
|
||||
sidebar_second = Barra lateral segunda
|
||||
footer = Pie
|
||||
|
|
|
|||
|
|
@ -39,11 +39,11 @@ async fn demo(request: server::HttpRequest) -> ResultPage<Markup, FatalError> {
|
|||
"/homedemo/css/styles.css",
|
||||
)))
|
||||
.with_body_classes(ClassesOp::AddFirst, "default-homepage")
|
||||
.with_this_in("region-content", hello_world())
|
||||
.with_this_in("region-content", welcome())
|
||||
.with_this_in("region-content", about_pagetop())
|
||||
.with_this_in("region-content", promo_pagetop())
|
||||
.with_this_in("region-content", reporting_issues())
|
||||
.with_this_in("content", hello_world())
|
||||
.with_this_in("content", welcome())
|
||||
.with_this_in("content", about_pagetop())
|
||||
.with_this_in("content", promo_pagetop())
|
||||
.with_this_in("content", reporting_issues())
|
||||
.render()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ async fn login(request: server::HttpRequest) -> ResultPage<Markup, FatalError> {
|
|||
Page::new(request)
|
||||
.with_title(L10n::text("Identificación del usuario"))
|
||||
.with_this_in(
|
||||
"region-content",
|
||||
"content",
|
||||
Container::new()
|
||||
.with_id("welcome")
|
||||
.with_component(form_login()),
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
use super::ModuleTrait;
|
||||
|
||||
use crate::app::LOCALE_PAGETOP;
|
||||
use crate::config;
|
||||
use crate::core::component::{ComponentTrait, RenderContext};
|
||||
use crate::core::component::{ComponentTrait, L10n, RenderContext};
|
||||
use crate::html::{html, Favicon, Markup};
|
||||
use crate::response::page::Page;
|
||||
|
||||
|
|
@ -9,6 +10,17 @@ pub type ThemeStaticRef = &'static dyn ThemeTrait;
|
|||
|
||||
/// Los temas deben implementar este "trait".
|
||||
pub trait ThemeTrait: ModuleTrait + Send + Sync {
|
||||
#[rustfmt::skip]
|
||||
fn regions(&self) -> Vec<(&'static str, L10n)> {
|
||||
vec![
|
||||
("header", L10n::t("header", &LOCALE_PAGETOP)),
|
||||
("pagetop", L10n::t("pagetop", &LOCALE_PAGETOP)),
|
||||
("content", L10n::t("content", &LOCALE_PAGETOP)),
|
||||
("sidebar", L10n::t("sidebar", &LOCALE_PAGETOP)),
|
||||
("footer", L10n::t("footer", &LOCALE_PAGETOP)),
|
||||
]
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn before_render_page(&self, page: &mut Page) {
|
||||
if page.favicon().is_none() {
|
||||
|
|
@ -56,20 +68,9 @@ pub trait ThemeTrait: ModuleTrait + Send + Sync {
|
|||
fn render_page_body(&self, page: &mut Page) -> Markup {
|
||||
html! {
|
||||
body class=[page.body_classes().get()] {
|
||||
@match page.template() {
|
||||
"admin" => {
|
||||
@for region in &["top-menu", "side-menu", "region-content"] {
|
||||
@if let Some(content) = page.render_region(region) {
|
||||
#(region) { (content) }
|
||||
}
|
||||
}
|
||||
},
|
||||
_ => {
|
||||
@for region in &["region-content"] {
|
||||
@if let Some(content) = page.render_region(region) {
|
||||
#(region) { (content) }
|
||||
}
|
||||
}
|
||||
@for (region, _) in self.regions().iter() {
|
||||
@if let Some(content) = page.render_region(region) {
|
||||
#(region) { (content) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ impl fmt::Display for FatalError {
|
|||
let error_page = Page::new(request.clone());
|
||||
if let Ok(page) = error_page
|
||||
.with_title(L10n::text("Error FORBIDDEN"))
|
||||
.with_this_in("region-content", error403::Error403)
|
||||
.with_this_in("content", error403::Error403)
|
||||
.with_template("error")
|
||||
.render()
|
||||
{
|
||||
|
|
@ -47,7 +47,7 @@ impl fmt::Display for FatalError {
|
|||
let error_page = Page::new(request.clone());
|
||||
if let Ok(page) = error_page
|
||||
.with_title(L10n::text("Error RESOURCE NOT FOUND"))
|
||||
.with_this_in("region-content", error404::Error404)
|
||||
.with_this_in("content", error404::Error404)
|
||||
.with_template("error")
|
||||
.render()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,5 +2,4 @@ header = Header
|
|||
pagetop = Page Top
|
||||
content = Content
|
||||
sidebar = Sidebar
|
||||
pagebottom = Page Bottom
|
||||
footer = Footer
|
||||
|
|
|
|||
|
|
@ -2,5 +2,4 @@ header = Cabecera
|
|||
pagetop = Superior
|
||||
content = Contenido
|
||||
sidebar = Barra lateral
|
||||
pagebottom = Inferior
|
||||
footer = Pie de página
|
||||
footer = Pie
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue