diff --git a/pagetop-admin/src/lib.rs b/pagetop-admin/src/lib.rs index bb9d70b0..c12421c3 100644 --- a/pagetop-admin/src/lib.rs +++ b/pagetop-admin/src/lib.rs @@ -1,6 +1,6 @@ use pagetop::prelude::*; -pub const ADMIN_MODULE: &str = "pagetop-admin::module::admin"; +pub const MODULE_ADMIN: &str = "pagetop-admin::module::admin"; localize!("src/locales"); @@ -10,7 +10,7 @@ pub struct Admin; impl ModuleTrait for Admin { fn handler(&self) -> &'static str { - ADMIN_MODULE + MODULE_ADMIN } fn name(&self) -> String { diff --git a/pagetop-node/src/lib.rs b/pagetop-node/src/lib.rs index 1662e625..bed7f9db 100644 --- a/pagetop-node/src/lib.rs +++ b/pagetop-node/src/lib.rs @@ -1,6 +1,6 @@ use pagetop::prelude::*; -pub const NODE_MODULE: &str = "pagetop-node::module::node"; +pub const MODULE_NODE: &str = "pagetop-node::module::node"; localize!("src/locales"); @@ -11,7 +11,7 @@ pub struct Node; impl ModuleTrait for Node { fn handler(&self) -> &'static str { - NODE_MODULE + MODULE_NODE } fn name(&self) -> String { diff --git a/pagetop-user/src/lib.rs b/pagetop-user/src/lib.rs index f1515419..d250adfc 100644 --- a/pagetop-user/src/lib.rs +++ b/pagetop-user/src/lib.rs @@ -1,6 +1,6 @@ use pagetop::prelude::*; -pub const USER_MODULE: &str = "pagetop-user::module::user"; +pub const MODULE_USER: &str = "pagetop-user::module::user"; localize!("src/locales"); @@ -10,7 +10,7 @@ pub struct User; impl ModuleTrait for User { fn handler(&self) -> &'static str { - USER_MODULE + MODULE_USER } fn name(&self) -> String { diff --git a/pagetop/src/base/component.rs b/pagetop/src/base/component.rs index b0fd2673..366c7ff3 100644 --- a/pagetop/src/base/component.rs +++ b/pagetop/src/base/component.rs @@ -1,44 +1,44 @@ mod container; pub use container::{ - CONTAINER_COMPONENT, Container, ContainerType + COMPONENT_CONTAINER, Container, ContainerType }; pub mod grid; mod chunck; pub use chunck::{ - CHUNCK_COMPONENT, Chunck + COMPONENT_CHUNCK, Chunck }; mod icon; pub use icon::{ - ICON_COMPONENT, Icon + COMPONENT_ICON, Icon }; mod heading; pub use heading::{ - HEADING_COMPONENT, Heading, HeadingDisplay, HeadingType + COMPONENT_HEADING, Heading, HeadingDisplay, HeadingType }; mod paragraph; pub use paragraph::{ - PARAGRAPH_COMPONENT, Paragraph, ParagraphDisplay + COMPONENT_PARAGRAPH, Paragraph, ParagraphDisplay }; mod anchor; pub use anchor::{ - ANCHOR_COMPONENT, Anchor, AnchorIcon, AnchorTarget, AnchorType + COMPONENT_ANCHOR, Anchor, AnchorIcon, AnchorTarget, AnchorType }; mod block; pub use block::{ - BLOCK_COMPONENT, Block + COMPONENT_BLOCK, Block }; mod image; pub use image::{ - IMAGE_COMPONENT, Image + COMPONENT_IMAGE, Image }; mod menu; pub use menu::{ - MENU_COMPONENT, MENUITEM_COMPONENT, Menu, MenuItem, MenuItemType + COMPONENT_MENU, COMPONENT_MENUITEM, Menu, MenuItem, MenuItemType }; pub mod form; pub use form::{ - FORM_COMPONENT, Form, FormMethod + COMPONENT_FORM, Form, FormMethod }; diff --git a/pagetop/src/base/component/anchor.rs b/pagetop/src/base/component/anchor.rs index 25c9a33e..26644db7 100644 --- a/pagetop/src/base/component/anchor.rs +++ b/pagetop/src/base/component/anchor.rs @@ -1,6 +1,6 @@ use crate::prelude::*; -pub const ANCHOR_COMPONENT: &str = "pagetop::component::anchor"; +pub const COMPONENT_ANCHOR: &str = "pagetop::component::anchor"; pub enum AnchorType { Button, @@ -50,17 +50,17 @@ impl ComponentTrait for Anchor { } fn handler(&self) -> &'static str { - ANCHOR_COMPONENT - } - - fn is_renderable(&self) -> bool { - (self.renderable)() + COMPONENT_ANCHOR } fn weight(&self) -> isize { self.weight } + fn is_renderable(&self, _: &InContext) -> bool { + (self.renderable)() + } + fn default_render(&self, context: &mut InContext) -> Markup { let target = match &self.target() { AnchorTarget::Blank => Some("_blank"), @@ -107,13 +107,13 @@ impl Anchor { // Anchor BUILDER. - pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self { - self.alter_renderable(renderable); + pub fn with_weight(mut self, weight: isize) -> Self { + self.alter_weight(weight); self } - pub fn with_weight(mut self, weight: isize) -> Self { - self.alter_weight(weight); + pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self { + self.alter_renderable(renderable); self } @@ -164,13 +164,13 @@ impl Anchor { // Anchor ALTER. - pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self { - self.renderable = renderable; + pub fn alter_weight(&mut self, weight: isize) -> &mut Self { + self.weight = weight; self } - pub fn alter_weight(&mut self, weight: isize) -> &mut Self { - self.weight = weight; + pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self { + self.renderable = renderable; self } diff --git a/pagetop/src/base/component/block.rs b/pagetop/src/base/component/block.rs index 7daf3ebe..fec21328 100644 --- a/pagetop/src/base/component/block.rs +++ b/pagetop/src/base/component/block.rs @@ -1,6 +1,6 @@ use crate::prelude::*; -pub const BLOCK_COMPONENT: &str = "pagetop::component::block"; +pub const COMPONENT_BLOCK: &str = "pagetop::component::block"; pub struct Block { renderable: fn() -> bool, @@ -26,17 +26,17 @@ impl ComponentTrait for Block { } fn handler(&self) -> &'static str { - BLOCK_COMPONENT - } - - fn is_renderable(&self) -> bool { - (self.renderable)() + COMPONENT_BLOCK } fn weight(&self) -> isize { self.weight } + fn is_renderable(&self, _: &InContext) -> bool { + (self.renderable)() + } + fn default_render(&self, context: &mut InContext) -> Markup { let id = context.required_id::(self.id()); html! { @@ -65,13 +65,13 @@ impl Block { // Block BUILDER. - pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self { - self.alter_renderable(renderable); + pub fn with_weight(mut self, weight: isize) -> Self { + self.alter_weight(weight); self } - pub fn with_weight(mut self, weight: isize) -> Self { - self.alter_weight(weight); + pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self { + self.alter_renderable(renderable); self } @@ -102,13 +102,13 @@ impl Block { // Block ALTER. - pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self { - self.renderable = renderable; + pub fn alter_weight(&mut self, weight: isize) -> &mut Self { + self.weight = weight; self } - pub fn alter_weight(&mut self, weight: isize) -> &mut Self { - self.weight = weight; + pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self { + self.renderable = renderable; self } diff --git a/pagetop/src/base/component/chunck.rs b/pagetop/src/base/component/chunck.rs index 1832a455..59d29b12 100644 --- a/pagetop/src/base/component/chunck.rs +++ b/pagetop/src/base/component/chunck.rs @@ -1,6 +1,6 @@ use crate::prelude::*; -pub const CHUNCK_COMPONENT: &str = "pagetop::component::chunck"; +pub const COMPONENT_CHUNCK: &str = "pagetop::component::chunck"; pub struct Chunck { renderable: fn() -> bool, @@ -20,17 +20,17 @@ impl ComponentTrait for Chunck { } fn handler(&self) -> &'static str { - CHUNCK_COMPONENT - } - - fn is_renderable(&self) -> bool { - (self.renderable)() + COMPONENT_CHUNCK } fn weight(&self) -> isize { self.weight } + fn is_renderable(&self, _: &InContext) -> bool { + (self.renderable)() + } + fn default_render(&self, _: &mut InContext) -> Markup { html! { (*self.html()) } } @@ -51,13 +51,13 @@ impl Chunck { // Chunck BUILDER. - pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self { - self.alter_renderable(renderable); + pub fn with_weight(mut self, weight: isize) -> Self { + self.alter_weight(weight); self } - pub fn with_weight(mut self, weight: isize) -> Self { - self.alter_weight(weight); + pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self { + self.alter_renderable(renderable); self } @@ -73,13 +73,13 @@ impl Chunck { // Chunck ALTER. - pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self { - self.renderable = renderable; + pub fn alter_weight(&mut self, weight: isize) -> &mut Self { + self.weight = weight; self } - pub fn alter_weight(&mut self, weight: isize) -> &mut Self { - self.weight = weight; + pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self { + self.renderable = renderable; self } diff --git a/pagetop/src/base/component/container.rs b/pagetop/src/base/component/container.rs index b1839901..94634943 100644 --- a/pagetop/src/base/component/container.rs +++ b/pagetop/src/base/component/container.rs @@ -1,6 +1,6 @@ use crate::prelude::*; -pub const CONTAINER_COMPONENT: &str = "pagetop::component::container"; +pub const COMPONENT_CONTAINER: &str = "pagetop::component::container"; pub enum ContainerType { Header, Footer, Main, Section, Wrapper } @@ -30,17 +30,17 @@ impl ComponentTrait for Container { } fn handler(&self) -> &'static str { - CONTAINER_COMPONENT - } - - fn is_renderable(&self) -> bool { - (self.renderable)() + COMPONENT_CONTAINER } fn weight(&self) -> isize { self.weight } + fn is_renderable(&self, _: &InContext) -> bool { + (self.renderable)() + } + fn default_render(&self, context: &mut InContext) -> Markup { match self.container_type() { ContainerType::Header => html! { @@ -115,13 +115,13 @@ impl Container { // Container BUILDER. - pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self { - self.alter_renderable(renderable); + pub fn with_weight(mut self, weight: isize) -> Self { + self.alter_weight(weight); self } - pub fn with_weight(mut self, weight: isize) -> Self { - self.alter_weight(weight); + pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self { + self.alter_renderable(renderable); self } @@ -152,13 +152,13 @@ impl Container { // Container ALTER. - pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self { - self.renderable = renderable; + pub fn alter_weight(&mut self, weight: isize) -> &mut Self { + self.weight = weight; self } - pub fn alter_weight(&mut self, weight: isize) -> &mut Self { - self.weight = weight; + pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self { + self.renderable = renderable; self } diff --git a/pagetop/src/base/component/form.rs b/pagetop/src/base/component/form.rs index 4e35a9d4..4b17e5c3 100644 --- a/pagetop/src/base/component/form.rs +++ b/pagetop/src/base/component/form.rs @@ -1,21 +1,21 @@ mod form; pub use form::{ - FORM_COMPONENT, Form, FormMethod + COMPONENT_FORM, Form, FormMethod }; mod input; pub use input::{ - INPUT_COMPONENT, Input, InputType + COMPONENT_INPUT, Input, InputType }; mod hidden; pub use hidden::{ - HIDDEN_COMPONENT, Hidden + COMPONENT_HIDDEN, Hidden }; mod date; pub use date::{ - DATE_COMPONENT, Date + COMPONENT_DATE, Date }; mod button; pub use button::{ - BUTTON_COMPONENT, Button, ButtonType + COMPONENT_BUTTON, Button, ButtonType }; diff --git a/pagetop/src/base/component/form/button.rs b/pagetop/src/base/component/form/button.rs index 6a01a1a3..e9ba40ec 100644 --- a/pagetop/src/base/component/form/button.rs +++ b/pagetop/src/base/component/form/button.rs @@ -1,6 +1,6 @@ use crate::prelude::*; -pub const BUTTON_COMPONENT: &str = "pagetop::component::form::button"; +pub const COMPONENT_BUTTON: &str = "pagetop::component::form::button"; pub enum ButtonType {Button, Reset, Submit} @@ -33,17 +33,17 @@ impl ComponentTrait for Button { } fn handler(&self) -> &'static str { - BUTTON_COMPONENT - } - - fn is_renderable(&self) -> bool { - (self.renderable)() + COMPONENT_BUTTON } fn weight(&self) -> isize { self.weight } + fn is_renderable(&self, _: &InContext) -> bool { + (self.renderable)() + } + fn default_render(&self, _: &mut InContext) -> Markup { let button_type = match self.button_type() { ButtonType::Button => "button", @@ -104,13 +104,13 @@ impl Button { // Button BUILDER. - pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self { - self.alter_renderable(renderable); + pub fn with_weight(mut self, weight: isize) -> Self { + self.alter_weight(weight); self } - pub fn with_weight(mut self, weight: isize) -> Self { - self.alter_weight(weight); + pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self { + self.alter_renderable(renderable); self } @@ -146,13 +146,13 @@ impl Button { // Button ALTER. - pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self { - self.renderable = renderable; + pub fn alter_weight(&mut self, weight: isize) -> &mut Self { + self.weight = weight; self } - pub fn alter_weight(&mut self, weight: isize) -> &mut Self { - self.weight = weight; + pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self { + self.renderable = renderable; self } diff --git a/pagetop/src/base/component/form/date.rs b/pagetop/src/base/component/form/date.rs index 1772e718..5151cead 100644 --- a/pagetop/src/base/component/form/date.rs +++ b/pagetop/src/base/component/form/date.rs @@ -1,6 +1,6 @@ use crate::prelude::*; -pub const DATE_COMPONENT: &str = "pagetop::component::form::date"; +pub const COMPONENT_DATE: &str = "pagetop::component::form::date"; pub struct Date { renderable : fn() -> bool, @@ -41,17 +41,17 @@ impl ComponentTrait for Date { } fn handler(&self) -> &'static str { - DATE_COMPONENT - } - - fn is_renderable(&self) -> bool { - (self.renderable)() + COMPONENT_DATE } fn weight(&self) -> isize { self.weight } + fn is_renderable(&self, _: &InContext) -> bool { + (self.renderable)() + } + fn default_render(&self, _: &mut InContext) -> Markup { let id = match self.name().get() { Some(name) => Some(concat_string!("edit-", name)), @@ -104,13 +104,13 @@ impl Date { // Date BUILDER. - pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self { - self.alter_renderable(renderable); + pub fn with_weight(mut self, weight: isize) -> Self { + self.alter_weight(weight); self } - pub fn with_weight(mut self, weight: isize) -> Self { - self.alter_weight(weight); + pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self { + self.alter_renderable(renderable); self } @@ -176,13 +176,13 @@ impl Date { // Date ALTER. - pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self { - self.renderable = renderable; + pub fn alter_weight(&mut self, weight: isize) -> &mut Self { + self.weight = weight; self } - pub fn alter_weight(&mut self, weight: isize) -> &mut Self { - self.weight = weight; + pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self { + self.renderable = renderable; self } diff --git a/pagetop/src/base/component/form/form.rs b/pagetop/src/base/component/form/form.rs index 65269ca4..17059a02 100644 --- a/pagetop/src/base/component/form/form.rs +++ b/pagetop/src/base/component/form/form.rs @@ -1,6 +1,6 @@ use crate::prelude::*; -pub const FORM_COMPONENT: &str = "pagetop::component::form"; +pub const COMPONENT_FORM: &str = "pagetop::component::form"; pub enum FormMethod {Get, Post} @@ -32,17 +32,17 @@ impl ComponentTrait for Form { } fn handler(&self) -> &'static str { - FORM_COMPONENT - } - - fn is_renderable(&self) -> bool { - (self.renderable)() + COMPONENT_FORM } fn weight(&self) -> isize { self.weight } + fn is_renderable(&self, _: &InContext) -> bool { + (self.renderable)() + } + fn default_render(&self, context: &mut InContext) -> Markup { let method = match self.method() { FormMethod::Get => None, @@ -74,13 +74,13 @@ impl Form { // Form BUILDER. - pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self { - self.alter_renderable(renderable); + pub fn with_weight(mut self, weight: isize) -> Self { + self.alter_weight(weight); self } - pub fn with_weight(mut self, weight: isize) -> Self { - self.alter_weight(weight); + pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self { + self.alter_renderable(renderable); self } @@ -121,13 +121,13 @@ impl Form { // Form ALTER. - pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self { - self.renderable = renderable; + pub fn alter_weight(&mut self, weight: isize) -> &mut Self { + self.weight = weight; self } - pub fn alter_weight(&mut self, weight: isize) -> &mut Self { - self.weight = weight; + pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self { + self.renderable = renderable; self } diff --git a/pagetop/src/base/component/form/hidden.rs b/pagetop/src/base/component/form/hidden.rs index 358e01ef..b233f7fe 100644 --- a/pagetop/src/base/component/form/hidden.rs +++ b/pagetop/src/base/component/form/hidden.rs @@ -1,6 +1,6 @@ use crate::prelude::*; -pub const HIDDEN_COMPONENT: &str = "pagetop::component::form::hidden"; +pub const COMPONENT_HIDDEN: &str = "pagetop::component::form::hidden"; pub struct Hidden { weight: isize, @@ -18,7 +18,7 @@ impl ComponentTrait for Hidden { } fn handler(&self) -> &'static str { - HIDDEN_COMPONENT + COMPONENT_HIDDEN } fn weight(&self) -> isize { diff --git a/pagetop/src/base/component/form/input.rs b/pagetop/src/base/component/form/input.rs index 0ee01c67..8dac6678 100644 --- a/pagetop/src/base/component/form/input.rs +++ b/pagetop/src/base/component/form/input.rs @@ -1,6 +1,6 @@ use crate::prelude::*; -pub const INPUT_COMPONENT: &str = "pagetop::component::form::input"; +pub const COMPONENT_INPUT: &str = "pagetop::component::form::input"; pub enum InputType {Email, Password, Search, Telephone, Textfield, Url} @@ -51,17 +51,17 @@ impl ComponentTrait for Input { } fn handler(&self) -> &'static str { - INPUT_COMPONENT - } - - fn is_renderable(&self) -> bool { - (self.renderable)() + COMPONENT_INPUT } fn weight(&self) -> isize { self.weight } + fn is_renderable(&self, _: &InContext) -> bool { + (self.renderable)() + } + fn default_render(&self, _: &mut InContext) -> Markup { let type_input = match self.input_type() { InputType::Email => "email", @@ -163,13 +163,13 @@ impl Input { // Input BUILDER. - pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self { - self.alter_renderable(renderable); + pub fn with_weight(mut self, weight: isize) -> Self { + self.alter_weight(weight); self } - pub fn with_weight(mut self, weight: isize) -> Self { - self.alter_weight(weight); + pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self { + self.alter_renderable(renderable); self } @@ -250,13 +250,13 @@ impl Input { // Input ALTER. - pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self { - self.renderable = renderable; + pub fn alter_weight(&mut self, weight: isize) -> &mut Self { + self.weight = weight; self } - pub fn alter_weight(&mut self, weight: isize) -> &mut Self { - self.weight = weight; + pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self { + self.renderable = renderable; self } diff --git a/pagetop/src/base/component/grid.rs b/pagetop/src/base/component/grid.rs index af88db55..17663df6 100644 --- a/pagetop/src/base/component/grid.rs +++ b/pagetop/src/base/component/grid.rs @@ -1,8 +1,8 @@ mod row; pub use row::{ - ROW_COMPONENT, Row + COMPONENT_ROW, Row }; mod column; pub use column::{ - COLUMN_COMPONENT, Column, ColumnSize + COMPONENT_COLUMN, Column, ColumnSize }; diff --git a/pagetop/src/base/component/grid/column.rs b/pagetop/src/base/component/grid/column.rs index 6fbc1989..5aabb947 100644 --- a/pagetop/src/base/component/grid/column.rs +++ b/pagetop/src/base/component/grid/column.rs @@ -1,6 +1,20 @@ use crate::prelude::*; -pub const COLUMN_COMPONENT: &str = "pagetop::component::grid::column"; +pub const COMPONENT_COLUMN: &str = "pagetop::component::grid::column"; + +const SIZE_DEFAULT: &str = "col-md"; +const SIZE_1_OF_12: &str = "col-md-1"; +const SIZE_2_OF_12: &str = "col-md-2"; +const SIZE_3_OF_12: &str = "col-md-3"; +const SIZE_4_OF_12: &str = "col-md-4"; +const SIZE_5_OF_12: &str = "col-md-5"; +const SIZE_6_OF_12: &str = "col-md-6"; +const SIZE_7_OF_12: &str = "col-md-7"; +const SIZE_8_OF_12: &str = "col-md-8"; +const SIZE_9_OF_12: &str = "col-md-9"; +const SIZE_10_OF_12: &str = "col-md-10"; +const SIZE_11_OF_12: &str = "col-md-11"; +const SIZE_12_OF_12: &str = "col-md-12"; pub enum ColumnSize { Default, @@ -33,7 +47,7 @@ impl ComponentTrait for Column { renderable: render_always, weight : 0, id : IdentifierValue::new(), - classes : Classes::new(), + classes : Classes::new_with_default(SIZE_DEFAULT), size : ColumnSize::Default, components: ComponentsBundle::new(), template : "default".to_owned(), @@ -41,33 +55,15 @@ impl ComponentTrait for Column { } fn handler(&self) -> &'static str { - COLUMN_COMPONENT - } - - fn is_renderable(&self) -> bool { - (self.renderable)() + COMPONENT_COLUMN } fn weight(&self) -> isize { self.weight } - fn before_render(&mut self, _context: &mut InContext) { - match self.size() { - ColumnSize::Default => self.alter_classes(ClassesOp::SetDefault, "col-md"), - ColumnSize::Is1of12 => self.alter_classes(ClassesOp::SetDefault, "col-md-1"), - ColumnSize::Is2of12 => self.alter_classes(ClassesOp::SetDefault, "col-md-2"), - ColumnSize::Is3of12 => self.alter_classes(ClassesOp::SetDefault, "col-md-3"), - ColumnSize::Is4of12 => self.alter_classes(ClassesOp::SetDefault, "col-md-4"), - ColumnSize::Is5of12 => self.alter_classes(ClassesOp::SetDefault, "col-md-5"), - ColumnSize::Is6of12 => self.alter_classes(ClassesOp::SetDefault, "col-md-6"), - ColumnSize::Is7of12 => self.alter_classes(ClassesOp::SetDefault, "col-md-7"), - ColumnSize::Is8of12 => self.alter_classes(ClassesOp::SetDefault, "col-md-8"), - ColumnSize::Is9of12 => self.alter_classes(ClassesOp::SetDefault, "col-md-9"), - ColumnSize::Is10of12 => self.alter_classes(ClassesOp::SetDefault, "col-md-10"), - ColumnSize::Is11of12 => self.alter_classes(ClassesOp::SetDefault, "col-md-11"), - ColumnSize::IsFull => self.alter_classes(ClassesOp::SetDefault, "col-md-12"), - }; + fn is_renderable(&self, _: &InContext) -> bool { + (self.renderable)() } fn default_render(&self, context: &mut InContext) -> Markup { @@ -91,13 +87,13 @@ impl Column { // Column BUILDER. - pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self { - self.alter_renderable(renderable); + pub fn with_weight(mut self, weight: isize) -> Self { + self.alter_weight(weight); self } - pub fn with_weight(mut self, weight: isize) -> Self { - self.alter_weight(weight); + pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self { + self.alter_renderable(renderable); self } @@ -128,13 +124,13 @@ impl Column { // Column ALTER. - pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self { - self.renderable = renderable; + pub fn alter_weight(&mut self, weight: isize) -> &mut Self { + self.weight = weight; self } - pub fn alter_weight(&mut self, weight: isize) -> &mut Self { - self.weight = weight; + pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self { + self.renderable = renderable; self } @@ -149,6 +145,21 @@ impl Column { } pub fn alter_size(&mut self, size: ColumnSize) -> &mut Self { + match size { + ColumnSize::Default => self.alter_classes(ClassesOp::SetDefault, SIZE_DEFAULT), + ColumnSize::Is1of12 => self.alter_classes(ClassesOp::SetDefault, SIZE_1_OF_12), + ColumnSize::Is2of12 => self.alter_classes(ClassesOp::SetDefault, SIZE_2_OF_12), + ColumnSize::Is3of12 => self.alter_classes(ClassesOp::SetDefault, SIZE_3_OF_12), + ColumnSize::Is4of12 => self.alter_classes(ClassesOp::SetDefault, SIZE_4_OF_12), + ColumnSize::Is5of12 => self.alter_classes(ClassesOp::SetDefault, SIZE_5_OF_12), + ColumnSize::Is6of12 => self.alter_classes(ClassesOp::SetDefault, SIZE_6_OF_12), + ColumnSize::Is7of12 => self.alter_classes(ClassesOp::SetDefault, SIZE_7_OF_12), + ColumnSize::Is8of12 => self.alter_classes(ClassesOp::SetDefault, SIZE_8_OF_12), + ColumnSize::Is9of12 => self.alter_classes(ClassesOp::SetDefault, SIZE_9_OF_12), + ColumnSize::Is10of12 => self.alter_classes(ClassesOp::SetDefault, SIZE_10_OF_12), + ColumnSize::Is11of12 => self.alter_classes(ClassesOp::SetDefault, SIZE_11_OF_12), + ColumnSize::IsFull => self.alter_classes(ClassesOp::SetDefault, SIZE_12_OF_12), + }; self.size = size; self } diff --git a/pagetop/src/base/component/grid/row.rs b/pagetop/src/base/component/grid/row.rs index 2681ae9b..2e67c6f4 100644 --- a/pagetop/src/base/component/grid/row.rs +++ b/pagetop/src/base/component/grid/row.rs @@ -1,6 +1,6 @@ use crate::prelude::*; -pub const ROW_COMPONENT: &str = "pagetop::component::grid::row"; +pub const COMPONENT_ROW: &str = "pagetop::component::grid::row"; pub struct Row { renderable: fn() -> bool, @@ -24,17 +24,17 @@ impl ComponentTrait for Row { } fn handler(&self) -> &'static str { - ROW_COMPONENT - } - - fn is_renderable(&self) -> bool { - (self.renderable)() + COMPONENT_ROW } fn weight(&self) -> isize { self.weight } + fn is_renderable(&self, _: &InContext) -> bool { + (self.renderable)() + } + fn default_render(&self, context: &mut InContext) -> Markup { html! { div id=[self.id().get()] class=[self.classes().get()] { @@ -56,13 +56,13 @@ impl Row { // Row BUILDER. - pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self { - self.alter_renderable(renderable); + pub fn with_weight(mut self, weight: isize) -> Self { + self.alter_weight(weight); self } - pub fn with_weight(mut self, weight: isize) -> Self { - self.alter_weight(weight); + pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self { + self.alter_renderable(renderable); self } @@ -88,13 +88,13 @@ impl Row { // Row ALTER. - pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self { - self.renderable = renderable; + pub fn alter_weight(&mut self, weight: isize) -> &mut Self { + self.weight = weight; self } - pub fn alter_weight(&mut self, weight: isize) -> &mut Self { - self.weight = weight; + pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self { + self.renderable = renderable; self } diff --git a/pagetop/src/base/component/heading.rs b/pagetop/src/base/component/heading.rs index 86094fb1..23fb0af1 100644 --- a/pagetop/src/base/component/heading.rs +++ b/pagetop/src/base/component/heading.rs @@ -1,6 +1,6 @@ use crate::prelude::*; -pub const HEADING_COMPONENT: &str = "pagetop::component::heading"; +pub const COMPONENT_HEADING: &str = "pagetop::component::heading"; pub enum HeadingType { H1, H2, H3, H4, H5, H6 } @@ -40,17 +40,17 @@ impl ComponentTrait for Heading { } fn handler(&self) -> &'static str { - HEADING_COMPONENT - } - - fn is_renderable(&self) -> bool { - (self.renderable)() + COMPONENT_HEADING } fn weight(&self) -> isize { self.weight } + fn is_renderable(&self, _: &InContext) -> bool { + (self.renderable)() + } + fn default_render(&self, _: &mut InContext) -> Markup { let id = self.id().get(); let classes = self.classes().get(); @@ -100,13 +100,13 @@ impl Heading { // Heading BUILDER. - pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self { - self.alter_renderable(renderable); + pub fn with_weight(mut self, weight: isize) -> Self { + self.alter_weight(weight); self } - pub fn with_weight(mut self, weight: isize) -> Self { - self.alter_weight(weight); + pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self { + self.alter_renderable(renderable); self } @@ -142,13 +142,13 @@ impl Heading { // Heading ALTER. - pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self { - self.renderable = renderable; + pub fn alter_weight(&mut self, weight: isize) -> &mut Self { + self.weight = weight; self } - pub fn alter_weight(&mut self, weight: isize) -> &mut Self { - self.weight = weight; + pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self { + self.renderable = renderable; self } diff --git a/pagetop/src/base/component/icon.rs b/pagetop/src/base/component/icon.rs index e3f2ede0..a45ebf20 100644 --- a/pagetop/src/base/component/icon.rs +++ b/pagetop/src/base/component/icon.rs @@ -1,6 +1,6 @@ use crate::prelude::*; -pub const ICON_COMPONENT: &str = "pagetop::component::icon"; +pub const COMPONENT_ICON: &str = "pagetop::component::icon"; pub struct Icon { renderable: fn() -> bool, @@ -15,33 +15,29 @@ impl ComponentTrait for Icon { renderable: render_always, weight : 0, icon_name : "question-circle-fill".to_owned(), - classes : Classes::new(), + classes : Classes::new_with_default("bi-question-circle-fill"), } } fn handler(&self) -> &'static str { - ICON_COMPONENT - } - - fn is_renderable(&self) -> bool { - (self.renderable)() + COMPONENT_ICON } fn weight(&self) -> isize { self.weight } - fn before_render(&mut self, context: &mut InContext) { + fn is_renderable(&self, _: &InContext) -> bool { + (self.renderable)() + } + + fn default_render(&self, context: &mut InContext) -> Markup { context .alter(InContextOp::StyleSheet(AssetsOp::Add( StyleSheet::located("/theme/icons/bootstrap-icons.css") .with_version("1.8.2") ))); - self.alter_classes(ClassesOp::SetDefault, concat_string!("bi-", self.icon_name()).as_str()); - } - - fn default_render(&self, _context: &mut InContext) -> Markup { html! { i class=[self.classes().get()] {}; } } @@ -61,13 +57,13 @@ impl Icon { // Icon BUILDER. - pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self { - self.alter_renderable(renderable); + pub fn with_weight(mut self, weight: isize) -> Self { + self.alter_weight(weight); self } - pub fn with_weight(mut self, weight: isize) -> Self { - self.alter_weight(weight); + pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self { + self.alter_renderable(renderable); self } @@ -83,18 +79,19 @@ impl Icon { // Icon ALTER. - pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self { - self.renderable = renderable; - self - } - pub fn alter_weight(&mut self, weight: isize) -> &mut Self { self.weight = weight; self } + pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self { + self.renderable = renderable; + self + } + pub fn alter_icon_name(&mut self, name: &str) -> &mut Self { self.icon_name = name.to_owned(); + self.alter_classes(ClassesOp::SetDefault, concat_string!("bi-", self.icon_name).as_str()); self } diff --git a/pagetop/src/base/component/image.rs b/pagetop/src/base/component/image.rs index a7cccdf2..8a28aba9 100644 --- a/pagetop/src/base/component/image.rs +++ b/pagetop/src/base/component/image.rs @@ -1,6 +1,6 @@ use crate::prelude::*; -pub const IMAGE_COMPONENT: &str = "pagetop::component::image"; +pub const COMPONENT_IMAGE: &str = "pagetop::component::image"; pub struct Image { renderable: fn() -> bool, @@ -24,17 +24,17 @@ impl ComponentTrait for Image { } fn handler(&self) -> &'static str { - IMAGE_COMPONENT - } - - fn is_renderable(&self) -> bool { - (self.renderable)() + COMPONENT_IMAGE } fn weight(&self) -> isize { self.weight } + fn is_renderable(&self, _: &InContext) -> bool { + (self.renderable)() + } + fn default_render(&self, _: &mut InContext) -> Markup { html! { img @@ -60,13 +60,13 @@ impl Image { // Image BUILDER. - pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self { - self.alter_renderable(renderable); + pub fn with_weight(mut self, weight: isize) -> Self { + self.alter_weight(weight); self } - pub fn with_weight(mut self, weight: isize) -> Self { - self.alter_weight(weight); + pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self { + self.alter_renderable(renderable); self } @@ -92,13 +92,13 @@ impl Image { // Image ALTER. - pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self { - self.renderable = renderable; + pub fn alter_weight(&mut self, weight: isize) -> &mut Self { + self.weight = weight; self } - pub fn alter_weight(&mut self, weight: isize) -> &mut Self { - self.weight = weight; + pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self { + self.renderable = renderable; self } diff --git a/pagetop/src/base/component/menu.rs b/pagetop/src/base/component/menu.rs index c0c8a0b3..cef6abee 100644 --- a/pagetop/src/base/component/menu.rs +++ b/pagetop/src/base/component/menu.rs @@ -1,7 +1,7 @@ use crate::prelude::*; -pub const MENU_COMPONENT: &str = "pagetop::component::menu"; -pub const MENUITEM_COMPONENT: &str = "pagetop::component::menu_item"; +pub const COMPONENT_MENU: &str = "pagetop::component::menu"; +pub const COMPONENT_MENUITEM: &str = "pagetop::component::menu_item"; pub enum MenuItemType { Label(String), @@ -31,17 +31,17 @@ impl ComponentTrait for MenuItem { } fn handler(&self) -> &'static str { - MENUITEM_COMPONENT - } - - fn is_renderable(&self) -> bool { - (self.renderable)() + COMPONENT_MENUITEM } fn weight(&self) -> isize { self.weight } + fn is_renderable(&self, _: &InContext) -> bool { + (self.renderable)() + } + fn default_render(&self, context: &mut InContext) -> Markup { match self.item_type() { MenuItemType::Label(label) => html! { @@ -142,28 +142,28 @@ impl MenuItem { // MenuItem BUILDER. - pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self { - self.alter_renderable(renderable); - self - } - pub fn with_weight(mut self, weight: isize) -> Self { self.alter_weight(weight); self } - // MenuItem ALTER. - - pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self { - self.renderable = renderable; + pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self { + self.alter_renderable(renderable); self } + // MenuItem ALTER. + pub fn alter_weight(&mut self, weight: isize) -> &mut Self { self.weight = weight; self } + pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self { + self.renderable = renderable; + self + } + // MenuItem GETTERS. pub fn item_type(&self) -> &MenuItemType { @@ -195,18 +195,18 @@ impl ComponentTrait for Menu { } fn handler(&self) -> &'static str { - MENU_COMPONENT - } - - fn is_renderable(&self) -> bool { - (self.renderable)() + COMPONENT_MENU } fn weight(&self) -> isize { self.weight } - fn before_render(&mut self, context: &mut InContext) { + fn is_renderable(&self, _: &InContext) -> bool { + (self.renderable)() + } + + fn default_render(&self, context: &mut InContext) -> Markup { context .alter(InContextOp::StyleSheet(AssetsOp::Add( StyleSheet::located("/theme/menu/css/menu.css") @@ -221,10 +221,9 @@ impl ComponentTrait for Menu { .with_version("1.1.1") ))) .alter(InContextOp::AddJQuery); - } - fn default_render(&self, context: &mut InContext) -> Markup { let id = context.required_id::(self.id()); + html! { ul id=(id) class=[self.classes().get()] { (self.items().render(context)) @@ -251,13 +250,13 @@ impl Menu { // Menu BUILDER. - pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self { - self.alter_renderable(renderable); + pub fn with_weight(mut self, weight: isize) -> Self { + self.alter_weight(weight); self } - pub fn with_weight(mut self, weight: isize) -> Self { - self.alter_weight(weight); + pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self { + self.alter_renderable(renderable); self } @@ -283,13 +282,13 @@ impl Menu { // Menu ALTER. - pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self { - self.renderable = renderable; + pub fn alter_weight(&mut self, weight: isize) -> &mut Self { + self.weight = weight; self } - pub fn alter_weight(&mut self, weight: isize) -> &mut Self { - self.weight = weight; + pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self { + self.renderable = renderable; self } diff --git a/pagetop/src/base/component/paragraph.rs b/pagetop/src/base/component/paragraph.rs index 564710cc..6329b312 100644 --- a/pagetop/src/base/component/paragraph.rs +++ b/pagetop/src/base/component/paragraph.rs @@ -1,6 +1,6 @@ use crate::prelude::*; -pub const PARAGRAPH_COMPONENT: &str = "pagetop::component::paragraph"; +pub const COMPONENT_PARAGRAPH: &str = "pagetop::component::paragraph"; pub enum ParagraphDisplay { XxLarge, @@ -35,17 +35,17 @@ impl ComponentTrait for Paragraph { } fn handler(&self) -> &'static str { - PARAGRAPH_COMPONENT - } - - fn is_renderable(&self) -> bool { - (self.renderable)() + COMPONENT_PARAGRAPH } fn weight(&self) -> isize { self.weight } + fn is_renderable(&self, _: &InContext) -> bool { + (self.renderable)() + } + fn default_render(&self, _: &mut InContext) -> Markup { html! { p id=[self.id().get()] class=[self.classes().get()] { (*self.html()) } @@ -68,13 +68,13 @@ impl Paragraph { // Paragraph BUILDER. - pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self { - self.alter_renderable(renderable); + pub fn with_weight(mut self, weight: isize) -> Self { + self.alter_weight(weight); self } - pub fn with_weight(mut self, weight: isize) -> Self { - self.alter_weight(weight); + pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self { + self.alter_renderable(renderable); self } @@ -105,13 +105,13 @@ impl Paragraph { // Paragraph ALTER. - pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self { - self.renderable = renderable; + pub fn alter_weight(&mut self, weight: isize) -> &mut Self { + self.weight = weight; self } - pub fn alter_weight(&mut self, weight: isize) -> &mut Self { - self.weight = weight; + pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self { + self.renderable = renderable; self } diff --git a/pagetop/src/base/module/demopage.rs b/pagetop/src/base/module/demopage.rs index ac9e120e..b02f8603 100644 --- a/pagetop/src/base/module/demopage.rs +++ b/pagetop/src/base/module/demopage.rs @@ -1,6 +1,6 @@ use crate::prelude::*; -pub const DEMOPAGE_MODULE: &str = "pagetop::module::demopage"; +pub const MODULE_DEMOPAGE: &str = "pagetop::module::demopage"; localize!("src/base/module/demopage/locales"); @@ -8,7 +8,7 @@ pub struct Demopage; impl ModuleTrait for Demopage { fn handler(&self) -> &'static str { - DEMOPAGE_MODULE + MODULE_DEMOPAGE } fn name(&self) -> String { @@ -27,6 +27,9 @@ impl ModuleTrait for Demopage { async fn demo() -> app::Result { Page::new() .with_title(l("page_title").as_str()) + .with_context(InContextOp::StyleSheet(AssetsOp::Add( + StyleSheet::located("/theme/module/demopage/styles.css") + ))) .add_to("content", hello_world()) .add_to("content", welcome()) .add_to("content", about_pagetop()) @@ -40,6 +43,7 @@ fn hello_world() -> Container { .with_id("hello-world") .with_component(grid::Row::new() .with_column(grid::Column::new() + .with_classes(ClassesOp::Add, "hello-col-text") .with_size(grid::ColumnSize::Is4of12) .with_component(Heading::h1(html! { (l("page_title")) @@ -63,6 +67,7 @@ fn hello_world() -> Container { ("Offered services") }) .with_left_icon(Icon::with("card-checklist")) + .with_classes(ClassesOp::Add, "services-link") ) .with_component(Anchor::button("#", html! { ("Get quote") @@ -71,6 +76,7 @@ fn hello_world() -> Container { ) ) .with_column(grid::Column::new() + .with_classes(ClassesOp::Add, "hello-col-image") .with_component(Image::image("/theme/images/demo-header.svg")) ) ) @@ -78,13 +84,15 @@ fn hello_world() -> Container { fn welcome() -> Container { Container::new() - .with_id("visiting") + .with_id("welcome") .with_component(grid::Row::new() .with_column(grid::Column::new() + .with_classes(ClassesOp::Add, "welcome-col-image") .with_size(grid::ColumnSize::Is5of12) .with_component(Image::image("/theme/images/demo-visiting.svg")) ) .with_column(grid::Column::new() + .with_classes(ClassesOp::Add, "welcome-col-text") .with_component(Heading::h2(html! { (t("welcome_to", &args!["app" => SETTINGS.app.name.as_str()])) })) diff --git a/pagetop/src/base/theme/aliner.rs b/pagetop/src/base/theme/aliner.rs index e7a76922..de6bc60f 100644 --- a/pagetop/src/base/theme/aliner.rs +++ b/pagetop/src/base/theme/aliner.rs @@ -1,6 +1,6 @@ use crate::prelude::*; -pub const ALINER_THEME: &str = "pagetop::theme::aliner"; +pub const THEME_ALINER: &str = "pagetop::theme::aliner"; include!(concat!(env!("OUT_DIR"), "/aliner.rs")); @@ -8,7 +8,7 @@ pub struct Aliner; impl ThemeTrait for Aliner { fn handler(&self) -> &'static str { - ALINER_THEME + THEME_ALINER } fn configure_service(&self, cfg: &mut app::web::ServiceConfig) { diff --git a/pagetop/src/base/theme/bootsier.rs b/pagetop/src/base/theme/bootsier.rs index 582a5499..4ba21119 100644 --- a/pagetop/src/base/theme/bootsier.rs +++ b/pagetop/src/base/theme/bootsier.rs @@ -1,6 +1,6 @@ use crate::prelude::*; -pub const BOOTSIER_THEME: &str = "pagetop::theme::bootsier"; +pub const THEME_BOOTSIER: &str = "pagetop::theme::bootsier"; include!(concat!(env!("OUT_DIR"), "/bootsier.rs")); @@ -10,7 +10,7 @@ pub struct Bootsier; impl ThemeTrait for Bootsier { fn handler(&self) -> &'static str { - BOOTSIER_THEME + THEME_BOOTSIER } fn configure_service(&self, cfg: &mut app::web::ServiceConfig) { diff --git a/pagetop/src/base/theme/bulmix.rs b/pagetop/src/base/theme/bulmix.rs index e46d601a..fda612a9 100644 --- a/pagetop/src/base/theme/bulmix.rs +++ b/pagetop/src/base/theme/bulmix.rs @@ -1,6 +1,6 @@ use crate::prelude::*; -pub const BULMIX_THEME: &str = "pagetop::theme::bulmix"; +pub const THEME_BULMIX: &str = "pagetop::theme::bulmix"; include!(concat!(env!("OUT_DIR"), "/bulmix.rs")); @@ -8,7 +8,7 @@ pub struct Bulmix; impl ThemeTrait for Bulmix { fn handler(&self) -> &'static str { - BULMIX_THEME + THEME_BULMIX } fn configure_service(&self, cfg: &mut app::web::ServiceConfig) { @@ -34,14 +34,14 @@ impl ThemeTrait for Bulmix { _context: &mut InContext ) { match component.handler() { - ANCHOR_COMPONENT => { + COMPONENT_ANCHOR => { let a = component_mut::(component); a.alter_classes(ClassesOp::SetDefault, match a.anchor_type() { AnchorType::Button => "button is-primary", _ => "", }); }, - HEADING_COMPONENT => { + COMPONENT_HEADING => { let h = component_mut::(component); h.alter_classes(ClassesOp::SetDefault, match h.display() { HeadingDisplay::XxLarge => "title is-1", @@ -53,7 +53,7 @@ impl ThemeTrait for Bulmix { HeadingDisplay::Subtitle => "subtitle", }); }, - PARAGRAPH_COMPONENT => { + COMPONENT_PARAGRAPH => { let p = component_mut::(component); p.alter_classes(ClassesOp::SetDefault, match p.display() { ParagraphDisplay::XxLarge => "is-size-2", @@ -64,7 +64,7 @@ impl ThemeTrait for Bulmix { ParagraphDisplay::Normal => "", }); }, - grid::COLUMN_COMPONENT => { + grid::COMPONENT_COLUMN => { let col = component_mut::(component); col.alter_classes(ClassesOp::SetDefault, concat_string!("column", match col.size() { grid::ColumnSize::Default => "", @@ -82,7 +82,7 @@ impl ThemeTrait for Bulmix { grid::ColumnSize::IsFull => " is-12", }, " content").as_str()); }, - grid::ROW_COMPONENT => { + grid::COMPONENT_ROW => { let row = component_mut::(component); row.alter_classes(ClassesOp::SetDefault, "columns"); }, @@ -96,7 +96,7 @@ impl ThemeTrait for Bulmix { _context: &mut InContext ) -> Option { match component.handler() { - ICON_COMPONENT => { + COMPONENT_ICON => { let icon = component_ref::(component); Some(html! { span class="icon" { diff --git a/pagetop/src/base/theme/minimal.rs b/pagetop/src/base/theme/minimal.rs index e86e1719..bcdbe8cf 100644 --- a/pagetop/src/base/theme/minimal.rs +++ b/pagetop/src/base/theme/minimal.rs @@ -1,11 +1,11 @@ use crate::prelude::*; -pub const MINIMAL_THEME: &str = "pagetop::theme::minimal"; +pub const THEME_MINIMAL: &str = "pagetop::theme::minimal"; pub struct Minimal; impl ThemeTrait for Minimal { fn handler(&self) -> &'static str { - MINIMAL_THEME + THEME_MINIMAL } } diff --git a/pagetop/src/core/component.rs b/pagetop/src/core/component.rs index 3e3c9dec..adcf0192 100644 --- a/pagetop/src/core/component.rs +++ b/pagetop/src/core/component.rs @@ -1,6 +1,6 @@ mod hook; pub use hook::{ - BEFORE_RENDER_COMPONENT_HOOK, + HOOK_BEFORE_RENDER_COMPONENT, BeforeRenderComponentHook, }; diff --git a/pagetop/src/core/component/context.rs b/pagetop/src/core/component/context.rs index 3f9de74a..6d3f8dc5 100644 --- a/pagetop/src/core/component/context.rs +++ b/pagetop/src/core/component/context.rs @@ -12,9 +12,9 @@ static DEFAULT_THEME: Lazy<&dyn ThemeTrait> = Lazy::new(|| { }); pub enum InContextOp { + SetTheme(&'static str), AddMetadata(&'static str, &'static str), Favicon(Option), - SetTheme(&'static str), StyleSheet(AssetsOp), JavaScript(AssetsOp), AddJQuery, @@ -45,15 +45,15 @@ impl InContext { pub fn alter(&mut self, op: InContextOp) -> &mut Self { match op { + InContextOp::SetTheme(theme_name) => { + self.theme = theme_by_single_name(theme_name).unwrap_or(*DEFAULT_THEME); + }, InContextOp::AddMetadata(name, content) => { self.metadata.push((name.to_owned(), content.to_owned())); }, InContextOp::Favicon(favicon) => { self.favicon = favicon; }, - InContextOp::SetTheme(theme_name) => { - self.theme = theme_by_single_name(theme_name).unwrap_or(*DEFAULT_THEME); - }, InContextOp::StyleSheet(css) => { self.stylesheets.alter(css); }, diff --git a/pagetop/src/core/component/definition.rs b/pagetop/src/core/component/definition.rs index bf88f4cd..787561b3 100644 --- a/pagetop/src/core/component/definition.rs +++ b/pagetop/src/core/component/definition.rs @@ -1,7 +1,7 @@ use crate::util; use crate::html::{Markup, html}; use crate::core::hook::{hook_ref, run_hooks}; -use super::{BEFORE_RENDER_COMPONENT_HOOK, BeforeRenderComponentHook, InContext}; +use super::{HOOK_BEFORE_RENDER_COMPONENT, BeforeRenderComponentHook, InContext}; pub use std::any::Any as AnyComponent; @@ -18,16 +18,13 @@ pub trait ComponentTrait: AnyComponent + Send + Sync { None } - fn is_renderable(&self) -> bool { - true - } - fn weight(&self) -> isize { 0 } #[allow(unused_variables)] - fn before_render(&mut self, context: &mut InContext) { + fn is_renderable(&self, context: &InContext) -> bool { + true } #[allow(unused_variables)] @@ -49,19 +46,16 @@ pub fn component_mut(component: &mut dyn ComponentTrait) -> &mut C { } pub fn render_component(component: &mut dyn ComponentTrait, context: &mut InContext) -> Markup { - // Acciones del propio componente antes de renderizarlo. - component.before_render(context); - // Acciones de los módulos antes de renderizar el componente. run_hooks( - BEFORE_RENDER_COMPONENT_HOOK, + HOOK_BEFORE_RENDER_COMPONENT, |hook| hook_ref::(&**hook).run(component, context) ); // Acciones del tema antes de renderizar el componente. context.theme().before_render_component(component, context); - match component.is_renderable() { + match component.is_renderable(context) { true => match context.theme().render_component(component, context) { Some(html) => html, None => component.default_render(context) diff --git a/pagetop/src/core/component/hook.rs b/pagetop/src/core/component/hook.rs index 82d1ba01..d95d1cdf 100644 --- a/pagetop/src/core/component/hook.rs +++ b/pagetop/src/core/component/hook.rs @@ -1,7 +1,7 @@ use crate::core::hook::{HookTrait, AnyHook}; use super::{ComponentTrait, InContext}; -pub const BEFORE_RENDER_COMPONENT_HOOK: &str = "pagetop::hook::before_render_component"; +pub const HOOK_BEFORE_RENDER_COMPONENT: &str = "pagetop::hook::before_render_component"; pub struct BeforeRenderComponentHook { hook: Option, @@ -17,7 +17,7 @@ impl HookTrait for BeforeRenderComponentHook { } fn handler(&self) -> &'static str { - BEFORE_RENDER_COMPONENT_HOOK + HOOK_BEFORE_RENDER_COMPONENT } fn weight(&self) -> isize { diff --git a/pagetop/src/response/page.rs b/pagetop/src/response/page.rs index 5f517471..d3def8df 100644 --- a/pagetop/src/response/page.rs +++ b/pagetop/src/response/page.rs @@ -1,6 +1,6 @@ mod hook; pub use hook::{ - BEFORE_RENDER_PAGE_HOOK, + HOOK_BEFORE_RENDER_PAGE, BeforeRenderPageHook, }; diff --git a/pagetop/src/response/page/definition.rs b/pagetop/src/response/page/definition.rs index 95362453..322c6e77 100644 --- a/pagetop/src/response/page/definition.rs +++ b/pagetop/src/response/page/definition.rs @@ -3,7 +3,7 @@ use crate::config::SETTINGS; use crate::html::*; use crate::core::hook::{hook_ref, run_hooks}; use crate::core::component::*; -use super::{BEFORE_RENDER_PAGE_HOOK, BeforeRenderPageHook}; +use super::{HOOK_BEFORE_RENDER_PAGE, BeforeRenderPageHook}; use std::collections::HashMap; @@ -194,7 +194,7 @@ impl Page { pub fn render(&mut self) -> app::Result { // Acciones de los módulos antes de renderizar la página. run_hooks( - BEFORE_RENDER_PAGE_HOOK, + HOOK_BEFORE_RENDER_PAGE, |hook| hook_ref::(&**hook).run(self) ); diff --git a/pagetop/src/response/page/hook.rs b/pagetop/src/response/page/hook.rs index d482fb56..e094c9ca 100644 --- a/pagetop/src/response/page/hook.rs +++ b/pagetop/src/response/page/hook.rs @@ -1,7 +1,7 @@ use crate::core::hook::{HookTrait, AnyHook}; use super::Page; -pub const BEFORE_RENDER_PAGE_HOOK: &str = "pagetop::hook::before_render_page"; +pub const HOOK_BEFORE_RENDER_PAGE: &str = "pagetop::hook::before_render_page"; pub struct BeforeRenderPageHook { hook: Option, @@ -17,7 +17,7 @@ impl HookTrait for BeforeRenderPageHook { } fn handler(&self) -> &'static str { - BEFORE_RENDER_PAGE_HOOK + HOOK_BEFORE_RENDER_PAGE } fn weight(&self) -> isize { diff --git a/pagetop/static/theme/module/demopage/styles.css b/pagetop/static/theme/module/demopage/styles.css new file mode 100644 index 00000000..956f49e7 --- /dev/null +++ b/pagetop/static/theme/module/demopage/styles.css @@ -0,0 +1,30 @@ +#hello-world { + padding: 2em 5%; +} +#hello-world a { + margin: .25em; +} +#hello-world a.services-link { + padding-left: 1.5em; + padding-right: 1.5em; + border-radius: 1.5em; +} +#welcome { + padding: 1em 5%; +} +#welcome .welcome-col-text { + padding-left: 5%; +} +/* Responsiveness */ +@media (max-width: 992px) { + #hello-world .hello-col-text { + text-align: center; + } + #hello-world .hello-col-image { + padding-top: 5%; + } + #welcome .welcome-col-text { + text-align: center; + padding-left: 0; + } +} \ No newline at end of file