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