💥 Cambios antes/después de preparar cuerpo pág.
This commit is contained in:
parent
44550edafa
commit
0880964fd1
12 changed files with 63 additions and 63 deletions
|
|
@ -30,7 +30,7 @@ impl ModuleTrait for Admin {
|
|||
}
|
||||
|
||||
fn actions(&self) -> Vec<Action> {
|
||||
vec![action!(ActionBeforePreparePage => before_prepare_page)]
|
||||
vec![action!(ActionBeforePrepareBody => before_prepare_body)]
|
||||
}
|
||||
|
||||
fn configure_service(&self, cfg: &mut service::web::ServiceConfig) {
|
||||
|
|
@ -40,6 +40,6 @@ impl ModuleTrait for Admin {
|
|||
}
|
||||
}
|
||||
|
||||
fn before_prepare_page(page: &mut Page) {
|
||||
fn before_prepare_body(page: &mut Page) {
|
||||
page.alter_body_classes(ClassesOp::Add, "test-admin");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ impl ModuleTrait for Aliner {
|
|||
}
|
||||
|
||||
impl ThemeTrait for Aliner {
|
||||
fn before_prepare_page(&self, page: &mut Page) {
|
||||
fn before_prepare_body(&self, page: &mut Page) {
|
||||
page.alter_favicon(Some(Favicon::new().with_icon("/theme/favicon.ico")))
|
||||
.alter_context(ContextOp::AddStyleSheet(
|
||||
StyleSheet::at("/aliner/css/styles.css").with_weight(-99),
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ impl ThemeTrait for Bootsier {
|
|||
]
|
||||
}
|
||||
|
||||
fn before_prepare_page(&self, page: &mut Page) {
|
||||
fn before_prepare_body(&self, page: &mut Page) {
|
||||
page.alter_favicon(Some(Favicon::new().with_icon("/theme/favicon.ico")))
|
||||
.alter_context(ContextOp::AddStyleSheet(
|
||||
StyleSheet::at("/bootsier/css/bootstrap.min.css")
|
||||
|
|
@ -58,7 +58,7 @@ impl ThemeTrait for Bootsier {
|
|||
JQuery.enable_jquery(page.context());
|
||||
}
|
||||
|
||||
fn prepare_page_body(&self, page: &mut Page) -> Markup {
|
||||
fn prepare_body(&self, page: &mut Page) -> Markup {
|
||||
match page.template() {
|
||||
"admin" => html! {
|
||||
body class=[page.body_classes().get()] {
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ impl ModuleTrait for Bulmix {
|
|||
}
|
||||
|
||||
impl ThemeTrait for Bulmix {
|
||||
fn before_prepare_page(&self, page: &mut Page) {
|
||||
fn before_prepare_body(&self, page: &mut Page) {
|
||||
page.alter_favicon(Some(Favicon::new().with_icon("/theme/favicon.ico")))
|
||||
.alter_context(ContextOp::AddStyleSheet(
|
||||
StyleSheet::at("/bulmix/css/bulma.min.css")
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ impl ModuleTrait for JQuery {
|
|||
}
|
||||
|
||||
fn actions(&self) -> Vec<Action> {
|
||||
vec![action!(ActionBeforeRenderPage => before_render_page)]
|
||||
vec![action!(ActionAfterPrepareBody => after_prepare_body)]
|
||||
}
|
||||
|
||||
fn configure_service(&self, cfg: &mut service::web::ServiceConfig) {
|
||||
|
|
@ -44,7 +44,7 @@ impl JQuery {
|
|||
}
|
||||
}
|
||||
|
||||
fn before_render_page(page: &mut Page) {
|
||||
fn after_prepare_body(page: &mut Page) {
|
||||
if let Some(true) = page.context().get_param::<bool>(PARAM_JQUERY) {
|
||||
page.context().alter(ContextOp::AddJavaScript(
|
||||
JavaScript::at("/jquery/jquery.min.js")
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ impl ModuleTrait for Node {
|
|||
}
|
||||
|
||||
fn actions(&self) -> Vec<Action> {
|
||||
vec![action!(ActionBeforePreparePage => before_prepare_page, -1)]
|
||||
vec![action!(ActionBeforePrepareBody => before_prepare_body, -1)]
|
||||
}
|
||||
|
||||
fn migrations(&self) -> Vec<MigrationItem> {
|
||||
|
|
@ -44,6 +44,6 @@ async fn node(request: service::HttpRequest) -> ResultPage<Markup, FatalError> {
|
|||
Page::new(request).with_title(L10n::n("Nodo")).render()
|
||||
}
|
||||
|
||||
fn before_prepare_page(page: &mut Page) {
|
||||
fn before_prepare_body(page: &mut Page) {
|
||||
page.alter_body_classes(ClassesOp::Add, "test-node");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ impl ModuleTrait for Basic {
|
|||
}
|
||||
|
||||
impl ThemeTrait for Basic {
|
||||
fn before_prepare_page(&self, page: &mut Page) {
|
||||
fn before_prepare_body(&self, page: &mut Page) {
|
||||
page.alter_favicon(Some(Favicon::new().with_icon("/theme/favicon.ico")))
|
||||
.alter_context(ContextOp::AddStyleSheet(
|
||||
StyleSheet::at("/theme/css/normalize.min.css").with_version("8.0.1"),
|
||||
|
|
|
|||
|
|
@ -21,9 +21,27 @@ pub trait ThemeTrait: ModuleTrait + Send + Sync {
|
|||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn before_prepare_page(&self, page: &mut Page) {}
|
||||
fn before_prepare_body(&self, page: &mut Page) {}
|
||||
|
||||
fn prepare_page_head(&self, page: &mut Page) -> Markup {
|
||||
fn prepare_body(&self, page: &mut Page) -> Markup {
|
||||
html! {
|
||||
body class=[page.body_classes().get()] {
|
||||
@for (region, _) in self.regions().iter() {
|
||||
@if let Some(content) = page.prepare_region(region) {
|
||||
#(region) { (content) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn after_prepare_body(&self, page: &mut Page) {
|
||||
if page.favicon().is_none() {
|
||||
page.alter_favicon(Some(Favicon::new().with_icon("/theme/favicon.ico")));
|
||||
}
|
||||
}
|
||||
|
||||
fn prepare_head(&self, page: &mut Page) -> Markup {
|
||||
let title = page.title();
|
||||
let description = page.description();
|
||||
let viewport = "width=device-width, initial-scale=1, shrink-to-fit=no";
|
||||
|
|
@ -60,24 +78,6 @@ pub trait ThemeTrait: ModuleTrait + Send + Sync {
|
|||
}
|
||||
}
|
||||
|
||||
fn prepare_page_body(&self, page: &mut Page) -> Markup {
|
||||
html! {
|
||||
body class=[page.body_classes().get()] {
|
||||
@for (region, _) in self.regions().iter() {
|
||||
@if let Some(content) = page.prepare_region(region) {
|
||||
#(region) { (content) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn before_render_page(&self, page: &mut Page) {
|
||||
if page.favicon().is_none() {
|
||||
page.alter_favicon(Some(Favicon::new().with_icon("/theme/favicon.ico")));
|
||||
}
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
#[allow(unused_variables)]
|
||||
fn before_prepare_component(
|
||||
|
|
|
|||
|
|
@ -137,23 +137,23 @@ impl Page {
|
|||
// Page RENDER.
|
||||
|
||||
pub fn render(&mut self) -> ResultPage<Markup, FatalError> {
|
||||
// Module actions before preparing the page.
|
||||
run_actions_before_prepare_page(self);
|
||||
// Module actions before preparing the page body.
|
||||
run_actions_before_prepare_body(self);
|
||||
|
||||
// Theme actions before preparing the page.
|
||||
self.context.theme().before_prepare_page(self);
|
||||
// Theme actions before preparing the page body.
|
||||
self.context.theme().before_prepare_body(self);
|
||||
|
||||
// Prepare page body.
|
||||
let body = self.context.theme().prepare_page_body(self);
|
||||
let body = self.context.theme().prepare_body(self);
|
||||
|
||||
// Module actions before rendering the page.
|
||||
run_actions_before_render_page(self);
|
||||
// Module actions after preparing the page body.
|
||||
run_actions_after_prepare_body(self);
|
||||
|
||||
// Theme actions before rendering the page.
|
||||
self.context.theme().before_render_page(self);
|
||||
// Theme actions after preparing the page body.
|
||||
self.context.theme().after_prepare_body(self);
|
||||
|
||||
// Prepare page head.
|
||||
let head = self.context.theme().prepare_page_head(self);
|
||||
let head = self.context.theme().prepare_head(self);
|
||||
|
||||
// Render the page.
|
||||
let lang = self.context.langid().language.as_str();
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ use crate::response::page::Page;
|
|||
|
||||
pub type ActionPage = fn(page: &mut Page);
|
||||
|
||||
mod before_prepare_page;
|
||||
pub use before_prepare_page::*;
|
||||
mod before_prepare_body;
|
||||
pub use before_prepare_body::*;
|
||||
|
||||
mod before_render_page;
|
||||
pub use before_render_page::*;
|
||||
mod after_prepare_body;
|
||||
pub use after_prepare_body::*;
|
||||
|
|
|
|||
|
|
@ -3,23 +3,23 @@ use crate::response::page::action::ActionPage;
|
|||
use crate::response::page::Page;
|
||||
use crate::{use_handle, Handle};
|
||||
|
||||
use_handle!(ACTION_BEFORE_RENDER_PAGE for Action);
|
||||
use_handle!(ACTION_AFTER_PREPARE_BODY for Action);
|
||||
|
||||
pub struct ActionBeforeRenderPage {
|
||||
pub struct ActionAfterPrepareBody {
|
||||
action: Option<ActionPage>,
|
||||
weight: isize,
|
||||
}
|
||||
|
||||
impl ActionTrait for ActionBeforeRenderPage {
|
||||
impl ActionTrait for ActionAfterPrepareBody {
|
||||
fn new() -> Self {
|
||||
ActionBeforeRenderPage {
|
||||
ActionAfterPrepareBody {
|
||||
action: None,
|
||||
weight: 0,
|
||||
}
|
||||
}
|
||||
|
||||
fn handle(&self) -> Handle {
|
||||
ACTION_BEFORE_RENDER_PAGE
|
||||
ACTION_AFTER_PREPARE_BODY
|
||||
}
|
||||
|
||||
fn weight(&self) -> isize {
|
||||
|
|
@ -31,7 +31,7 @@ impl ActionTrait for ActionBeforeRenderPage {
|
|||
}
|
||||
}
|
||||
|
||||
impl ActionBeforeRenderPage {
|
||||
impl ActionAfterPrepareBody {
|
||||
pub fn with_action(mut self, action: ActionPage) -> Self {
|
||||
self.action = Some(action);
|
||||
self
|
||||
|
|
@ -50,8 +50,8 @@ impl ActionBeforeRenderPage {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub(crate) fn run_actions_before_render_page(page: &mut Page) {
|
||||
run_actions(ACTION_BEFORE_RENDER_PAGE, |action| {
|
||||
action_ref::<ActionBeforeRenderPage>(&**action).run(page)
|
||||
pub(crate) fn run_actions_after_prepare_body(page: &mut Page) {
|
||||
run_actions(ACTION_AFTER_PREPARE_BODY, |action| {
|
||||
action_ref::<ActionAfterPrepareBody>(&**action).run(page)
|
||||
});
|
||||
}
|
||||
|
|
@ -3,23 +3,23 @@ use crate::response::page::action::ActionPage;
|
|||
use crate::response::page::Page;
|
||||
use crate::{use_handle, Handle};
|
||||
|
||||
use_handle!(ACTION_BEFORE_PREPARE_PAGE for Action);
|
||||
use_handle!(ACTION_BEFORE_PREPARE_BODY for Action);
|
||||
|
||||
pub struct ActionBeforePreparePage {
|
||||
pub struct ActionBeforePrepareBody {
|
||||
action: Option<ActionPage>,
|
||||
weight: isize,
|
||||
}
|
||||
|
||||
impl ActionTrait for ActionBeforePreparePage {
|
||||
impl ActionTrait for ActionBeforePrepareBody {
|
||||
fn new() -> Self {
|
||||
ActionBeforePreparePage {
|
||||
ActionBeforePrepareBody {
|
||||
action: None,
|
||||
weight: 0,
|
||||
}
|
||||
}
|
||||
|
||||
fn handle(&self) -> Handle {
|
||||
ACTION_BEFORE_PREPARE_PAGE
|
||||
ACTION_BEFORE_PREPARE_BODY
|
||||
}
|
||||
|
||||
fn weight(&self) -> isize {
|
||||
|
|
@ -31,7 +31,7 @@ impl ActionTrait for ActionBeforePreparePage {
|
|||
}
|
||||
}
|
||||
|
||||
impl ActionBeforePreparePage {
|
||||
impl ActionBeforePrepareBody {
|
||||
pub fn with_action(mut self, action: ActionPage) -> Self {
|
||||
self.action = Some(action);
|
||||
self
|
||||
|
|
@ -50,8 +50,8 @@ impl ActionBeforePreparePage {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub(crate) fn run_actions_before_prepare_page(page: &mut Page) {
|
||||
run_actions(ACTION_BEFORE_PREPARE_PAGE, |action| {
|
||||
action_ref::<ActionBeforePreparePage>(&**action).run(page)
|
||||
pub(crate) fn run_actions_before_prepare_body(page: &mut Page) {
|
||||
run_actions(ACTION_BEFORE_PREPARE_BODY, |action| {
|
||||
action_ref::<ActionBeforePrepareBody>(&**action).run(page)
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue