🧑💻 Replace "prepare" with "render" for better
This commit is contained in:
parent
80139d9153
commit
306cf5dc43
18 changed files with 40 additions and 70 deletions
|
|
@ -49,7 +49,7 @@ impl ComponentTrait for Block {
|
|||
h2 class="block-title" { (title) }
|
||||
}
|
||||
div class="block-body" {
|
||||
(self.components().prepare(cx))
|
||||
(self.components().render(cx))
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ impl ComponentTrait for Branding {
|
|||
div id=[self.id()] {
|
||||
div class="pt-branding__wrapper" {
|
||||
div class="pt-branding__logo" {
|
||||
(self.logo().prepare(cx))
|
||||
(self.logo().render(cx))
|
||||
}
|
||||
div class="pt-branding__text" {
|
||||
div class="pt-branding__name" {
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ impl ComponentTrait for Container {
|
|||
|
||||
PrepareMarkup::With(html! {
|
||||
div id=[self.id()] class=[self.classes().get()] style=[gap] {
|
||||
(self.items().prepare(cx))
|
||||
(self.items().render(cx))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ impl ComponentTrait for Item {
|
|||
PrepareMarkup::With(html! {
|
||||
div id=[self.id()] class=[self.item_classes().get()] style=[order] {
|
||||
div class=[self.inner_classes().get()] {
|
||||
(self.components().prepare(cx))
|
||||
(self.components().render(cx))
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ impl ComponentTrait for Form {
|
|||
method=[method]
|
||||
accept-charset=[self.charset().get()]
|
||||
{
|
||||
div { (self.elements().prepare(cx)) }
|
||||
div { (self.elements().render(cx)) }
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,10 +46,10 @@ impl ComponentTrait for Element {
|
|||
match self.element_type() {
|
||||
ElementType::Void => PrepareMarkup::None,
|
||||
ElementType::Html(content) => PrepareMarkup::With(html! {
|
||||
(content.prepare(cx))
|
||||
(content.render(cx))
|
||||
}),
|
||||
ElementType::Submenu(submenu) => PrepareMarkup::With(html! {
|
||||
(submenu.prepare(cx))
|
||||
(submenu.render(cx))
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ impl ComponentTrait for Group {
|
|||
fn prepare_component(&self, cx: &mut Context) -> PrepareMarkup {
|
||||
PrepareMarkup::With(html! {
|
||||
div id=[self.id()] class="menu-group" {
|
||||
(self.elements().prepare(cx))
|
||||
(self.elements().render(cx))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ impl ComponentTrait for Item {
|
|||
}),
|
||||
ItemType::Html(content) => PrepareMarkup::With(html! {
|
||||
li class="pt-menu__html" {
|
||||
(content.prepare(cx))
|
||||
(content.render(cx))
|
||||
}
|
||||
}),
|
||||
ItemType::Submenu(label, submenu) => PrepareMarkup::With(html! {
|
||||
|
|
@ -85,7 +85,7 @@ impl ComponentTrait for Item {
|
|||
(label.escaped(cx.langid())) i class="pt-menu__icon bi-chevron-down" {}
|
||||
}
|
||||
div class="pt-menu__subs" {
|
||||
(submenu.prepare(cx))
|
||||
(submenu.render(cx))
|
||||
}
|
||||
}
|
||||
}),
|
||||
|
|
@ -95,7 +95,7 @@ impl ComponentTrait for Item {
|
|||
(label.escaped(cx.langid())) i class="pt-menu__icon bi-chevron-down" {}
|
||||
}
|
||||
div class="pt-menu__subs pt-menu__mega" {
|
||||
(megamenu.prepare(cx))
|
||||
(megamenu.render(cx))
|
||||
}
|
||||
}
|
||||
}),
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ impl ComponentTrait for Megamenu {
|
|||
fn prepare_component(&self, cx: &mut Context) -> PrepareMarkup {
|
||||
PrepareMarkup::With(html! {
|
||||
div id=[self.id()] class="pt-menu__groups" {
|
||||
(self.groups().prepare(cx))
|
||||
(self.groups().render(cx))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ impl ComponentTrait for Menu {
|
|||
}
|
||||
}
|
||||
ul class="pt-menu__section" {
|
||||
(self.items().prepare(cx))
|
||||
(self.items().render(cx))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ impl ComponentTrait for Submenu {
|
|||
h4 class="pt-menu__title" { (title) }
|
||||
}
|
||||
ul {
|
||||
(self.items().prepare(cx))
|
||||
(self.items().render(cx))
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ impl ComponentTrait for Paragraph {
|
|||
id=[self.id()]
|
||||
class=[self.classes().get()]
|
||||
{
|
||||
(self.components().prepare(cx))
|
||||
(self.components().render(cx))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,34 +59,34 @@ impl ComponentTrait for Wrapper {
|
|||
WrapperType::Header => PrepareMarkup::With(html! {
|
||||
header id=[self.id()] class=[self.classes().get()] {
|
||||
div class=[self.inner_classes().get()] {
|
||||
(self.components().prepare(cx))
|
||||
(self.components().render(cx))
|
||||
}
|
||||
}
|
||||
}),
|
||||
WrapperType::Footer => PrepareMarkup::With(html! {
|
||||
footer id=[self.id()] class=[self.classes().get()] {
|
||||
div class=[self.inner_classes().get()] {
|
||||
(self.components().prepare(cx))
|
||||
(self.components().render(cx))
|
||||
}
|
||||
}
|
||||
}),
|
||||
WrapperType::Main => PrepareMarkup::With(html! {
|
||||
main id=[self.id()] class=[self.classes().get()] {
|
||||
div class=[self.inner_classes().get()] {
|
||||
(self.components().prepare(cx))
|
||||
(self.components().render(cx))
|
||||
}
|
||||
}
|
||||
}),
|
||||
WrapperType::Section => PrepareMarkup::With(html! {
|
||||
section id=[self.id()] class=[self.classes().get()] {
|
||||
div class=[self.inner_classes().get()] {
|
||||
(self.components().prepare(cx))
|
||||
(self.components().render(cx))
|
||||
}
|
||||
}
|
||||
}),
|
||||
_ => PrepareMarkup::With(html! {
|
||||
div id=[self.id()] class=[self.classes().get()] {
|
||||
(self.components().prepare(cx))
|
||||
(self.components().render(cx))
|
||||
}
|
||||
}),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,10 +61,10 @@ impl ArcComponent {
|
|||
self.0.read().unwrap().weight()
|
||||
}
|
||||
|
||||
// ArcComponent PREPARE.
|
||||
// ArcComponent RENDER.
|
||||
|
||||
pub fn prepare(&self, cx: &mut Context) -> Markup {
|
||||
self.0.write().unwrap().prepare(cx)
|
||||
pub fn render(&self, cx: &mut Context) -> Markup {
|
||||
self.0.write().unwrap().render(cx)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -150,14 +150,14 @@ impl ArcComponents {
|
|||
self.0.iter().filter(move |&c| c.handle() == handle)
|
||||
}
|
||||
|
||||
// ArcComponents PREPARE.
|
||||
// ArcComponents RENDER.
|
||||
|
||||
pub fn prepare(&self, cx: &mut Context) -> Markup {
|
||||
pub fn render(&self, cx: &mut Context) -> Markup {
|
||||
let mut components = self.0.clone();
|
||||
components.sort_by_key(|c| c.weight());
|
||||
html! {
|
||||
@for c in components.iter() {
|
||||
" " (c.prepare(cx)) " "
|
||||
" " (c.render(cx)) " "
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use crate::{util, Handle, Weight};
|
|||
use std::any::Any;
|
||||
|
||||
pub trait ComponentBase: Any {
|
||||
fn prepare(&mut self, cx: &mut Context) -> Markup;
|
||||
fn render(&mut self, cx: &mut Context) -> Markup;
|
||||
|
||||
fn as_ref_any(&self) -> &dyn Any;
|
||||
|
||||
|
|
@ -53,7 +53,7 @@ pub trait ComponentTrait: ComponentBase + Send + Sync {
|
|||
}
|
||||
|
||||
impl<C: ComponentTrait> ComponentBase for C {
|
||||
fn prepare(&mut self, cx: &mut Context) -> Markup {
|
||||
fn render(&mut self, cx: &mut Context) -> Markup {
|
||||
if self.is_renderable(cx) {
|
||||
// Acciones antes de preparar el componente.
|
||||
self.before_prepare_component(cx);
|
||||
|
|
@ -63,7 +63,11 @@ impl<C: ComponentTrait> ComponentBase for C {
|
|||
|
||||
let markup = match cx.theme().render_component(self, cx) {
|
||||
Some(html) => html,
|
||||
None => self.prepare_component(cx).html(),
|
||||
None => match self.prepare_component(cx) {
|
||||
PrepareMarkup::None => html! {},
|
||||
PrepareMarkup::Text(text) => html! { (text) },
|
||||
PrepareMarkup::With(html) => html,
|
||||
},
|
||||
};
|
||||
|
||||
// Acciones después de preparar el componente.
|
||||
|
|
|
|||
|
|
@ -46,10 +46,10 @@ impl<T: ComponentTrait + Default> TypedComponent<T> {
|
|||
self.0.read().unwrap().weight()
|
||||
}
|
||||
|
||||
// TypedComponent PREPARE.
|
||||
// TypedComponent RENDER.
|
||||
|
||||
pub fn prepare(&self, cx: &mut Context) -> Markup {
|
||||
self.0.write().unwrap().prepare(cx)
|
||||
pub fn render(&self, cx: &mut Context) -> Markup {
|
||||
self.0.write().unwrap().render(cx)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -127,14 +127,14 @@ impl<T: ComponentTrait + Default> TypedComponents<T> {
|
|||
self.0.iter().filter(move |&c| c.handle() == handle)
|
||||
}
|
||||
|
||||
// TypedComponents PREPARE.
|
||||
// TypedComponents RENDER.
|
||||
|
||||
pub fn prepare(&self, cx: &mut Context) -> Markup {
|
||||
pub fn render(&self, cx: &mut Context) -> Markup {
|
||||
let mut components = self.0.clone();
|
||||
components.sort_by_key(|c| c.weight());
|
||||
html! {
|
||||
@for c in components.iter() {
|
||||
" " (c.prepare(cx)) " "
|
||||
" " (c.render(cx)) " "
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ pub trait ThemeTrait: ModuleTrait + Send + Sync {
|
|||
}
|
||||
|
||||
fn prepare_region(&self, page: &mut Page, region: &str) -> Markup {
|
||||
let render_region = page.components_in(region).prepare(page.context());
|
||||
let render_region = page.components_in(region).render(page.context());
|
||||
if render_region.is_empty() {
|
||||
html! {}
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -35,37 +35,3 @@ pub enum PrepareMarkup {
|
|||
Text(&'static str),
|
||||
With(Markup),
|
||||
}
|
||||
|
||||
impl PrepareMarkup {
|
||||
pub fn html(self) -> Markup {
|
||||
match self {
|
||||
PrepareMarkup::None => html! {},
|
||||
PrepareMarkup::Text(text) => html! { (text) },
|
||||
PrepareMarkup::With(markup) => markup,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn into_string(self) -> Option<String> {
|
||||
match self {
|
||||
PrepareMarkup::None => None,
|
||||
PrepareMarkup::Text(text) => {
|
||||
if text.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(text.to_string())
|
||||
}
|
||||
}
|
||||
PrepareMarkup::With(markup) => Some(markup.into_string()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ToString for PrepareMarkup {
|
||||
fn to_string(&self) -> String {
|
||||
match self {
|
||||
PrepareMarkup::None => "".to_owned(),
|
||||
PrepareMarkup::Text(text) => text.to_string(),
|
||||
PrepareMarkup::With(markup) => markup.to_owned().into_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue