Libera la versión de desarrollo 0.0.5

This commit is contained in:
Manuel Cillero 2022-03-27 13:07:16 +02:00
parent c6bbd565ab
commit b02a92dbb0
16 changed files with 113 additions and 113 deletions

View file

@ -1,6 +1,6 @@
[package] [package]
name = "pagetop" name = "pagetop"
version = "0.0.4" version = "0.0.5"
edition = "2021" edition = "2021"
authors = [ authors = [

View file

@ -3,8 +3,8 @@ use crate::prelude::*;
pub struct Block { pub struct Block {
renderable: fn() -> bool, renderable: fn() -> bool,
weight : i8, weight : i8,
id : OptionId, id : OptIden,
title : OptionAttr, title : OptAttr,
html : Vec<Markup>, html : Vec<Markup>,
template : String, template : String,
} }
@ -15,8 +15,8 @@ impl PageComponent for Block {
Block { Block {
renderable: always, renderable: always,
weight : 0, weight : 0,
id : OptionId::none(), id : OptIden::none(),
title : OptionAttr::none(), title : OptAttr::none(),
html : Vec::new(), html : Vec::new(),
template : "default".to_owned(), template : "default".to_owned(),
} }

View file

@ -5,7 +5,7 @@ enum ContainerType { Header, Footer, Main, Section, Wrapper }
pub struct Container { pub struct Container {
renderable: fn() -> bool, renderable: fn() -> bool,
weight : i8, weight : i8,
id : OptionId, id : OptIden,
container : ContainerType, container : ContainerType,
components: PageContainer, components: PageContainer,
template : String, template : String,
@ -17,7 +17,7 @@ impl PageComponent for Container {
Container { Container {
renderable: always, renderable: always,
weight : 0, weight : 0,
id : OptionId::none(), id : OptIden::none(),
container : ContainerType::Wrapper, container : ContainerType::Wrapper,
components: PageContainer::new(), components: PageContainer::new(),
template : "default".to_owned(), template : "default".to_owned(),

View file

@ -6,10 +6,10 @@ pub struct Button {
renderable : fn() -> bool, renderable : fn() -> bool,
weight : i8, weight : i8,
button_type: ButtonType, button_type: ButtonType,
name : OptionAttr, name : OptAttr,
value : OptionAttr, value : OptAttr,
autofocus : OptionAttr, autofocus : OptAttr,
disabled : OptionAttr, disabled : OptAttr,
template : String, template : String,
} }
@ -20,10 +20,10 @@ impl PageComponent for Button {
renderable : always, renderable : always,
weight : 0, weight : 0,
button_type: ButtonType::Button, button_type: ButtonType::Button,
name : OptionAttr::none(), name : OptAttr::none(),
value : OptionAttr::none(), value : OptAttr::none(),
autofocus : OptionAttr::none(), autofocus : OptAttr::none(),
disabled : OptionAttr::none(), disabled : OptAttr::none(),
template : "default".to_owned(), template : "default".to_owned(),
} }
} }
@ -42,14 +42,14 @@ impl PageComponent for Button {
ButtonType::Reset => ("reset", "btn btn-primary form-reset" ), ButtonType::Reset => ("reset", "btn btn-primary form-reset" ),
ButtonType::Submit => ("submit", "btn btn-primary form-submit") 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)), Some(name) => Some(format!("edit-{}", name)),
_ => None _ => None
}; };
html! { html! {
button button
type=(button_type) type=(button_type)
id=[&id_item] id=[&id]
class=(button_class) class=(button_class)
name=[&self.name.option()] name=[&self.name.option()]
value=[&self.value.option()] value=[&self.value.option()]

View file

@ -3,16 +3,16 @@ use crate::prelude::*;
pub struct Date { pub struct Date {
renderable : fn() -> bool, renderable : fn() -> bool,
weight : i8, weight : i8,
name : OptionAttr, name : OptAttr,
value : OptionAttr, value : OptAttr,
label : OptionAttr, label : OptAttr,
placeholder : OptionAttr, placeholder : OptAttr,
autofocus : OptionAttr, autofocus : OptAttr,
autocomplete: OptionAttr, autocomplete: OptAttr,
disabled : OptionAttr, disabled : OptAttr,
readonly : OptionAttr, readonly : OptAttr,
required : OptionAttr, required : OptAttr,
help_text : OptionAttr, help_text : OptAttr,
template : String, template : String,
} }
@ -22,16 +22,16 @@ impl PageComponent for Date {
Date { Date {
renderable : always, renderable : always,
weight : 0, weight : 0,
name : OptionAttr::none(), name : OptAttr::none(),
value : OptionAttr::none(), value : OptAttr::none(),
label : OptionAttr::none(), label : OptAttr::none(),
placeholder : OptionAttr::none(), placeholder : OptAttr::none(),
autofocus : OptionAttr::none(), autofocus : OptAttr::none(),
autocomplete: OptionAttr::none(), autocomplete: OptAttr::none(),
disabled : OptionAttr::none(), disabled : OptAttr::none(),
readonly : OptionAttr::none(), readonly : OptAttr::none(),
required : OptionAttr::none(), required : OptAttr::none(),
help_text : OptionAttr::none(), help_text : OptAttr::none(),
template : "default".to_owned(), template : "default".to_owned(),
} }
} }
@ -45,7 +45,7 @@ impl PageComponent for Date {
} }
fn default_render(&self, _: &mut PageAssets) -> Markup { 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) => ( Some(name) => (
format!("form-item form-item-{} form-type-date", name), format!("form-item form-item-{} form-type-date", name),
Some(format!("edit-{}", name)) Some(format!("edit-{}", name))
@ -56,9 +56,9 @@ impl PageComponent for Date {
) )
}; };
html! { html! {
div class=(class_item) { div class=(class) {
@if self.label.has_value() { @if self.label.has_value() {
label class="form-label" for=[&id_item] { label class="form-label" for=[&id] {
(self.label.value()) " " (self.label.value()) " "
@if self.required.has_value() { @if self.required.has_value() {
span span
@ -72,7 +72,7 @@ impl PageComponent for Date {
} }
input input
type="date" type="date"
id=[&id_item] id=[&id]
class="form-control" class="form-control"
name=[&self.name.option()] name=[&self.name.option()]
value=[&self.value.option()] value=[&self.value.option()]

View file

@ -5,10 +5,10 @@ pub enum FormMethod {Get, Post}
pub struct Form { pub struct Form {
renderable: fn() -> bool, renderable: fn() -> bool,
weight : i8, weight : i8,
id : OptionId, id : OptIden,
action : OptionAttr, action : OptAttr,
method : FormMethod, method : FormMethod,
charset : OptionAttr, charset : OptAttr,
elements : PageContainer, elements : PageContainer,
template : String, template : String,
} }
@ -19,10 +19,10 @@ impl PageComponent for Form {
Form { Form {
renderable: always, renderable: always,
weight : 0, weight : 0,
id : OptionId::none(), id : OptIden::none(),
action : OptionAttr::none(), action : OptAttr::none(),
method : FormMethod::Post, method : FormMethod::Post,
charset : OptionAttr::some("UTF-8"), charset : OptAttr::some("UTF-8"),
elements : PageContainer::new(), elements : PageContainer::new(),
template : "default".to_owned(), template : "default".to_owned(),
} }

View file

@ -2,8 +2,8 @@ use crate::prelude::*;
pub struct Hidden { pub struct Hidden {
weight : i8, weight : i8,
name : OptionId, name : OptIden,
value : OptionAttr, value : OptAttr,
} }
impl PageComponent for Hidden { impl PageComponent for Hidden {
@ -11,8 +11,8 @@ impl PageComponent for Hidden {
fn new() -> Self { fn new() -> Self {
Hidden { Hidden {
weight : 0, weight : 0,
name : OptionId::none(), name : OptIden::none(),
value : OptionAttr::none(), value : OptAttr::none(),
} }
} }
@ -21,14 +21,14 @@ impl PageComponent for Hidden {
} }
fn default_render(&self, _: &mut PageAssets) -> Markup { 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)), Some(name) => Some(format!("value-{}", name)),
_ => None _ => None
}; };
html! { html! {
input input
type="hidden" type="hidden"
id=[&id_item] id=[&id]
name=[&self.name.option()] name=[&self.name.option()]
value=[&self.value.option()]; value=[&self.value.option()];
} }

View file

@ -6,19 +6,19 @@ pub struct Input {
renderable : fn() -> bool, renderable : fn() -> bool,
weight : i8, weight : i8,
input_type : InputType, input_type : InputType,
name : OptionId, name : OptIden,
value : OptionAttr, value : OptAttr,
label : OptionAttr, label : OptAttr,
size : Option<u16>, size : Option<u16>,
minlength : Option<u16>, minlength : Option<u16>,
maxlength : Option<u16>, maxlength : Option<u16>,
placeholder : OptionAttr, placeholder : OptAttr,
autofocus : OptionAttr, autofocus : OptAttr,
autocomplete: OptionAttr, autocomplete: OptAttr,
disabled : OptionAttr, disabled : OptAttr,
readonly : OptionAttr, readonly : OptAttr,
required : OptionAttr, required : OptAttr,
help_text : OptionAttr, help_text : OptAttr,
template : String, template : String,
} }
@ -29,19 +29,19 @@ impl PageComponent for Input {
renderable : always, renderable : always,
weight : 0, weight : 0,
input_type : InputType::Textfield, input_type : InputType::Textfield,
name : OptionId::none(), name : OptIden::none(),
value : OptionAttr::none(), value : OptAttr::none(),
label : OptionAttr::none(), label : OptAttr::none(),
size : Some(60), size : Some(60),
minlength : None, minlength : None,
maxlength : Some(128), maxlength : Some(128),
placeholder : OptionAttr::none(), placeholder : OptAttr::none(),
autofocus : OptionAttr::none(), autofocus : OptAttr::none(),
autocomplete: OptionAttr::none(), autocomplete: OptAttr::none(),
disabled : OptionAttr::none(), disabled : OptAttr::none(),
readonly : OptionAttr::none(), readonly : OptAttr::none(),
required : OptionAttr::none(), required : OptAttr::none(),
help_text : OptionAttr::none(), help_text : OptAttr::none(),
template : "default".to_owned(), template : "default".to_owned(),
} }
} }
@ -55,7 +55,7 @@ impl PageComponent for Input {
} }
fn default_render(&self, _: &mut PageAssets) -> Markup { 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::Email => ("email", "form-type-email"),
InputType::Password => ("password", "form-type-password"), InputType::Password => ("password", "form-type-password"),
InputType::Search => ("search", "form-type-search"), InputType::Search => ("search", "form-type-search"),
@ -63,20 +63,20 @@ impl PageComponent for Input {
InputType::Textfield => ("text", "form-type-textfield"), InputType::Textfield => ("text", "form-type-textfield"),
InputType::Url => ("url", "form-type-url") InputType::Url => ("url", "form-type-url")
}; };
let (class_item, id_item) = match &self.name.option() { let (class, id) = match &self.name.option() {
Some(name) => ( Some(name) => (
format!("form-item form-item-{} {}", name, class_type), format!("form-item form-item-{} {}", name, type_class),
Some(format!("edit-{}", name)) Some(format!("edit-{}", name))
), ),
None => ( None => (
format!("form-item {}", class_type), format!("form-item {}", type_class),
None None
) )
}; };
html! { html! {
div class=(class_item) { div class=(class) {
@if self.label.has_value() { @if self.label.has_value() {
label class="form-label" for=[&id_item] { label class="form-label" for=[&id] {
(self.label.value()) " " (self.label.value()) " "
@if self.required.has_value() { @if self.required.has_value() {
span span
@ -89,8 +89,8 @@ impl PageComponent for Input {
} }
} }
input input
type=(input_type) type=(type_input)
id=[&id_item] id=[&id]
class="form-control" class="form-control"
name=[&self.name.option()] name=[&self.name.option()]
value=[&self.value.option()] value=[&self.value.option()]

View file

@ -3,7 +3,7 @@ use crate::prelude::*;
pub struct Column { pub struct Column {
renderable: fn() -> bool, renderable: fn() -> bool,
weight : i8, weight : i8,
id : OptionId, id : OptIden,
components: PageContainer, components: PageContainer,
template : String, template : String,
} }
@ -14,7 +14,7 @@ impl PageComponent for Column {
Column { Column {
renderable: always, renderable: always,
weight : 0, weight : 0,
id : OptionId::none(), id : OptIden::none(),
components: PageContainer::new(), components: PageContainer::new(),
template : "default".to_owned(), template : "default".to_owned(),
} }

View file

@ -3,7 +3,7 @@ use crate::prelude::*;
pub struct Row { pub struct Row {
renderable: fn() -> bool, renderable: fn() -> bool,
weight : i8, weight : i8,
id : OptionId, id : OptIden,
columns : PageContainer, columns : PageContainer,
template : String, template : String,
} }
@ -14,7 +14,7 @@ impl PageComponent for Row {
Row { Row {
renderable: always, renderable: always,
weight : 0, weight : 0,
id : OptionId::none(), id : OptIden::none(),
columns : PageContainer::new(), columns : PageContainer::new(),
template : "default".to_owned(), template : "default".to_owned(),
} }

View file

@ -148,7 +148,7 @@ impl MenuItem {
pub struct Menu { pub struct Menu {
renderable: fn() -> bool, renderable: fn() -> bool,
weight : i8, weight : i8,
id : OptionId, id : OptIden,
items : PageContainer, items : PageContainer,
template : String, template : String,
} }
@ -159,7 +159,7 @@ impl PageComponent for Menu {
Menu { Menu {
renderable: always, renderable: always,
weight : 0, weight : 0,
id : OptionId::none(), id : OptIden::none(),
items : PageContainer::new(), items : PageContainer::new(),
template : "default".to_owned(), template : "default".to_owned(),
} }

View file

@ -27,7 +27,7 @@ async fn demo() -> app::Result<Markup> {
.using_theme("Bootsier") .using_theme("Bootsier")
.with_title(l("page_title").as_str()) .with_title(l("page_title").as_str())
.add_to("content", hello_world()) .add_to("content", hello_world())
.add_to("content", hello_world2()) .add_to("content", hello_world_original())
.add_to("content", just_visiting()) .add_to("content", just_visiting())
.add_to("content", about_pagetop()) .add_to("content", about_pagetop())
.add_to("content", promo_pagetop()) .add_to("content", promo_pagetop())
@ -35,7 +35,7 @@ async fn demo() -> app::Result<Markup> {
.render() .render()
} }
fn hello_world2() -> Container { fn hello_world() -> Container {
Container::header() Container::header()
.add(grid::Row::new() .add(grid::Row::new()
.add_column(grid::Column::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! { Chunck::with(html! {
header id="header" class="header" { header id="header" class="header" {
div class="container" { div class="container" {

View file

@ -1,8 +1,8 @@
pub use maud::{DOCTYPE, Markup, PreEscaped, html}; pub use maud::{DOCTYPE, Markup, PreEscaped, html};
mod optional_id; mod optiden;
pub use optional_id::OptionId; pub use optiden::OptIden;
mod optional_attr; mod optattr;
pub use optional_attr::OptionAttr; pub use optattr::OptAttr;
mod classes; mod classes;
pub use classes::Classes; pub use classes::Classes;

View file

@ -1,15 +1,15 @@
pub struct OptionAttr(Option<String>); pub struct OptAttr(Option<String>);
impl OptionAttr { impl OptAttr {
pub fn none() -> Self { pub fn none() -> Self {
OptionAttr(None) OptAttr(None)
} }
pub fn some(value: &str) -> Self { pub fn some(value: &str) -> Self {
let value = value.trim(); let value = value.trim();
match value.is_empty() { match value.is_empty() {
true => OptionAttr(None), true => OptAttr(None),
false => OptionAttr(Some(value.to_owned())), false => OptAttr(Some(value.to_owned())),
} }
} }

View file

@ -1,8 +1,8 @@
pub struct OptionId(Option<String>); pub struct OptIden(Option<String>);
impl OptionId { impl OptIden {
pub fn none() -> Self { pub fn none() -> Self {
OptionId(None) OptIden(None)
} }
pub fn with_value(&mut self, id: &str) { pub fn with_value(&mut self, id: &str) {

View file

@ -1,6 +1,6 @@
use crate::{Lazy, app, trace}; use crate::{Lazy, app, trace};
use crate::config::SETTINGS; 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 crate::response::page::{PageAssets, PageComponent, PageContainer};
use std::sync::RwLock; use std::sync::RwLock;
@ -40,10 +40,10 @@ static DEFAULT_DIRECTION: Lazy<Option<String>> = Lazy::new(|| {
pub enum TextDirection { Auto, LeftToRight, RightToLeft } pub enum TextDirection { Auto, LeftToRight, RightToLeft }
pub struct Page<'a> { pub struct Page<'a> {
language : OptionAttr, language : OptAttr,
direction : OptionAttr, direction : OptAttr,
title : OptionAttr, title : OptAttr,
description : OptionAttr, description : OptAttr,
assets : PageAssets, assets : PageAssets,
body_classes: Classes, body_classes: Classes,
regions : HashMap<&'a str, PageContainer>, regions : HashMap<&'a str, PageContainer>,
@ -55,15 +55,15 @@ impl<'a> Page<'a> {
pub fn new() -> Self { pub fn new() -> Self {
Page { Page {
language : match &*DEFAULT_LANGUAGE { language : match &*DEFAULT_LANGUAGE {
Some(language) => OptionAttr::some(language), Some(language) => OptAttr::some(language),
_ => OptionAttr::none(), _ => OptAttr::none(),
}, },
direction : match &*DEFAULT_DIRECTION { direction : match &*DEFAULT_DIRECTION {
Some(direction) => OptionAttr::some(direction), Some(direction) => OptAttr::some(direction),
_ => OptionAttr::none(), _ => OptAttr::none(),
}, },
title : OptionAttr::none(), title : OptAttr::none(),
description : OptionAttr::none(), description : OptAttr::none(),
body_classes: Classes::some_class("body"), body_classes: Classes::some_class("body"),
assets : PageAssets::new(), assets : PageAssets::new(),
regions : COMPONENTS.read().unwrap().clone(), regions : COMPONENTS.read().unwrap().clone(),