Ahora Block es un componente base de PageTop

This commit is contained in:
Manuel Cillero 2023-06-06 22:53:43 +02:00
parent cb735cf0fa
commit 35c221f1f8
5 changed files with 12 additions and 11 deletions

View file

@ -1,129 +0,0 @@
use pagetop::prelude::*;
define_handle!(COMPONENT_BLOCK);
action_before_render_component!(ACTION_BEFORE_RENDER_BLOCK, Block);
#[rustfmt::skip]
#[derive(Default)]
pub struct Block {
weight : isize,
renderable: Renderable,
id : IdentifierValue,
classes : Classes,
title : AttributeValue,
components: ComponentsBundle,
template : String,
}
impl ComponentTrait for Block {
fn new() -> Self {
Block::default().with_classes(ClassesOp::SetDefault, "block")
}
fn handle(&self) -> Handle {
COMPONENT_BLOCK
}
fn weight(&self) -> isize {
self.weight
}
fn is_renderable(&self, rcx: &RenderContext) -> bool {
(self.renderable.check)(rcx)
}
fn before_render(&mut self, rcx: &mut RenderContext) {
before_render_inline(self, rcx);
}
fn default_render(&self, rcx: &mut RenderContext) -> Markup {
let id = rcx.required_id::<Block>(self.id());
html! {
div id=(id) class=[self.classes().get()] {
@if let Some(title) = self.title().get() {
h2 class="block-title" { (title) }
}
div class="block-body" {
(self.components().render(rcx))
}
}
}
}
fn as_ref_any(&self) -> &dyn AnyComponent {
self
}
fn as_mut_any(&mut self) -> &mut dyn AnyComponent {
self
}
}
impl Block {
// Block BUILDER.
#[fn_builder]
pub fn alter_weight(&mut self, weight: isize) -> &mut Self {
self.weight = weight;
self
}
#[fn_builder]
pub fn alter_renderable(&mut self, check: IsRenderable) -> &mut Self {
self.renderable.check = check;
self
}
#[fn_builder]
pub fn alter_id(&mut self, id: &str) -> &mut Self {
self.id.alter_value(id);
self
}
#[fn_builder]
pub fn alter_classes(&mut self, op: ClassesOp, classes: &str) -> &mut Self {
self.classes.alter_value(op, classes);
self
}
#[fn_builder]
pub fn alter_title(&mut self, title: &str) -> &mut Self {
self.title.alter_value(title);
self
}
#[fn_builder]
pub fn alter_component(&mut self, component: impl ComponentTrait) -> &mut Self {
self.components.add(component);
self
}
#[fn_builder]
pub fn alter_template(&mut self, template: &str) -> &mut Self {
self.template = template.to_owned();
self
}
// Block GETTERS.
pub fn id(&self) -> &IdentifierValue {
&self.id
}
pub fn classes(&self) -> &Classes {
&self.classes
}
pub fn title(&self) -> &AttributeValue {
&self.title
}
pub fn components(&self) -> &ComponentsBundle {
&self.components
}
pub fn template(&self) -> &str {
self.template.as_str()
}
}