🐛 Corrige orden ejecución de acciones de página
This commit is contained in:
parent
8eba48283e
commit
7138b9c58b
4 changed files with 24 additions and 35 deletions
|
|
@ -72,7 +72,7 @@ pub trait ThemeTrait: ModuleTrait + Send + Sync {
|
|||
}
|
||||
}
|
||||
|
||||
fn after_prepare_page(&self, page: &mut Page) {
|
||||
fn before_render_page(&self, page: &mut Page) {
|
||||
if page.favicon().is_none() {
|
||||
page.alter_favicon(Some(Favicon::new().with_icon("/theme/favicon.ico")));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@ pub use actix_web::Result as ResultPage;
|
|||
mod before_prepare_page;
|
||||
pub use before_prepare_page::{ActionBeforePreparePage, ACTION_BEFORE_PREPARE_PAGE};
|
||||
|
||||
mod after_prepare_page;
|
||||
pub use after_prepare_page::{ActionAfterPreparePage, ACTION_AFTER_PREPARE_PAGE};
|
||||
mod before_render_page;
|
||||
pub use before_render_page::{ActionBeforeRenderPage, ACTION_BEFORE_RENDER_PAGE};
|
||||
|
||||
mod definition;
|
||||
pub use definition::Page;
|
||||
|
|
|
|||
|
|
@ -2,25 +2,25 @@ use crate::core::action::{ActionTrait, AnyAction};
|
|||
use crate::response::page::Page;
|
||||
use crate::{use_handle, Handle};
|
||||
|
||||
use_handle!(ACTION_AFTER_PREPARE_PAGE);
|
||||
use_handle!(ACTION_BEFORE_RENDER_PAGE);
|
||||
|
||||
type Action = fn(&mut Page);
|
||||
|
||||
pub struct ActionAfterPreparePage {
|
||||
pub struct ActionBeforeRenderPage {
|
||||
action: Option<Action>,
|
||||
weight: isize,
|
||||
}
|
||||
|
||||
impl ActionTrait for ActionAfterPreparePage {
|
||||
impl ActionTrait for ActionBeforeRenderPage {
|
||||
fn new() -> Self {
|
||||
ActionAfterPreparePage {
|
||||
ActionBeforeRenderPage {
|
||||
action: None,
|
||||
weight: 0,
|
||||
}
|
||||
}
|
||||
|
||||
fn handle(&self) -> Handle {
|
||||
ACTION_AFTER_PREPARE_PAGE
|
||||
ACTION_BEFORE_RENDER_PAGE
|
||||
}
|
||||
|
||||
fn weight(&self) -> isize {
|
||||
|
|
@ -32,7 +32,7 @@ impl ActionTrait for ActionAfterPreparePage {
|
|||
}
|
||||
}
|
||||
|
||||
impl ActionAfterPreparePage {
|
||||
impl ActionBeforeRenderPage {
|
||||
pub fn with_action(mut self, action: Action) -> Self {
|
||||
self.action = Some(action);
|
||||
self
|
||||
|
|
@ -3,11 +3,10 @@ use crate::core::action::{action_ref, run_actions};
|
|||
use crate::core::component::{ComponentTrait, ContextOp, OneComponent, RenderContext};
|
||||
use crate::core::theme::ComponentsRegions;
|
||||
use crate::html::{html, Classes, ClassesOp, Favicon, Markup, DOCTYPE};
|
||||
use crate::locale::{langid_for, LanguageIdentifier};
|
||||
use crate::response::fatal_error::FatalError;
|
||||
use crate::response::page::ResultPage;
|
||||
use crate::response::page::{ActionAfterPreparePage, ACTION_AFTER_PREPARE_PAGE};
|
||||
use crate::response::page::{ActionBeforePreparePage, ACTION_BEFORE_PREPARE_PAGE};
|
||||
use crate::response::page::{ActionBeforeRenderPage, ACTION_BEFORE_RENDER_PAGE};
|
||||
use crate::{fn_builder, service};
|
||||
|
||||
use unic_langid::CharacterDirection;
|
||||
|
|
@ -54,12 +53,6 @@ impl Page {
|
|||
|
||||
// Page BUILDER.
|
||||
|
||||
#[fn_builder]
|
||||
pub fn alter_language(&mut self, language: &'static str) -> &mut Self {
|
||||
self.context.alter(ContextOp::LangId(langid_for(language)));
|
||||
self
|
||||
}
|
||||
|
||||
#[fn_builder]
|
||||
pub fn alter_title(&mut self, title: L10n) -> &mut Self {
|
||||
self.title.set(title);
|
||||
|
|
@ -116,10 +109,6 @@ impl Page {
|
|||
|
||||
// Page GETTERS.
|
||||
|
||||
pub fn langid(&self) -> &LanguageIdentifier {
|
||||
self.context.langid()
|
||||
}
|
||||
|
||||
pub fn title(&mut self) -> String {
|
||||
self.title.prepare(&mut self.context).into_string()
|
||||
}
|
||||
|
|
@ -155,31 +144,31 @@ impl Page {
|
|||
// Page RENDER.
|
||||
|
||||
pub fn render(&mut self) -> ResultPage<Markup, FatalError> {
|
||||
// Acciones de los módulos antes de preparar la página.
|
||||
// Module actions before preparing the page.
|
||||
run_actions(ACTION_BEFORE_PREPARE_PAGE, |action| {
|
||||
action_ref::<ActionBeforePreparePage>(&**action).run(self)
|
||||
});
|
||||
|
||||
// Acciones del tema antes de preparar la página.
|
||||
// Theme actions before preparing the page.
|
||||
self.context.theme().before_prepare_page(self);
|
||||
|
||||
// Primero, preparar el cuerpo.
|
||||
// Prepare page body.
|
||||
let body = self.context.theme().prepare_page_body(self);
|
||||
|
||||
// Luego, preparar la cabecera.
|
||||
let head = self.context.theme().prepare_page_head(self);
|
||||
|
||||
// Acciones de los módulos después de preparar la página.
|
||||
run_actions(ACTION_AFTER_PREPARE_PAGE, |action| {
|
||||
action_ref::<ActionAfterPreparePage>(&**action).run(self)
|
||||
// Module actions before rendering the page.
|
||||
run_actions(ACTION_BEFORE_RENDER_PAGE, |action| {
|
||||
action_ref::<ActionBeforeRenderPage>(&**action).run(self)
|
||||
});
|
||||
|
||||
// Acciones del tema después de preparar la página.
|
||||
self.context.theme().after_prepare_page(self);
|
||||
// Theme actions before rendering the page.
|
||||
self.context.theme().before_render_page(self);
|
||||
|
||||
// Finalmente, renderiza la página.
|
||||
let lang = self.langid().language.as_str();
|
||||
let dir = match self.langid().character_direction() {
|
||||
// Prepare page head.
|
||||
let head = self.context.theme().prepare_page_head(self);
|
||||
|
||||
// Render the page.
|
||||
let lang = self.context.langid().language.as_str();
|
||||
let dir = match self.context.langid().character_direction() {
|
||||
CharacterDirection::LTR => "ltr",
|
||||
CharacterDirection::RTL => "rtl",
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue