Libera la versión de desarrollo 0.0.6
This commit is contained in:
parent
68d79f6090
commit
363cec7a75
17 changed files with 284 additions and 115 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "pagetop"
|
name = "pagetop"
|
||||||
version = "0.0.5"
|
version = "0.0.6"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
authors = [
|
authors = [
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,10 @@ use crate::prelude::*;
|
||||||
pub struct Block {
|
pub struct Block {
|
||||||
renderable: fn() -> bool,
|
renderable: fn() -> bool,
|
||||||
weight : i8,
|
weight : i8,
|
||||||
id : OptIden,
|
|
||||||
title : OptAttr,
|
title : OptAttr,
|
||||||
html : Vec<Markup>,
|
html : Vec<Markup>,
|
||||||
|
id : OptIden,
|
||||||
|
classes : Classes,
|
||||||
template : String,
|
template : String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -15,9 +16,10 @@ impl PageComponent for Block {
|
||||||
Block {
|
Block {
|
||||||
renderable: always,
|
renderable: always,
|
||||||
weight : 0,
|
weight : 0,
|
||||||
id : OptIden::none(),
|
|
||||||
title : OptAttr::none(),
|
title : OptAttr::none(),
|
||||||
html : Vec::new(),
|
html : Vec::new(),
|
||||||
|
id : OptIden::none(),
|
||||||
|
classes : Classes::none(),
|
||||||
template : "default".to_owned(),
|
template : "default".to_owned(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -33,7 +35,7 @@ impl PageComponent for Block {
|
||||||
fn default_render(&self, assets: &mut PageAssets) -> Markup {
|
fn default_render(&self, assets: &mut PageAssets) -> Markup {
|
||||||
let id = assets.serial_id(self.name(), self.id());
|
let id = assets.serial_id(self.name(), self.id());
|
||||||
html! {
|
html! {
|
||||||
div id=(id) class="block" {
|
div id=(id) class=[self.classes("block")] {
|
||||||
@match self.title() {
|
@match self.title() {
|
||||||
Some(title) => h2 class="block-title" { (title) },
|
Some(title) => h2 class="block-title" { (title) },
|
||||||
None => {}
|
None => {}
|
||||||
|
|
@ -66,11 +68,6 @@ impl Block {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_id(mut self, id: &str) -> Self {
|
|
||||||
self.id.with_value(id);
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn with_title(mut self, title: &str) -> Self {
|
pub fn with_title(mut self, title: &str) -> Self {
|
||||||
self.title.with_value(title);
|
self.title.with_value(title);
|
||||||
self
|
self
|
||||||
|
|
@ -81,6 +78,21 @@ impl Block {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn with_id(mut self, id: &str) -> Self {
|
||||||
|
self.id.with_value(id);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_classes(mut self, classes: &str) -> Self {
|
||||||
|
self.classes.set_classes(classes);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn add_classes(mut self, classes: &str) -> Self {
|
||||||
|
self.classes.add_classes(classes);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn using_template(mut self, template: &str) -> Self {
|
pub fn using_template(mut self, template: &str) -> Self {
|
||||||
self.template = template.to_owned();
|
self.template = template.to_owned();
|
||||||
self
|
self
|
||||||
|
|
@ -88,10 +100,6 @@ impl Block {
|
||||||
|
|
||||||
// Block GETTERS.
|
// Block GETTERS.
|
||||||
|
|
||||||
pub fn id(&self) -> &Option<String> {
|
|
||||||
self.id.option()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn title(&self) -> &Option<String> {
|
pub fn title(&self) -> &Option<String> {
|
||||||
self.title.option()
|
self.title.option()
|
||||||
}
|
}
|
||||||
|
|
@ -100,6 +108,14 @@ impl Block {
|
||||||
&self.html
|
&self.html
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn id(&self) -> &Option<String> {
|
||||||
|
self.id.option()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn classes(&self, default: &str) -> Option<String> {
|
||||||
|
self.classes.option(default)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn template(&self) -> &str {
|
pub fn template(&self) -> &str {
|
||||||
self.template.as_str()
|
self.template.as_str()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,9 @@ pub struct Container {
|
||||||
renderable: fn() -> bool,
|
renderable: fn() -> bool,
|
||||||
weight : i8,
|
weight : i8,
|
||||||
container : ContainerType,
|
container : ContainerType,
|
||||||
id : OptIden,
|
|
||||||
components: PageContainer,
|
components: PageContainer,
|
||||||
|
id : OptIden,
|
||||||
|
classes : Classes,
|
||||||
template : String,
|
template : String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -18,8 +19,9 @@ impl PageComponent for Container {
|
||||||
renderable: always,
|
renderable: always,
|
||||||
weight : 0,
|
weight : 0,
|
||||||
container : ContainerType::Wrapper,
|
container : ContainerType::Wrapper,
|
||||||
id : OptIden::none(),
|
|
||||||
components: PageContainer::new(),
|
components: PageContainer::new(),
|
||||||
|
id : OptIden::none(),
|
||||||
|
classes : Classes::none(),
|
||||||
template : "default".to_owned(),
|
template : "default".to_owned(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -35,35 +37,35 @@ impl PageComponent for Container {
|
||||||
fn default_render(&self, assets: &mut PageAssets) -> Markup {
|
fn default_render(&self, assets: &mut PageAssets) -> Markup {
|
||||||
match self.container_type() {
|
match self.container_type() {
|
||||||
ContainerType::Header => html! {
|
ContainerType::Header => html! {
|
||||||
header id=[self.id()] class="header" {
|
header id=[self.id()] class=[self.classes("header")] {
|
||||||
div class="container" {
|
div class="container" {
|
||||||
(self.render_components(assets))
|
(self.render_components(assets))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
ContainerType::Footer => html! {
|
ContainerType::Footer => html! {
|
||||||
footer id=[self.id()] class="footer" {
|
footer id=[self.id()] class=[self.classes("footer")] {
|
||||||
div class="container" {
|
div class="container" {
|
||||||
(self.render_components(assets))
|
(self.render_components(assets))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
ContainerType::Main => html! {
|
ContainerType::Main => html! {
|
||||||
main id=[self.id()] class="main" {
|
main id=[self.id()] class=[self.classes("main")] {
|
||||||
div class="container" {
|
div class="container" {
|
||||||
(self.render_components(assets))
|
(self.render_components(assets))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
ContainerType::Section => html! {
|
ContainerType::Section => html! {
|
||||||
section id=[self.id()] class="section" {
|
section id=[self.id()] class=[self.classes("section")] {
|
||||||
div class="container" {
|
div class="container" {
|
||||||
(self.render_components(assets))
|
(self.render_components(assets))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
_ => html! {
|
_ => html! {
|
||||||
div id=[self.id()] class="container" {
|
div id=[self.id()] class=[self.classes("container")] {
|
||||||
(self.render_components(assets))
|
(self.render_components(assets))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -109,13 +111,23 @@ impl Container {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn add(mut self, component: impl PageComponent) -> Self {
|
||||||
|
self.components.add(component);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn with_id(mut self, id: &str) -> Self {
|
pub fn with_id(mut self, id: &str) -> Self {
|
||||||
self.id.with_value(id);
|
self.id.with_value(id);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add(mut self, component: impl PageComponent) -> Self {
|
pub fn set_classes(mut self, classes: &str) -> Self {
|
||||||
self.components.add(component);
|
self.classes.set_classes(classes);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn add_classes(mut self, classes: &str) -> Self {
|
||||||
|
self.classes.add_classes(classes);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -134,6 +146,10 @@ impl Container {
|
||||||
self.id.option()
|
self.id.option()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn classes(&self, default: &str) -> Option<String> {
|
||||||
|
self.classes.option(default)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn template(&self) -> &str {
|
pub fn template(&self) -> &str {
|
||||||
self.template.as_str()
|
self.template.as_str()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ pub struct Button {
|
||||||
value : OptAttr,
|
value : OptAttr,
|
||||||
autofocus : OptAttr,
|
autofocus : OptAttr,
|
||||||
disabled : OptAttr,
|
disabled : OptAttr,
|
||||||
|
classes : Classes,
|
||||||
template : String,
|
template : String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -24,6 +25,7 @@ impl PageComponent for Button {
|
||||||
value : OptAttr::none(),
|
value : OptAttr::none(),
|
||||||
autofocus : OptAttr::none(),
|
autofocus : OptAttr::none(),
|
||||||
disabled : OptAttr::none(),
|
disabled : OptAttr::none(),
|
||||||
|
classes : Classes::none(),
|
||||||
template : "default".to_owned(),
|
template : "default".to_owned(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -50,7 +52,7 @@ impl PageComponent for Button {
|
||||||
button
|
button
|
||||||
type=(button_type)
|
type=(button_type)
|
||||||
id=[id]
|
id=[id]
|
||||||
class=(button_class)
|
class=[self.classes(button_class)]
|
||||||
name=[self.name()]
|
name=[self.name()]
|
||||||
value=[self.value()]
|
value=[self.value()]
|
||||||
autofocus=[self.autofocus()]
|
autofocus=[self.autofocus()]
|
||||||
|
|
@ -121,6 +123,16 @@ impl Button {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_classes(mut self, classes: &str) -> Self {
|
||||||
|
self.classes.set_classes(classes);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn add_classes(mut self, classes: &str) -> Self {
|
||||||
|
self.classes.add_classes(classes);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn using_template(mut self, template: &str) -> Self {
|
pub fn using_template(mut self, template: &str) -> Self {
|
||||||
self.template = template.to_owned();
|
self.template = template.to_owned();
|
||||||
self
|
self
|
||||||
|
|
@ -148,6 +160,10 @@ impl Button {
|
||||||
self.disabled.option()
|
self.disabled.option()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn classes(&self, default: &str) -> Option<String> {
|
||||||
|
self.classes.option(default)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn template(&self) -> &str {
|
pub fn template(&self) -> &str {
|
||||||
self.template.as_str()
|
self.template.as_str()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ pub struct Date {
|
||||||
readonly : OptAttr,
|
readonly : OptAttr,
|
||||||
required : OptAttr,
|
required : OptAttr,
|
||||||
help_text : OptAttr,
|
help_text : OptAttr,
|
||||||
|
classes : Classes,
|
||||||
template : String,
|
template : String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -32,6 +33,7 @@ impl PageComponent for Date {
|
||||||
readonly : OptAttr::none(),
|
readonly : OptAttr::none(),
|
||||||
required : OptAttr::none(),
|
required : OptAttr::none(),
|
||||||
help_text : OptAttr::none(),
|
help_text : OptAttr::none(),
|
||||||
|
classes : Classes::none(),
|
||||||
template : "default".to_owned(),
|
template : "default".to_owned(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -45,7 +47,7 @@ impl PageComponent for Date {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_render(&self, _: &mut PageAssets) -> Markup {
|
fn default_render(&self, _: &mut PageAssets) -> Markup {
|
||||||
let (class, id) = match self.name() {
|
let (classes, id) = match self.name() {
|
||||||
Some(name) => (
|
Some(name) => (
|
||||||
concat_string!("form-item form-item-", name, " form-type-date"),
|
concat_string!("form-item form-item-", name, " form-type-date"),
|
||||||
Some(concat_string!("edit-", name))
|
Some(concat_string!("edit-", name))
|
||||||
|
|
@ -56,7 +58,7 @@ impl PageComponent for Date {
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
html! {
|
html! {
|
||||||
div class=(class) {
|
div class=[self.classes(classes.as_str())] {
|
||||||
@match self.label() {
|
@match self.label() {
|
||||||
Some(label) => label class="form-label" for=[&id] {
|
Some(label) => label class="form-label" for=[&id] {
|
||||||
(label) " "
|
(label) " "
|
||||||
|
|
@ -169,6 +171,16 @@ impl Date {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_classes(mut self, classes: &str) -> Self {
|
||||||
|
self.classes.set_classes(classes);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn add_classes(mut self, classes: &str) -> Self {
|
||||||
|
self.classes.add_classes(classes);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn using_template(mut self, template: &str) -> Self {
|
pub fn using_template(mut self, template: &str) -> Self {
|
||||||
self.template = template.to_owned();
|
self.template = template.to_owned();
|
||||||
self
|
self
|
||||||
|
|
@ -216,6 +228,10 @@ impl Date {
|
||||||
self.help_text.option()
|
self.help_text.option()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn classes(&self, default: &str) -> Option<String> {
|
||||||
|
self.classes.option(default)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn template(&self) -> &str {
|
pub fn template(&self) -> &str {
|
||||||
self.template.as_str()
|
self.template.as_str()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,12 @@ pub enum FormMethod {Get, Post}
|
||||||
pub struct Form {
|
pub struct Form {
|
||||||
renderable: fn() -> bool,
|
renderable: fn() -> bool,
|
||||||
weight : i8,
|
weight : i8,
|
||||||
id : OptIden,
|
|
||||||
action : OptAttr,
|
action : OptAttr,
|
||||||
charset : OptAttr,
|
charset : OptAttr,
|
||||||
method : FormMethod,
|
method : FormMethod,
|
||||||
elements : PageContainer,
|
elements : PageContainer,
|
||||||
|
id : OptIden,
|
||||||
|
classes : Classes,
|
||||||
template : String,
|
template : String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -19,11 +20,12 @@ impl PageComponent for Form {
|
||||||
Form {
|
Form {
|
||||||
renderable: always,
|
renderable: always,
|
||||||
weight : 0,
|
weight : 0,
|
||||||
id : OptIden::none(),
|
|
||||||
action : OptAttr::none(),
|
action : OptAttr::none(),
|
||||||
charset : OptAttr::some("UTF-8"),
|
charset : OptAttr::some("UTF-8"),
|
||||||
method : FormMethod::Post,
|
method : FormMethod::Post,
|
||||||
elements : PageContainer::new(),
|
elements : PageContainer::new(),
|
||||||
|
id : OptIden::none(),
|
||||||
|
classes : Classes::none(),
|
||||||
template : "default".to_owned(),
|
template : "default".to_owned(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -44,6 +46,7 @@ impl PageComponent for Form {
|
||||||
html! {
|
html! {
|
||||||
form
|
form
|
||||||
id=[self.id()]
|
id=[self.id()]
|
||||||
|
class=[self.classes("form")]
|
||||||
action=[self.action()]
|
action=[self.action()]
|
||||||
method=[method]
|
method=[method]
|
||||||
accept-charset=[self.charset()]
|
accept-charset=[self.charset()]
|
||||||
|
|
@ -70,11 +73,6 @@ impl Form {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_id(mut self, id: &str) -> Self {
|
|
||||||
self.id.with_value(id);
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn with_action(mut self, action: &str) -> Self {
|
pub fn with_action(mut self, action: &str) -> Self {
|
||||||
self.action.with_value(action);
|
self.action.with_value(action);
|
||||||
self
|
self
|
||||||
|
|
@ -95,6 +93,21 @@ impl Form {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn with_id(mut self, id: &str) -> Self {
|
||||||
|
self.id.with_value(id);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_classes(mut self, classes: &str) -> Self {
|
||||||
|
self.classes.set_classes(classes);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn add_classes(mut self, classes: &str) -> Self {
|
||||||
|
self.classes.add_classes(classes);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn using_template(mut self, template: &str) -> Self {
|
pub fn using_template(mut self, template: &str) -> Self {
|
||||||
self.template = template.to_owned();
|
self.template = template.to_owned();
|
||||||
self
|
self
|
||||||
|
|
@ -102,10 +115,6 @@ impl Form {
|
||||||
|
|
||||||
// Form GETTERS.
|
// Form GETTERS.
|
||||||
|
|
||||||
pub fn id(&self) -> &Option<String> {
|
|
||||||
self.id.option()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn action(&self) -> &Option<String> {
|
pub fn action(&self) -> &Option<String> {
|
||||||
self.action.option()
|
self.action.option()
|
||||||
}
|
}
|
||||||
|
|
@ -118,6 +127,14 @@ impl Form {
|
||||||
&self.method
|
&self.method
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn id(&self) -> &Option<String> {
|
||||||
|
self.id.option()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn classes(&self, default: &str) -> Option<String> {
|
||||||
|
self.classes.option(default)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn template(&self) -> &str {
|
pub fn template(&self) -> &str {
|
||||||
self.template.as_str()
|
self.template.as_str()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ pub struct Input {
|
||||||
readonly : OptAttr,
|
readonly : OptAttr,
|
||||||
required : OptAttr,
|
required : OptAttr,
|
||||||
help_text : OptAttr,
|
help_text : OptAttr,
|
||||||
|
classes : Classes,
|
||||||
template : String,
|
template : String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -42,6 +43,7 @@ impl PageComponent for Input {
|
||||||
readonly : OptAttr::none(),
|
readonly : OptAttr::none(),
|
||||||
required : OptAttr::none(),
|
required : OptAttr::none(),
|
||||||
help_text : OptAttr::none(),
|
help_text : OptAttr::none(),
|
||||||
|
classes : Classes::none(),
|
||||||
template : "default".to_owned(),
|
template : "default".to_owned(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -239,6 +241,16 @@ impl Input {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_classes(mut self, classes: &str) -> Self {
|
||||||
|
self.classes.set_classes(classes);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn add_classes(mut self, classes: &str) -> Self {
|
||||||
|
self.classes.add_classes(classes);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn using_template(mut self, template: &str) -> Self {
|
pub fn using_template(mut self, template: &str) -> Self {
|
||||||
self.template = template.to_owned();
|
self.template = template.to_owned();
|
||||||
self
|
self
|
||||||
|
|
@ -302,6 +314,10 @@ impl Input {
|
||||||
self.help_text.option()
|
self.help_text.option()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn classes(&self, default: &str) -> Option<String> {
|
||||||
|
self.classes.option(default)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn template(&self) -> &str {
|
pub fn template(&self) -> &str {
|
||||||
self.template.as_str()
|
self.template.as_str()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,9 @@ use crate::prelude::*;
|
||||||
pub struct Column {
|
pub struct Column {
|
||||||
renderable: fn() -> bool,
|
renderable: fn() -> bool,
|
||||||
weight : i8,
|
weight : i8,
|
||||||
|
components: PageContainer,
|
||||||
id : OptIden,
|
id : OptIden,
|
||||||
classes : Classes,
|
classes : Classes,
|
||||||
components: PageContainer,
|
|
||||||
template : String,
|
template : String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -15,13 +15,17 @@ impl PageComponent for Column {
|
||||||
Column {
|
Column {
|
||||||
renderable: always,
|
renderable: always,
|
||||||
weight : 0,
|
weight : 0,
|
||||||
id : OptIden::none(),
|
|
||||||
classes : Classes::some(vec!["col"]),
|
|
||||||
components: PageContainer::new(),
|
components: PageContainer::new(),
|
||||||
|
id : OptIden::none(),
|
||||||
|
classes : Classes::none(),
|
||||||
template : "default".to_owned(),
|
template : "default".to_owned(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn name(&self) -> &'static str {
|
||||||
|
"GridColumn"
|
||||||
|
}
|
||||||
|
|
||||||
fn is_renderable(&self) -> bool {
|
fn is_renderable(&self) -> bool {
|
||||||
(self.renderable)()
|
(self.renderable)()
|
||||||
}
|
}
|
||||||
|
|
@ -32,7 +36,7 @@ impl PageComponent for Column {
|
||||||
|
|
||||||
fn default_render(&self, assets: &mut PageAssets) -> Markup {
|
fn default_render(&self, assets: &mut PageAssets) -> Markup {
|
||||||
html! {
|
html! {
|
||||||
div id=[self.id()] class=[self.classes()] {
|
div id=[self.id()] class=[self.classes("col")] {
|
||||||
(self.render_components(assets))
|
(self.render_components(assets))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -53,18 +57,23 @@ impl Column {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn add(mut self, component: impl PageComponent) -> Self {
|
||||||
|
self.components.add(component);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn with_id(mut self, id: &str) -> Self {
|
pub fn with_id(mut self, id: &str) -> Self {
|
||||||
self.id.with_value(id);
|
self.id.with_value(id);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_classes(mut self, classes: Vec<&str>) -> Self {
|
pub fn set_classes(mut self, classes: &str) -> Self {
|
||||||
self.classes.add_classes(classes);
|
self.classes.set_classes(classes);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add(mut self, component: impl PageComponent) -> Self {
|
pub fn add_classes(mut self, classes: &str) -> Self {
|
||||||
self.components.add(component);
|
self.classes.add_classes(classes);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -79,8 +88,8 @@ impl Column {
|
||||||
self.id.option()
|
self.id.option()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn classes(&self) -> &Option<String> {
|
pub fn classes(&self, default: &str) -> Option<String> {
|
||||||
self.classes.option()
|
self.classes.option(default)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn template(&self) -> &str {
|
pub fn template(&self) -> &str {
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,9 @@ use crate::prelude::*;
|
||||||
pub struct Row {
|
pub struct Row {
|
||||||
renderable: fn() -> bool,
|
renderable: fn() -> bool,
|
||||||
weight : i8,
|
weight : i8,
|
||||||
|
columns : PageContainer,
|
||||||
id : OptIden,
|
id : OptIden,
|
||||||
classes : Classes,
|
classes : Classes,
|
||||||
columns : PageContainer,
|
|
||||||
template : String,
|
template : String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -15,13 +15,17 @@ impl PageComponent for Row {
|
||||||
Row {
|
Row {
|
||||||
renderable: always,
|
renderable: always,
|
||||||
weight : 0,
|
weight : 0,
|
||||||
id : OptIden::none(),
|
|
||||||
classes : Classes::some(vec!["row"]),
|
|
||||||
columns : PageContainer::new(),
|
columns : PageContainer::new(),
|
||||||
|
id : OptIden::none(),
|
||||||
|
classes : Classes::none(),
|
||||||
template : "default".to_owned(),
|
template : "default".to_owned(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn name(&self) -> &'static str {
|
||||||
|
"GridRow"
|
||||||
|
}
|
||||||
|
|
||||||
fn is_renderable(&self) -> bool {
|
fn is_renderable(&self) -> bool {
|
||||||
(self.renderable)()
|
(self.renderable)()
|
||||||
}
|
}
|
||||||
|
|
@ -32,7 +36,7 @@ impl PageComponent for Row {
|
||||||
|
|
||||||
fn default_render(&self, assets: &mut PageAssets) -> Markup {
|
fn default_render(&self, assets: &mut PageAssets) -> Markup {
|
||||||
html! {
|
html! {
|
||||||
div id=[self.id()] class=[self.classes()] {
|
div id=[self.id()] class=[self.classes("row")] {
|
||||||
(self.render_columns(assets))
|
(self.render_columns(assets))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -53,18 +57,23 @@ impl Row {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn add_column(mut self, column: grid::Column) -> Self {
|
||||||
|
self.columns.add(column);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn with_id(mut self, id: &str) -> Self {
|
pub fn with_id(mut self, id: &str) -> Self {
|
||||||
self.id.with_value(id);
|
self.id.with_value(id);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_classes(mut self, classes: Vec<&str>) -> Self {
|
pub fn set_classes(mut self, classes: &str) -> Self {
|
||||||
self.classes.add_classes(classes);
|
self.classes.set_classes(classes);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_column(mut self, column: grid::Column) -> Self {
|
pub fn add_classes(mut self, classes: &str) -> Self {
|
||||||
self.columns.add(column);
|
self.classes.add_classes(classes);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -79,8 +88,8 @@ impl Row {
|
||||||
self.id.option()
|
self.id.option()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn classes(&self) -> &Option<String> {
|
pub fn classes(&self, default: &str) -> Option<String> {
|
||||||
self.classes.option()
|
self.classes.option(default)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn template(&self) -> &str {
|
pub fn template(&self) -> &str {
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,8 @@ pub struct Image {
|
||||||
renderable: fn() -> bool,
|
renderable: fn() -> bool,
|
||||||
weight : i8,
|
weight : i8,
|
||||||
source : OptAttr,
|
source : OptAttr,
|
||||||
|
id : OptIden,
|
||||||
|
classes : Classes,
|
||||||
template : String,
|
template : String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -14,6 +16,8 @@ impl PageComponent for Image {
|
||||||
renderable: always,
|
renderable: always,
|
||||||
weight : 0,
|
weight : 0,
|
||||||
source : OptAttr::none(),
|
source : OptAttr::none(),
|
||||||
|
id : OptIden::none(),
|
||||||
|
classes : Classes::none(),
|
||||||
template : "default".to_owned(),
|
template : "default".to_owned(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -28,7 +32,10 @@ impl PageComponent for Image {
|
||||||
|
|
||||||
fn default_render(&self, _: &mut PageAssets) -> Markup {
|
fn default_render(&self, _: &mut PageAssets) -> Markup {
|
||||||
html! {
|
html! {
|
||||||
img src=[self.source()] class="img-fluid";
|
img
|
||||||
|
src=[self.source()]
|
||||||
|
id=[self.id()]
|
||||||
|
class=[self.classes("img-fluid")];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -56,6 +63,21 @@ impl Image {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn with_id(mut self, id: &str) -> Self {
|
||||||
|
self.id.with_value(id);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_classes(mut self, classes: &str) -> Self {
|
||||||
|
self.classes.set_classes(classes);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn add_classes(mut self, classes: &str) -> Self {
|
||||||
|
self.classes.add_classes(classes);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn using_template(mut self, template: &str) -> Self {
|
pub fn using_template(mut self, template: &str) -> Self {
|
||||||
self.template = template.to_owned();
|
self.template = template.to_owned();
|
||||||
self
|
self
|
||||||
|
|
@ -67,6 +89,14 @@ impl Image {
|
||||||
self.source.option()
|
self.source.option()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn id(&self) -> &Option<String> {
|
||||||
|
self.id.option()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn classes(&self, default: &str) -> Option<String> {
|
||||||
|
self.classes.option(default)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn template(&self) -> &str {
|
pub fn template(&self) -> &str {
|
||||||
self.template.as_str()
|
self.template.as_str()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -155,8 +155,9 @@ impl MenuItem {
|
||||||
pub struct Menu {
|
pub struct Menu {
|
||||||
renderable: fn() -> bool,
|
renderable: fn() -> bool,
|
||||||
weight : i8,
|
weight : i8,
|
||||||
id : OptIden,
|
|
||||||
items : PageContainer,
|
items : PageContainer,
|
||||||
|
id : OptIden,
|
||||||
|
classes : Classes,
|
||||||
template : String,
|
template : String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -166,8 +167,9 @@ impl PageComponent for Menu {
|
||||||
Menu {
|
Menu {
|
||||||
renderable: always,
|
renderable: always,
|
||||||
weight : 0,
|
weight : 0,
|
||||||
id : OptIden::none(),
|
|
||||||
items : PageContainer::new(),
|
items : PageContainer::new(),
|
||||||
|
id : OptIden::none(),
|
||||||
|
classes : Classes::none(),
|
||||||
template : "default".to_owned(),
|
template : "default".to_owned(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -195,7 +197,7 @@ impl PageComponent for Menu {
|
||||||
|
|
||||||
let id = assets.serial_id(self.name(), self.id());
|
let id = assets.serial_id(self.name(), self.id());
|
||||||
html! {
|
html! {
|
||||||
ul id=(id) class="sm sm-clean" {
|
ul id=(id) class=[self.classes("sm sm-clean")] {
|
||||||
(self.render_items(assets))
|
(self.render_items(assets))
|
||||||
}
|
}
|
||||||
script type="text/javascript" defer {
|
script type="text/javascript" defer {
|
||||||
|
|
@ -222,13 +224,23 @@ impl Menu {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn add(mut self, item: MenuItem) -> Self {
|
||||||
|
self.items.add(item);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn with_id(mut self, id: &str) -> Self {
|
pub fn with_id(mut self, id: &str) -> Self {
|
||||||
self.id.with_value(id);
|
self.id.with_value(id);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add(mut self, item: MenuItem) -> Self {
|
pub fn set_classes(mut self, classes: &str) -> Self {
|
||||||
self.items.add(item);
|
self.classes.set_classes(classes);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn add_classes(mut self, classes: &str) -> Self {
|
||||||
|
self.classes.add_classes(classes);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -243,6 +255,10 @@ impl Menu {
|
||||||
self.id.option()
|
self.id.option()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn classes(&self, default: &str) -> Option<String> {
|
||||||
|
self.classes.option(default)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn template(&self) -> &str {
|
pub fn template(&self) -> &str {
|
||||||
self.template.as_str()
|
self.template.as_str()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,4 +31,30 @@ impl ThemeTrait for BulmixTheme {
|
||||||
)
|
)
|
||||||
.add_jquery();
|
.add_jquery();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn render_component(
|
||||||
|
&self,
|
||||||
|
component: &dyn PageComponent,
|
||||||
|
assets: &mut PageAssets
|
||||||
|
) -> Option<Markup> {
|
||||||
|
match component.name() {
|
||||||
|
"GridRow" => {
|
||||||
|
let row = component.downcast_ref::<grid::Row>().unwrap();
|
||||||
|
Some(html! {
|
||||||
|
div id=[row.id()] class=[row.classes("columns")] {
|
||||||
|
(row.render_columns(assets))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
"GridColumn" => {
|
||||||
|
let col = component.downcast_ref::<grid::Column>().unwrap();
|
||||||
|
Some(html! {
|
||||||
|
div id=[col.id()] class=[col.classes("column")] {
|
||||||
|
(col.render_components(assets))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
_ => None
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,48 +1,23 @@
|
||||||
use crate::concat_string;
|
use crate::concat_string;
|
||||||
|
|
||||||
pub struct Classes(Option<String>);
|
pub struct Classes(String);
|
||||||
|
|
||||||
impl Classes {
|
impl Classes {
|
||||||
pub fn none() -> Self {
|
pub fn none() -> Self {
|
||||||
Classes(None)
|
Classes("".to_owned())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn some(classes: Vec<&str>) -> Self {
|
pub fn set_classes(&mut self, classes: &str) -> &mut Self {
|
||||||
let mut c = Classes::none();
|
self.0 = classes.to_owned();
|
||||||
c.add_classes(classes);
|
self
|
||||||
c
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_classes(&mut self, classes: Vec<&str>) {
|
pub fn add_classes(&mut self, classes: &str) -> &mut Self {
|
||||||
for class in classes.iter() {
|
self.0 = concat_string!(self.0, " ", classes).trim().to_owned();
|
||||||
self.add_class(class);
|
self
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_class(&mut self, class: &str) {
|
pub fn option(&self, default: &str) -> Option<String> {
|
||||||
let class = class.trim().replace(" ", "_");
|
Some(concat_string!(default.to_owned(), " ", self.0).trim().to_owned())
|
||||||
if !class.is_empty() {
|
|
||||||
match &self.0 {
|
|
||||||
None => self.0 = Some(class),
|
|
||||||
Some(classes) => if !classes.split(" ").any(|c| *c == class) {
|
|
||||||
self.0 = Some(concat_string!(classes, " ", class))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn classes(&self) -> &str {
|
|
||||||
match &self.0 {
|
|
||||||
Some(classes) => classes.as_str(),
|
|
||||||
None => "",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn has_classes(&self) -> bool {
|
|
||||||
self.0 != None
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn option(&self) -> &Option<String> {
|
|
||||||
&self.0
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,17 +6,18 @@ impl OptAttr {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn some(value: &str) -> Self {
|
pub fn some(value: &str) -> Self {
|
||||||
let mut o = OptAttr::none();
|
let mut o = OptAttr(None);
|
||||||
o.with_value(value);
|
o.with_value(value);
|
||||||
o
|
o
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_value(&mut self, value: &str) {
|
pub fn with_value(&mut self, value: &str) -> &mut Self {
|
||||||
let value = value.trim();
|
let value = value.trim();
|
||||||
self.0 = match value.is_empty() {
|
self.0 = match value.is_empty() {
|
||||||
true => None,
|
true => None,
|
||||||
false => Some(value.to_owned()),
|
false => Some(value.to_owned()),
|
||||||
};
|
};
|
||||||
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn option(&self) -> &Option<String> {
|
pub fn option(&self) -> &Option<String> {
|
||||||
|
|
|
||||||
|
|
@ -6,17 +6,18 @@ impl OptIden {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn some(id: &str) -> Self {
|
pub fn some(id: &str) -> Self {
|
||||||
let mut o = OptIden::none();
|
let mut o = OptIden(None);
|
||||||
o.with_value(id);
|
o.with_value(id);
|
||||||
o
|
o
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_value(&mut self, id: &str) {
|
pub fn with_value(&mut self, id: &str) -> &mut Self {
|
||||||
let id = id.trim();
|
let id = id.trim();
|
||||||
self.0 = match id.is_empty() {
|
self.0 = match id.is_empty() {
|
||||||
true => None,
|
true => None,
|
||||||
false => Some(id.replace(" ", "_")),
|
false => Some(id.replace(" ", "_")),
|
||||||
};
|
};
|
||||||
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn option(&self) -> &Option<String> {
|
pub fn option(&self) -> &Option<String> {
|
||||||
|
|
|
||||||
|
|
@ -45,8 +45,8 @@ pub struct Page<'a> {
|
||||||
title : OptAttr,
|
title : OptAttr,
|
||||||
description : OptAttr,
|
description : OptAttr,
|
||||||
assets : PageAssets,
|
assets : PageAssets,
|
||||||
body_classes: Classes,
|
|
||||||
regions : HashMap<&'a str, PageContainer>,
|
regions : HashMap<&'a str, PageContainer>,
|
||||||
|
body_classes: Classes,
|
||||||
template : String,
|
template : String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -64,9 +64,9 @@ impl<'a> Page<'a> {
|
||||||
},
|
},
|
||||||
title : OptAttr::none(),
|
title : OptAttr::none(),
|
||||||
description : OptAttr::none(),
|
description : OptAttr::none(),
|
||||||
body_classes: Classes::some(vec!["body"]),
|
|
||||||
assets : PageAssets::new(),
|
assets : PageAssets::new(),
|
||||||
regions : COMPONENTS.read().unwrap().clone(),
|
regions : COMPONENTS.read().unwrap().clone(),
|
||||||
|
body_classes: Classes::none(),
|
||||||
template : "default".to_owned(),
|
template : "default".to_owned(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -97,11 +97,6 @@ impl<'a> Page<'a> {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_body_classes(&mut self, classes: Vec<&str>) -> &mut Self {
|
|
||||||
self.body_classes.add_classes(classes);
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn add_to(
|
pub fn add_to(
|
||||||
&mut self,
|
&mut self,
|
||||||
region: &'a str,
|
region: &'a str,
|
||||||
|
|
@ -115,6 +110,16 @@ impl<'a> Page<'a> {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_body_classes(&mut self, classes: &str) -> &mut Self {
|
||||||
|
self.body_classes.set_classes(classes);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn add_body_classes(&mut self, classes: &str) -> &mut Self {
|
||||||
|
self.body_classes.add_classes(classes);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn using_template(&mut self, template: &str) -> &mut Self {
|
pub fn using_template(&mut self, template: &str) -> &mut Self {
|
||||||
self.template = template.to_owned();
|
self.template = template.to_owned();
|
||||||
self
|
self
|
||||||
|
|
@ -138,14 +143,14 @@ impl<'a> Page<'a> {
|
||||||
self.description.option()
|
self.description.option()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn body_classes(&mut self) -> &str {
|
|
||||||
self.body_classes.classes()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn assets(&mut self) -> &mut PageAssets {
|
pub fn assets(&mut self) -> &mut PageAssets {
|
||||||
&mut self.assets
|
&mut self.assets
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn body_classes(&self, default: &str) -> Option<String> {
|
||||||
|
self.body_classes.option(default)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn template(&self) -> &str {
|
pub fn template(&self) -> &str {
|
||||||
self.template.as_str()
|
self.template.as_str()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ pub trait ThemeTrait: Send + Sync {
|
||||||
|
|
||||||
fn render_page_body(&self, page: &mut Page) -> Markup {
|
fn render_page_body(&self, page: &mut Page) -> Markup {
|
||||||
html! {
|
html! {
|
||||||
body class=(page.body_classes()) {
|
body class=[page.body_classes("body")] {
|
||||||
@match page.template() {
|
@match page.template() {
|
||||||
"admin" => {
|
"admin" => {
|
||||||
@for region in &["top-menu", "side-menu", "content"] {
|
@for region in &["top-menu", "side-menu", "content"] {
|
||||||
|
|
@ -85,8 +85,8 @@ pub trait ThemeTrait: Send + Sync {
|
||||||
Cómo usarlo:
|
Cómo usarlo:
|
||||||
|
|
||||||
match component.name() {
|
match component.name() {
|
||||||
"block" => {
|
"Block" => {
|
||||||
let block = component.downcast_mut::<Block>().unwrap();
|
let block = component.downcast_ref::<Block>().unwrap();
|
||||||
match block.template() {
|
match block.template() {
|
||||||
"default" => Some(block_default(block)),
|
"default" => Some(block_default(block)),
|
||||||
_ => None
|
_ => None
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue