🎨 Is render, not prepare

This commit is contained in:
Manuel Cillero 2024-12-01 12:06:15 +01:00
parent 17f266b032
commit c329f0f72f
11 changed files with 59 additions and 58 deletions

1
.gitignore vendored
View file

@ -2,3 +2,4 @@
**/log/*.log*
**/local.*.toml
**/local.toml
workdir

View file

@ -1,5 +1,5 @@
mod before_prepare_body;
pub use before_prepare_body::*;
mod before_render_body;
pub use before_render_body::*;
mod after_prepare_body;
pub use after_prepare_body::*;
mod after_render_body;
pub use after_render_body::*;

View file

@ -1,21 +1,21 @@
use crate::prelude::*;
pub type FnAfterPrepareBody = fn(page: &mut Page);
pub type FnAfterRenderBody = fn(page: &mut Page);
pub struct AfterPrepareBody {
f: FnAfterPrepareBody,
pub struct AfterRenderBody {
f: FnAfterRenderBody,
weight: Weight,
}
impl ActionTrait for AfterPrepareBody {
impl ActionTrait for AfterRenderBody {
fn weight(&self) -> Weight {
self.weight
}
}
impl AfterPrepareBody {
pub fn new(f: FnAfterPrepareBody) -> Self {
AfterPrepareBody { f, weight: 0 }
impl AfterRenderBody {
pub fn new(f: FnAfterRenderBody) -> Self {
AfterRenderBody { f, weight: 0 }
}
pub fn with_weight(mut self, value: Weight) -> Self {

View file

@ -1,21 +1,21 @@
use crate::prelude::*;
pub type FnBeforePrepareBody = fn(page: &mut Page);
pub type FnBeforeRenderBody = fn(page: &mut Page);
pub struct BeforePrepareBody {
f: FnBeforePrepareBody,
pub struct BeforeRenderBody {
f: FnBeforeRenderBody,
weight: Weight,
}
impl ActionTrait for BeforePrepareBody {
impl ActionTrait for BeforeRenderBody {
fn weight(&self) -> Weight {
self.weight
}
}
impl BeforePrepareBody {
pub fn new(f: FnBeforePrepareBody) -> Self {
BeforePrepareBody { f, weight: 0 }
impl BeforeRenderBody {
pub fn new(f: FnBeforeRenderBody) -> Self {
BeforeRenderBody { f, weight: 0 }
}
pub fn with_weight(mut self, value: Weight) -> Self {

View file

@ -154,21 +154,21 @@ impl Context {
.and_then(|v| T::from_str(v).map_err(|_| ErrorParam::ParseError(v.clone())))
}
// Context PREPARE.
// Context RENDER.
pub fn prepare_assets(&mut self) -> Markup {
pub fn render_assets(&mut self) -> Markup {
html! {
@if let Some(favicon) = &self.favicon {
(favicon.prepare())
(favicon.render())
}
(self.stylesheet.prepare())
(self.javascript.prepare())
(self.stylesheet.render())
(self.javascript.render())
}
}
pub fn prepare_region(&mut self, region: impl Into<String>) -> Markup {
pub fn render_region(&mut self, region: impl Into<String>) -> Markup {
self.regions
.all_in_region(self.theme, region.into().as_str())
.all_in_region(self.theme, &region.into())
.render(self)
}

View file

@ -1,6 +1,6 @@
use crate::core::package::PackageTrait;
use crate::global;
use crate::html::{html, PrepareMarkup};
use crate::html::{html, Markup};
use crate::locale::L10n;
use crate::response::page::Page;
@ -12,9 +12,9 @@ pub trait ThemeTrait: PackageTrait + Send + Sync {
vec![("content", L10n::l("content"))]
}
fn prepare_head(&self, page: &mut Page) -> PrepareMarkup {
fn render_head(&self, page: &mut Page) -> Markup {
let viewport = "width=device-width, initial-scale=1, shrink-to-fit=no";
PrepareMarkup::With(html! {
html! {
head {
meta charset="utf-8";
@ -38,22 +38,22 @@ pub trait ThemeTrait: PackageTrait + Send + Sync {
meta property=(property) content=(content) {}
}
(page.context().prepare_assets())
(page.context().render_assets())
}
})
}
}
#[allow(unused_variables)]
fn before_prepare_body(&self, page: &mut Page) {}
fn before_render_body(&self, page: &mut Page) {}
fn prepare_body(&self, page: &mut Page) -> PrepareMarkup {
PrepareMarkup::With(html! {
fn render_body(&self, page: &mut Page) -> Markup {
html! {
body id=[page.body_id().get()] class=[page.body_classes().get()] {
(page.context().prepare_region("content"))
(page.context().render_region("content"))
}
})
}
}
#[allow(unused_variables)]
fn after_prepare_body(&self, page: &mut Page) {}
fn after_render_body(&self, page: &mut Page) {}
}

View file

@ -10,7 +10,7 @@ pub trait AssetsTrait {
fn weight(&self) -> Weight;
fn prepare(&self) -> Markup;
fn render(&self) -> Markup;
}
#[derive(AutoDefault)]
@ -41,12 +41,12 @@ impl<T: AssetsTrait> Assets<T> {
self
}
pub fn prepare(&mut self) -> Markup {
pub fn render(&mut self) -> Markup {
let assets = &mut self.0;
assets.sort_by_key(AssetsTrait::weight);
html! {
@for a in assets {
(a.prepare())
(a.render())
}
}
}

View file

@ -83,7 +83,7 @@ impl Favicon {
// Favicon PREPARE.
pub(crate) fn prepare(&self) -> Markup {
pub(crate) fn render(&self) -> Markup {
html! {
@for item in &self.0 {
(item)

View file

@ -36,7 +36,7 @@ impl AssetsTrait for JavaScript {
self.weight
}
fn prepare(&self) -> Markup {
fn render(&self) -> Markup {
match &self.source {
Source::From(path) => html! {
script src=(concat_string!(path, self.prefix, self.version)) {};

View file

@ -38,7 +38,7 @@ impl AssetsTrait for StyleSheet {
self.weight
}
fn prepare(&self) -> Markup {
fn render(&self) -> Markup {
match &self.source {
Source::From(path) => html! {
link

View file

@ -156,26 +156,26 @@ impl Page {
// Page RENDER.
pub fn render(&mut self) -> ResultPage<Markup, ErrorPage> {
// Theme operations before preparing the page body.
self.context.theme().before_prepare_body(self);
// Theme-specific operations before rendering the page body.
self.context.theme().before_render_body(self);
// Packages actions before preparing the page body.
action::page::BeforePrepareBody::dispatch(self);
// Execute package actions before rendering the page body.
action::page::BeforeRenderBody::dispatch(self);
// Prepare page body.
let body = self.context.theme().prepare_body(self);
// Render the page body.
let body = self.context.theme().render_body(self);
// Theme operations after preparing the page body.
self.context.theme().after_prepare_body(self);
// Theme-specific operations after rendering the page body.
self.context.theme().after_render_body(self);
// Packages actions after preparing the page body.
action::page::AfterPrepareBody::dispatch(self);
// Execute package actions after rendering the page body.
action::page::AfterRenderBody::dispatch(self);
// Prepare page head.
let head = self.context.theme().prepare_head(self);
// Render the page head.
let head = self.context.theme().render_head(self);
// Render the page.
let lang = self.context.langid().language.as_str();
// Render the full page with language and direction attributes.
let lang = &self.context.langid().language;
let dir = match self.context.langid().character_direction() {
CharacterDirection::LTR => "ltr",
CharacterDirection::RTL => "rtl",
@ -184,8 +184,8 @@ impl Page {
Ok(html! {
(DOCTYPE)
html lang=(lang) dir=(dir) {
(head.render())
(body.render())
(head)
(body)
}
})
}