diff --git a/pagetop/Cargo.toml b/pagetop/Cargo.toml index a260d17f..514ab6e9 100644 --- a/pagetop/Cargo.toml +++ b/pagetop/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pagetop" -version = "0.0.4" +version = "0.0.5" edition = "2021" authors = [ diff --git a/pagetop/src/base/component/block.rs b/pagetop/src/base/component/block.rs index b857712f..5e5a7159 100644 --- a/pagetop/src/base/component/block.rs +++ b/pagetop/src/base/component/block.rs @@ -3,8 +3,8 @@ use crate::prelude::*; pub struct Block { renderable: fn() -> bool, weight : i8, - id : OptionId, - title : OptionAttr, + id : OptIden, + title : OptAttr, html : Vec, template : String, } @@ -15,8 +15,8 @@ impl PageComponent for Block { Block { renderable: always, weight : 0, - id : OptionId::none(), - title : OptionAttr::none(), + id : OptIden::none(), + title : OptAttr::none(), html : Vec::new(), template : "default".to_owned(), } diff --git a/pagetop/src/base/component/container.rs b/pagetop/src/base/component/container.rs index 18d6337a..e76b48b4 100644 --- a/pagetop/src/base/component/container.rs +++ b/pagetop/src/base/component/container.rs @@ -5,7 +5,7 @@ enum ContainerType { Header, Footer, Main, Section, Wrapper } pub struct Container { renderable: fn() -> bool, weight : i8, - id : OptionId, + id : OptIden, container : ContainerType, components: PageContainer, template : String, @@ -17,7 +17,7 @@ impl PageComponent for Container { Container { renderable: always, weight : 0, - id : OptionId::none(), + id : OptIden::none(), container : ContainerType::Wrapper, components: PageContainer::new(), template : "default".to_owned(), diff --git a/pagetop/src/base/component/form/button.rs b/pagetop/src/base/component/form/button.rs index a1975ea4..fa9794f2 100644 --- a/pagetop/src/base/component/form/button.rs +++ b/pagetop/src/base/component/form/button.rs @@ -6,10 +6,10 @@ pub struct Button { renderable : fn() -> bool, weight : i8, button_type: ButtonType, - name : OptionAttr, - value : OptionAttr, - autofocus : OptionAttr, - disabled : OptionAttr, + name : OptAttr, + value : OptAttr, + autofocus : OptAttr, + disabled : OptAttr, template : String, } @@ -20,10 +20,10 @@ impl PageComponent for Button { renderable : always, weight : 0, button_type: ButtonType::Button, - name : OptionAttr::none(), - value : OptionAttr::none(), - autofocus : OptionAttr::none(), - disabled : OptionAttr::none(), + name : OptAttr::none(), + value : OptAttr::none(), + autofocus : OptAttr::none(), + disabled : OptAttr::none(), template : "default".to_owned(), } } @@ -42,14 +42,14 @@ impl PageComponent for Button { ButtonType::Reset => ("reset", "btn btn-primary form-reset" ), ButtonType::Submit => ("submit", "btn btn-primary form-submit") }; - let id_item = match &self.name.option() { + let id = match &self.name.option() { Some(name) => Some(format!("edit-{}", name)), _ => None }; html! { button type=(button_type) - id=[&id_item] + id=[&id] class=(button_class) name=[&self.name.option()] value=[&self.value.option()] diff --git a/pagetop/src/base/component/form/date.rs b/pagetop/src/base/component/form/date.rs index 7f04691b..5e42bc6b 100644 --- a/pagetop/src/base/component/form/date.rs +++ b/pagetop/src/base/component/form/date.rs @@ -3,16 +3,16 @@ use crate::prelude::*; pub struct Date { renderable : fn() -> bool, weight : i8, - name : OptionAttr, - value : OptionAttr, - label : OptionAttr, - placeholder : OptionAttr, - autofocus : OptionAttr, - autocomplete: OptionAttr, - disabled : OptionAttr, - readonly : OptionAttr, - required : OptionAttr, - help_text : OptionAttr, + name : OptAttr, + value : OptAttr, + label : OptAttr, + placeholder : OptAttr, + autofocus : OptAttr, + autocomplete: OptAttr, + disabled : OptAttr, + readonly : OptAttr, + required : OptAttr, + help_text : OptAttr, template : String, } @@ -22,16 +22,16 @@ impl PageComponent for Date { Date { renderable : always, weight : 0, - name : OptionAttr::none(), - value : OptionAttr::none(), - label : OptionAttr::none(), - placeholder : OptionAttr::none(), - autofocus : OptionAttr::none(), - autocomplete: OptionAttr::none(), - disabled : OptionAttr::none(), - readonly : OptionAttr::none(), - required : OptionAttr::none(), - help_text : OptionAttr::none(), + name : OptAttr::none(), + value : OptAttr::none(), + label : OptAttr::none(), + placeholder : OptAttr::none(), + autofocus : OptAttr::none(), + autocomplete: OptAttr::none(), + disabled : OptAttr::none(), + readonly : OptAttr::none(), + required : OptAttr::none(), + help_text : OptAttr::none(), template : "default".to_owned(), } } @@ -45,7 +45,7 @@ impl PageComponent for Date { } fn default_render(&self, _: &mut PageAssets) -> Markup { - let (class_item, id_item) = match self.name.option() { + let (class, id) = match self.name.option() { Some(name) => ( format!("form-item form-item-{} form-type-date", name), Some(format!("edit-{}", name)) @@ -56,9 +56,9 @@ impl PageComponent for Date { ) }; html! { - div class=(class_item) { + div class=(class) { @if self.label.has_value() { - label class="form-label" for=[&id_item] { + label class="form-label" for=[&id] { (self.label.value()) " " @if self.required.has_value() { span @@ -72,7 +72,7 @@ impl PageComponent for Date { } input type="date" - id=[&id_item] + id=[&id] class="form-control" name=[&self.name.option()] value=[&self.value.option()] diff --git a/pagetop/src/base/component/form/form.rs b/pagetop/src/base/component/form/form.rs index e93926a7..385dd369 100644 --- a/pagetop/src/base/component/form/form.rs +++ b/pagetop/src/base/component/form/form.rs @@ -5,10 +5,10 @@ pub enum FormMethod {Get, Post} pub struct Form { renderable: fn() -> bool, weight : i8, - id : OptionId, - action : OptionAttr, + id : OptIden, + action : OptAttr, method : FormMethod, - charset : OptionAttr, + charset : OptAttr, elements : PageContainer, template : String, } @@ -19,10 +19,10 @@ impl PageComponent for Form { Form { renderable: always, weight : 0, - id : OptionId::none(), - action : OptionAttr::none(), + id : OptIden::none(), + action : OptAttr::none(), method : FormMethod::Post, - charset : OptionAttr::some("UTF-8"), + charset : OptAttr::some("UTF-8"), elements : PageContainer::new(), template : "default".to_owned(), } diff --git a/pagetop/src/base/component/form/hidden.rs b/pagetop/src/base/component/form/hidden.rs index b27caf37..b7eca015 100644 --- a/pagetop/src/base/component/form/hidden.rs +++ b/pagetop/src/base/component/form/hidden.rs @@ -2,8 +2,8 @@ use crate::prelude::*; pub struct Hidden { weight : i8, - name : OptionId, - value : OptionAttr, + name : OptIden, + value : OptAttr, } impl PageComponent for Hidden { @@ -11,8 +11,8 @@ impl PageComponent for Hidden { fn new() -> Self { Hidden { weight : 0, - name : OptionId::none(), - value : OptionAttr::none(), + name : OptIden::none(), + value : OptAttr::none(), } } @@ -21,14 +21,14 @@ impl PageComponent for Hidden { } fn default_render(&self, _: &mut PageAssets) -> Markup { - let id_item = match self.name.option() { + let id = match self.name.option() { Some(name) => Some(format!("value-{}", name)), _ => None }; html! { input type="hidden" - id=[&id_item] + id=[&id] name=[&self.name.option()] value=[&self.value.option()]; } diff --git a/pagetop/src/base/component/form/input.rs b/pagetop/src/base/component/form/input.rs index c483c9a9..7622fd08 100644 --- a/pagetop/src/base/component/form/input.rs +++ b/pagetop/src/base/component/form/input.rs @@ -6,19 +6,19 @@ pub struct Input { renderable : fn() -> bool, weight : i8, input_type : InputType, - name : OptionId, - value : OptionAttr, - label : OptionAttr, + name : OptIden, + value : OptAttr, + label : OptAttr, size : Option, minlength : Option, maxlength : Option, - placeholder : OptionAttr, - autofocus : OptionAttr, - autocomplete: OptionAttr, - disabled : OptionAttr, - readonly : OptionAttr, - required : OptionAttr, - help_text : OptionAttr, + placeholder : OptAttr, + autofocus : OptAttr, + autocomplete: OptAttr, + disabled : OptAttr, + readonly : OptAttr, + required : OptAttr, + help_text : OptAttr, template : String, } @@ -29,19 +29,19 @@ impl PageComponent for Input { renderable : always, weight : 0, input_type : InputType::Textfield, - name : OptionId::none(), - value : OptionAttr::none(), - label : OptionAttr::none(), + name : OptIden::none(), + value : OptAttr::none(), + label : OptAttr::none(), size : Some(60), minlength : None, maxlength : Some(128), - placeholder : OptionAttr::none(), - autofocus : OptionAttr::none(), - autocomplete: OptionAttr::none(), - disabled : OptionAttr::none(), - readonly : OptionAttr::none(), - required : OptionAttr::none(), - help_text : OptionAttr::none(), + placeholder : OptAttr::none(), + autofocus : OptAttr::none(), + autocomplete: OptAttr::none(), + disabled : OptAttr::none(), + readonly : OptAttr::none(), + required : OptAttr::none(), + help_text : OptAttr::none(), template : "default".to_owned(), } } @@ -55,7 +55,7 @@ impl PageComponent for Input { } fn default_render(&self, _: &mut PageAssets) -> Markup { - let (input_type, class_type) = match &self.input_type { + let (type_input, type_class) = match &self.input_type { InputType::Email => ("email", "form-type-email"), InputType::Password => ("password", "form-type-password"), InputType::Search => ("search", "form-type-search"), @@ -63,20 +63,20 @@ impl PageComponent for Input { InputType::Textfield => ("text", "form-type-textfield"), InputType::Url => ("url", "form-type-url") }; - let (class_item, id_item) = match &self.name.option() { + let (class, id) = match &self.name.option() { Some(name) => ( - format!("form-item form-item-{} {}", name, class_type), + format!("form-item form-item-{} {}", name, type_class), Some(format!("edit-{}", name)) ), None => ( - format!("form-item {}", class_type), + format!("form-item {}", type_class), None ) }; html! { - div class=(class_item) { + div class=(class) { @if self.label.has_value() { - label class="form-label" for=[&id_item] { + label class="form-label" for=[&id] { (self.label.value()) " " @if self.required.has_value() { span @@ -89,8 +89,8 @@ impl PageComponent for Input { } } input - type=(input_type) - id=[&id_item] + type=(type_input) + id=[&id] class="form-control" name=[&self.name.option()] value=[&self.value.option()] diff --git a/pagetop/src/base/component/grid/column.rs b/pagetop/src/base/component/grid/column.rs index 96463490..8bcfb54f 100644 --- a/pagetop/src/base/component/grid/column.rs +++ b/pagetop/src/base/component/grid/column.rs @@ -3,7 +3,7 @@ use crate::prelude::*; pub struct Column { renderable: fn() -> bool, weight : i8, - id : OptionId, + id : OptIden, components: PageContainer, template : String, } @@ -14,7 +14,7 @@ impl PageComponent for Column { Column { renderable: always, weight : 0, - id : OptionId::none(), + id : OptIden::none(), components: PageContainer::new(), template : "default".to_owned(), } diff --git a/pagetop/src/base/component/grid/row.rs b/pagetop/src/base/component/grid/row.rs index 6aed7d0f..7c94fea6 100644 --- a/pagetop/src/base/component/grid/row.rs +++ b/pagetop/src/base/component/grid/row.rs @@ -3,7 +3,7 @@ use crate::prelude::*; pub struct Row { renderable: fn() -> bool, weight : i8, - id : OptionId, + id : OptIden, columns : PageContainer, template : String, } @@ -14,7 +14,7 @@ impl PageComponent for Row { Row { renderable: always, weight : 0, - id : OptionId::none(), + id : OptIden::none(), columns : PageContainer::new(), template : "default".to_owned(), } diff --git a/pagetop/src/base/component/menu.rs b/pagetop/src/base/component/menu.rs index 10ac8ca5..0f529874 100644 --- a/pagetop/src/base/component/menu.rs +++ b/pagetop/src/base/component/menu.rs @@ -148,7 +148,7 @@ impl MenuItem { pub struct Menu { renderable: fn() -> bool, weight : i8, - id : OptionId, + id : OptIden, items : PageContainer, template : String, } @@ -159,7 +159,7 @@ impl PageComponent for Menu { Menu { renderable: always, weight : 0, - id : OptionId::none(), + id : OptIden::none(), items : PageContainer::new(), template : "default".to_owned(), } diff --git a/pagetop/src/base/module/demopage/mod.rs b/pagetop/src/base/module/demopage/mod.rs index f3d3a903..7fa78181 100644 --- a/pagetop/src/base/module/demopage/mod.rs +++ b/pagetop/src/base/module/demopage/mod.rs @@ -27,7 +27,7 @@ async fn demo() -> app::Result { .using_theme("Bootsier") .with_title(l("page_title").as_str()) .add_to("content", hello_world()) - .add_to("content", hello_world2()) + .add_to("content", hello_world_original()) .add_to("content", just_visiting()) .add_to("content", about_pagetop()) .add_to("content", promo_pagetop()) @@ -35,7 +35,7 @@ async fn demo() -> app::Result { .render() } -fn hello_world2() -> Container { +fn hello_world() -> Container { Container::header() .add(grid::Row::new() .add_column(grid::Column::new() @@ -76,7 +76,7 @@ fn hello_world2() -> Container { ) } -fn hello_world() -> Chunck { +fn hello_world_original() -> Chunck { Chunck::with(html! { header id="header" class="header" { div class="container" { diff --git a/pagetop/src/html/mod.rs b/pagetop/src/html/mod.rs index 60a9bd82..52f735fe 100644 --- a/pagetop/src/html/mod.rs +++ b/pagetop/src/html/mod.rs @@ -1,8 +1,8 @@ pub use maud::{DOCTYPE, Markup, PreEscaped, html}; -mod optional_id; -pub use optional_id::OptionId; -mod optional_attr; -pub use optional_attr::OptionAttr; +mod optiden; +pub use optiden::OptIden; +mod optattr; +pub use optattr::OptAttr; mod classes; pub use classes::Classes; diff --git a/pagetop/src/html/optional_attr.rs b/pagetop/src/html/optattr.rs similarity index 80% rename from pagetop/src/html/optional_attr.rs rename to pagetop/src/html/optattr.rs index f6b48189..af82751c 100644 --- a/pagetop/src/html/optional_attr.rs +++ b/pagetop/src/html/optattr.rs @@ -1,15 +1,15 @@ -pub struct OptionAttr(Option); +pub struct OptAttr(Option); -impl OptionAttr { +impl OptAttr { pub fn none() -> Self { - OptionAttr(None) + OptAttr(None) } pub fn some(value: &str) -> Self { let value = value.trim(); match value.is_empty() { - true => OptionAttr(None), - false => OptionAttr(Some(value.to_owned())), + true => OptAttr(None), + false => OptAttr(Some(value.to_owned())), } } diff --git a/pagetop/src/html/optional_id.rs b/pagetop/src/html/optiden.rs similarity index 88% rename from pagetop/src/html/optional_id.rs rename to pagetop/src/html/optiden.rs index 678ff5c8..ca10155e 100644 --- a/pagetop/src/html/optional_id.rs +++ b/pagetop/src/html/optiden.rs @@ -1,8 +1,8 @@ -pub struct OptionId(Option); +pub struct OptIden(Option); -impl OptionId { +impl OptIden { pub fn none() -> Self { - OptionId(None) + OptIden(None) } pub fn with_value(&mut self, id: &str) { diff --git a/pagetop/src/response/page/page.rs b/pagetop/src/response/page/page.rs index 1ccb9603..5bd4696a 100644 --- a/pagetop/src/response/page/page.rs +++ b/pagetop/src/response/page/page.rs @@ -1,6 +1,6 @@ use crate::{Lazy, app, trace}; use crate::config::SETTINGS; -use crate::html::{Classes, DOCTYPE, Markup, OptionAttr, html}; +use crate::html::{Classes, DOCTYPE, Markup, OptAttr, html}; use crate::response::page::{PageAssets, PageComponent, PageContainer}; use std::sync::RwLock; @@ -40,10 +40,10 @@ static DEFAULT_DIRECTION: Lazy> = Lazy::new(|| { pub enum TextDirection { Auto, LeftToRight, RightToLeft } pub struct Page<'a> { - language : OptionAttr, - direction : OptionAttr, - title : OptionAttr, - description : OptionAttr, + language : OptAttr, + direction : OptAttr, + title : OptAttr, + description : OptAttr, assets : PageAssets, body_classes: Classes, regions : HashMap<&'a str, PageContainer>, @@ -55,15 +55,15 @@ impl<'a> Page<'a> { pub fn new() -> Self { Page { language : match &*DEFAULT_LANGUAGE { - Some(language) => OptionAttr::some(language), - _ => OptionAttr::none(), + Some(language) => OptAttr::some(language), + _ => OptAttr::none(), }, direction : match &*DEFAULT_DIRECTION { - Some(direction) => OptionAttr::some(direction), - _ => OptionAttr::none(), + Some(direction) => OptAttr::some(direction), + _ => OptAttr::none(), }, - title : OptionAttr::none(), - description : OptionAttr::none(), + title : OptAttr::none(), + description : OptAttr::none(), body_classes: Classes::some_class("body"), assets : PageAssets::new(), regions : COMPONENTS.read().unwrap().clone(),