🎨 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* **/log/*.log*
**/local.*.toml **/local.*.toml
**/local.toml **/local.toml
workdir

View file

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

View file

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

View file

@ -1,21 +1,21 @@
use crate::prelude::*; use crate::prelude::*;
pub type FnBeforePrepareBody = fn(page: &mut Page); pub type FnBeforeRenderBody = fn(page: &mut Page);
pub struct BeforePrepareBody { pub struct BeforeRenderBody {
f: FnBeforePrepareBody, f: FnBeforeRenderBody,
weight: Weight, weight: Weight,
} }
impl ActionTrait for BeforePrepareBody { impl ActionTrait for BeforeRenderBody {
fn weight(&self) -> Weight { fn weight(&self) -> Weight {
self.weight self.weight
} }
} }
impl BeforePrepareBody { impl BeforeRenderBody {
pub fn new(f: FnBeforePrepareBody) -> Self { pub fn new(f: FnBeforeRenderBody) -> Self {
BeforePrepareBody { f, weight: 0 } BeforeRenderBody { f, weight: 0 }
} }
pub fn with_weight(mut self, value: Weight) -> Self { 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()))) .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! { html! {
@if let Some(favicon) = &self.favicon { @if let Some(favicon) = &self.favicon {
(favicon.prepare()) (favicon.render())
} }
(self.stylesheet.prepare()) (self.stylesheet.render())
(self.javascript.prepare()) (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 self.regions
.all_in_region(self.theme, region.into().as_str()) .all_in_region(self.theme, &region.into())
.render(self) .render(self)
} }

View file

@ -1,6 +1,6 @@
use crate::core::package::PackageTrait; use crate::core::package::PackageTrait;
use crate::global; use crate::global;
use crate::html::{html, PrepareMarkup}; use crate::html::{html, Markup};
use crate::locale::L10n; use crate::locale::L10n;
use crate::response::page::Page; use crate::response::page::Page;
@ -12,9 +12,9 @@ pub trait ThemeTrait: PackageTrait + Send + Sync {
vec![("content", L10n::l("content"))] 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"; let viewport = "width=device-width, initial-scale=1, shrink-to-fit=no";
PrepareMarkup::With(html! { html! {
head { head {
meta charset="utf-8"; meta charset="utf-8";
@ -38,22 +38,22 @@ pub trait ThemeTrait: PackageTrait + Send + Sync {
meta property=(property) content=(content) {} meta property=(property) content=(content) {}
} }
(page.context().prepare_assets()) (page.context().render_assets())
} }
}) }
} }
#[allow(unused_variables)] #[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 { fn render_body(&self, page: &mut Page) -> Markup {
PrepareMarkup::With(html! { html! {
body id=[page.body_id().get()] class=[page.body_classes().get()] { body id=[page.body_id().get()] class=[page.body_classes().get()] {
(page.context().prepare_region("content")) (page.context().render_region("content"))
} }
}) }
} }
#[allow(unused_variables)] #[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 weight(&self) -> Weight;
fn prepare(&self) -> Markup; fn render(&self) -> Markup;
} }
#[derive(AutoDefault)] #[derive(AutoDefault)]
@ -41,12 +41,12 @@ impl<T: AssetsTrait> Assets<T> {
self self
} }
pub fn prepare(&mut self) -> Markup { pub fn render(&mut self) -> Markup {
let assets = &mut self.0; let assets = &mut self.0;
assets.sort_by_key(AssetsTrait::weight); assets.sort_by_key(AssetsTrait::weight);
html! { html! {
@for a in assets { @for a in assets {
(a.prepare()) (a.render())
} }
} }
} }

View file

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

View file

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

View file

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

View file

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