Añade alteración de componentes antes del render
Los componentes implementan a la vez el paradigma "builder" y la modificación por "setters" para poder ser modificados durante la creación de la página o alterados antes de ser renderizados.
This commit is contained in:
parent
e11b36f7ed
commit
ba4cc982be
22 changed files with 872 additions and 412 deletions
|
|
@ -13,12 +13,12 @@ pub struct Block {
|
|||
impl PageComponent for Block {
|
||||
fn new() -> Self {
|
||||
Block {
|
||||
renderable: always,
|
||||
renderable: render_always,
|
||||
weight : 0,
|
||||
components: PageContainer::new(),
|
||||
title : OptAttr::none(),
|
||||
id : OptIden::none(),
|
||||
classes : Classes::none(),
|
||||
title : OptAttr::new(),
|
||||
id : OptIden::new(),
|
||||
classes : Classes::new_with_default("block"),
|
||||
template : "default".to_owned(),
|
||||
}
|
||||
}
|
||||
|
|
@ -34,7 +34,7 @@ impl PageComponent for Block {
|
|||
fn default_render(&self, assets: &mut PageAssets) -> Markup {
|
||||
let id = assets.serial_id(self.name(), self.id());
|
||||
html! {
|
||||
div id=(id) class=[self.classes("block")] {
|
||||
div id=(id) class=[self.classes()] {
|
||||
@match self.title() {
|
||||
Some(title) => h2 class="block-title" { (title) },
|
||||
None => {}
|
||||
|
|
@ -63,36 +63,63 @@ impl Block {
|
|||
// Block BUILDER.
|
||||
|
||||
pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self {
|
||||
self.renderable = renderable;
|
||||
self.alter_renderable(renderable);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_weight(mut self, weight: i8) -> Self {
|
||||
self.weight = weight;
|
||||
self.alter_weight(weight);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_title(mut self, title: &str) -> Self {
|
||||
self.title.with_value(title);
|
||||
self.alter_title(title);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_id(mut self, id: &str) -> Self {
|
||||
self.id.with_value(id);
|
||||
self.alter_id(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);
|
||||
pub fn with_classes(mut self, classes: &str, op: ClassesOp) -> Self {
|
||||
self.alter_classes(classes, op);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn using_template(mut self, template: &str) -> Self {
|
||||
self.alter_template(template);
|
||||
self
|
||||
}
|
||||
|
||||
// Block ALTER.
|
||||
|
||||
pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self {
|
||||
self.renderable = renderable;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn alter_weight(&mut self, weight: i8) -> &mut Self {
|
||||
self.weight = weight;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn alter_title(&mut self, title: &str) -> &mut Self {
|
||||
self.title.with_value(title);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn alter_id(&mut self, id: &str) -> &mut Self {
|
||||
self.id.with_value(id);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn alter_classes(&mut self, classes: &str, op: ClassesOp) -> &mut Self {
|
||||
self.classes.alter(classes, op);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn alter_template(&mut self, template: &str) -> &mut Self {
|
||||
self.template = template.to_owned();
|
||||
self
|
||||
}
|
||||
|
|
@ -107,15 +134,11 @@ impl Block {
|
|||
self.id.option()
|
||||
}
|
||||
|
||||
pub fn classes(&self, default: &str) -> Option<String> {
|
||||
self.classes.option(default)
|
||||
pub fn classes(&self) -> &Option<String> {
|
||||
self.classes.option()
|
||||
}
|
||||
|
||||
pub fn template(&self) -> &str {
|
||||
self.template.as_str()
|
||||
}
|
||||
}
|
||||
|
||||
fn always() -> bool {
|
||||
true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ pub struct Chunck {
|
|||
impl PageComponent for Chunck {
|
||||
fn new() -> Self {
|
||||
Chunck {
|
||||
renderable: always,
|
||||
renderable: render_always,
|
||||
weight : 0,
|
||||
html : html! {},
|
||||
template : "default".to_owned(),
|
||||
|
|
@ -32,24 +32,49 @@ impl PageComponent for Chunck {
|
|||
|
||||
impl Chunck {
|
||||
pub fn with(html: Markup) -> Self {
|
||||
let mut chunck = Chunck::new();
|
||||
chunck.html = html;
|
||||
chunck
|
||||
Chunck::new().with_html(html)
|
||||
}
|
||||
|
||||
// Chunck BUILDER.
|
||||
|
||||
pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self {
|
||||
self.renderable = renderable;
|
||||
self.alter_renderable(renderable);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_weight(mut self, weight: i8) -> Self {
|
||||
self.weight = weight;
|
||||
self.alter_weight(weight);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_html(mut self, html: Markup) -> Self {
|
||||
self.alter_html(html);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn using_template(mut self, template: &str) -> Self {
|
||||
self.alter_template(template);
|
||||
self
|
||||
}
|
||||
|
||||
// Chunck ALTER.
|
||||
|
||||
pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self {
|
||||
self.renderable = renderable;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn alter_weight(&mut self, weight: i8) -> &mut Self {
|
||||
self.weight = weight;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn alter_html(&mut self, html: Markup) -> &mut Self {
|
||||
self.html = html;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn alter_template(&mut self, template: &str) -> &mut Self {
|
||||
self.template = template.to_owned();
|
||||
self
|
||||
}
|
||||
|
|
@ -64,7 +89,3 @@ impl Chunck {
|
|||
self.template.as_str()
|
||||
}
|
||||
}
|
||||
|
||||
fn always() -> bool {
|
||||
true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,18 +9,20 @@ pub struct Container {
|
|||
container : ContainerType,
|
||||
id : OptIden,
|
||||
classes : Classes,
|
||||
inner_classes: Classes,
|
||||
template : String,
|
||||
}
|
||||
|
||||
impl PageComponent for Container {
|
||||
fn new() -> Self {
|
||||
Container {
|
||||
renderable: always,
|
||||
renderable : render_always,
|
||||
weight : 0,
|
||||
components : PageContainer::new(),
|
||||
container : ContainerType::Wrapper,
|
||||
id : OptIden::none(),
|
||||
classes : Classes::none(),
|
||||
id : OptIden::new(),
|
||||
classes : Classes::new_with_default("container"),
|
||||
inner_classes: Classes::new_with_default("container"),
|
||||
template : "default".to_owned(),
|
||||
}
|
||||
}
|
||||
|
|
@ -36,35 +38,35 @@ impl PageComponent for Container {
|
|||
fn default_render(&self, assets: &mut PageAssets) -> Markup {
|
||||
match self.container_type() {
|
||||
ContainerType::Header => html! {
|
||||
header id=[self.id()] class=[self.classes("header")] {
|
||||
div class="container" {
|
||||
header id=[self.id()] class=[self.classes()] {
|
||||
div class=[self.inner_classes()] {
|
||||
(self.components().render(assets))
|
||||
}
|
||||
}
|
||||
},
|
||||
ContainerType::Footer => html! {
|
||||
footer id=[self.id()] class=[self.classes("footer")] {
|
||||
div class="container" {
|
||||
footer id=[self.id()] class=[self.classes()] {
|
||||
div class=[self.inner_classes()] {
|
||||
(self.components().render(assets))
|
||||
}
|
||||
}
|
||||
},
|
||||
ContainerType::Main => html! {
|
||||
main id=[self.id()] class=[self.classes("main")] {
|
||||
div class="container" {
|
||||
main id=[self.id()] class=[self.classes()] {
|
||||
div class=[self.inner_classes()] {
|
||||
(self.components().render(assets))
|
||||
}
|
||||
}
|
||||
},
|
||||
ContainerType::Section => html! {
|
||||
section id=[self.id()] class=[self.classes("section")] {
|
||||
div class="container" {
|
||||
section id=[self.id()] class=[self.classes()] {
|
||||
div class=[self.inner_classes()] {
|
||||
(self.components().render(assets))
|
||||
}
|
||||
}
|
||||
},
|
||||
_ => html! {
|
||||
div id=[self.id()] class=[self.classes("container")] {
|
||||
div id=[self.id()] class=[self.classes()] {
|
||||
(self.components().render(assets))
|
||||
}
|
||||
}
|
||||
|
|
@ -74,25 +76,25 @@ impl PageComponent for Container {
|
|||
|
||||
impl Container {
|
||||
pub fn header() -> Self {
|
||||
let mut c = Container::new();
|
||||
let mut c = Container::new().with_classes("header", ClassesOp::SetDefault);
|
||||
c.container = ContainerType::Header;
|
||||
c
|
||||
}
|
||||
|
||||
pub fn footer() -> Self {
|
||||
let mut c = Container::new();
|
||||
let mut c = Container::new().with_classes("footer", ClassesOp::SetDefault);
|
||||
c.container = ContainerType::Footer;
|
||||
c
|
||||
}
|
||||
|
||||
pub fn main() -> Self {
|
||||
let mut c = Container::new();
|
||||
let mut c = Container::new().with_classes("main", ClassesOp::SetDefault);
|
||||
c.container = ContainerType::Main;
|
||||
c
|
||||
}
|
||||
|
||||
pub fn section() -> Self {
|
||||
let mut c = Container::new();
|
||||
let mut c = Container::new().with_classes("section", ClassesOp::SetDefault);
|
||||
c.container = ContainerType::Section;
|
||||
c
|
||||
}
|
||||
|
|
@ -111,31 +113,63 @@ impl Container {
|
|||
// Container BUILDER.
|
||||
|
||||
pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self {
|
||||
self.renderable = renderable;
|
||||
self.alter_renderable(renderable);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_weight(mut self, weight: i8) -> Self {
|
||||
self.weight = weight;
|
||||
self.alter_weight(weight);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_id(mut self, id: &str) -> Self {
|
||||
self.id.with_value(id);
|
||||
self.alter_id(id);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn set_classes(mut self, classes: &str) -> Self {
|
||||
self.classes.set_classes(classes);
|
||||
pub fn with_classes(mut self, classes: &str, op: ClassesOp) -> Self {
|
||||
self.alter_classes(classes, op);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn add_classes(mut self, classes: &str) -> Self {
|
||||
self.classes.add_classes(classes);
|
||||
pub fn with_inner_classes(mut self, classes: &str, op: ClassesOp) -> Self {
|
||||
self.alter_inner_classes(classes, op);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn using_template(mut self, template: &str) -> Self {
|
||||
self.alter_template(template);
|
||||
self
|
||||
}
|
||||
|
||||
// Container ALTER.
|
||||
|
||||
pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self {
|
||||
self.renderable = renderable;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn alter_weight(&mut self, weight: i8) -> &mut Self {
|
||||
self.weight = weight;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn alter_id(&mut self, id: &str) -> &mut Self {
|
||||
self.id.with_value(id);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn alter_classes(&mut self, classes: &str, op: ClassesOp) -> &mut Self {
|
||||
self.classes.alter(classes, op);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn alter_inner_classes(&mut self, classes: &str, op: ClassesOp) -> &mut Self {
|
||||
self.inner_classes.alter(classes, op);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn alter_template(&mut self, template: &str) -> &mut Self {
|
||||
self.template = template.to_owned();
|
||||
self
|
||||
}
|
||||
|
|
@ -150,15 +184,15 @@ impl Container {
|
|||
self.id.option()
|
||||
}
|
||||
|
||||
pub fn classes(&self, default: &str) -> Option<String> {
|
||||
self.classes.option(default)
|
||||
pub fn classes(&self) -> &Option<String> {
|
||||
self.classes.option()
|
||||
}
|
||||
|
||||
pub fn inner_classes(&self) -> &Option<String> {
|
||||
self.inner_classes.option()
|
||||
}
|
||||
|
||||
pub fn template(&self) -> &str {
|
||||
self.template.as_str()
|
||||
}
|
||||
}
|
||||
|
||||
fn always() -> bool {
|
||||
true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,16 +17,17 @@ pub struct Button {
|
|||
impl PageComponent for Button {
|
||||
fn new() -> Self {
|
||||
Button {
|
||||
renderable : always,
|
||||
renderable : render_always,
|
||||
weight : 0,
|
||||
button_type: ButtonType::Button,
|
||||
name : OptAttr::none(),
|
||||
value : OptAttr::none(),
|
||||
autofocus : OptAttr::none(),
|
||||
disabled : OptAttr::none(),
|
||||
classes : Classes::none(),
|
||||
name : OptAttr::new(),
|
||||
value : OptAttr::new(),
|
||||
autofocus : OptAttr::new(),
|
||||
disabled : OptAttr::new(),
|
||||
classes : Classes::new_with_default("btn btn-primary"),
|
||||
template : "default".to_owned(),
|
||||
}
|
||||
.with_classes("form-button", ClassesOp::AddFirst)
|
||||
}
|
||||
|
||||
fn is_renderable(&self) -> bool {
|
||||
|
|
@ -38,10 +39,10 @@ impl PageComponent for Button {
|
|||
}
|
||||
|
||||
fn default_render(&self, _: &mut PageAssets) -> Markup {
|
||||
let (button_type, button_class) = match self.button_type() {
|
||||
ButtonType::Button => ("button", "btn btn-primary form-button"),
|
||||
ButtonType::Reset => ("reset", "btn btn-primary form-reset" ),
|
||||
ButtonType::Submit => ("submit", "btn btn-primary form-submit"),
|
||||
let button_type = match self.button_type() {
|
||||
ButtonType::Button => "button",
|
||||
ButtonType::Reset => "reset",
|
||||
ButtonType::Submit => "submit",
|
||||
};
|
||||
let id = match self.name() {
|
||||
Some(name) => Some(concat_string!("edit-", name)),
|
||||
|
|
@ -51,7 +52,7 @@ impl PageComponent for Button {
|
|||
button
|
||||
type=(button_type)
|
||||
id=[id]
|
||||
class=[self.classes(button_class)]
|
||||
class=[self.classes()]
|
||||
name=[self.name()]
|
||||
value=[self.value()]
|
||||
autofocus=[self.autofocus()]
|
||||
|
|
@ -72,13 +73,17 @@ impl Button {
|
|||
}
|
||||
|
||||
pub fn reset(value: &str) -> Self {
|
||||
let mut button = Button::new().with_value(value);
|
||||
let mut button = Button::new()
|
||||
.with_classes("form-reset", ClassesOp::Replace("form-button"))
|
||||
.with_value(value);
|
||||
button.button_type = ButtonType::Reset;
|
||||
button
|
||||
}
|
||||
|
||||
pub fn submit(value: &str) -> Self {
|
||||
let mut button = Button::new().with_value(value);
|
||||
let mut button = Button::new()
|
||||
.with_classes("form-submit", ClassesOp::Replace("form-button"))
|
||||
.with_value(value);
|
||||
button.button_type = ButtonType::Submit;
|
||||
button
|
||||
}
|
||||
|
|
@ -86,26 +91,68 @@ impl Button {
|
|||
// Button BUILDER.
|
||||
|
||||
pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self {
|
||||
self.renderable = renderable;
|
||||
self.alter_renderable(renderable);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_weight(mut self, weight: i8) -> Self {
|
||||
self.weight = weight;
|
||||
self.alter_weight(weight);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_name(mut self, name: &str) -> Self {
|
||||
self.name.with_value(name);
|
||||
self.alter_name(name);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_value(mut self, value: &str) -> Self {
|
||||
self.value.with_value(value);
|
||||
self.alter_value(value);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_autofocus(mut self, toggle: bool) -> Self {
|
||||
self.alter_autofocus(toggle);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_disabled(mut self, toggle: bool) -> Self {
|
||||
self.alter_disabled(toggle);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_classes(mut self, classes: &str, op: ClassesOp) -> Self {
|
||||
self.alter_classes(classes, op);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn using_template(mut self, template: &str) -> Self {
|
||||
self.alter_template(template);
|
||||
self
|
||||
}
|
||||
|
||||
// Button ALTER.
|
||||
|
||||
pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self {
|
||||
self.renderable = renderable;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn alter_weight(&mut self, weight: i8) -> &mut Self {
|
||||
self.weight = weight;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn alter_name(&mut self, name: &str) -> &mut Self {
|
||||
self.name.with_value(name);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn alter_value(&mut self, value: &str) -> &mut Self {
|
||||
self.value.with_value(value);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn alter_autofocus(&mut self, toggle: bool) -> &mut Self {
|
||||
self.autofocus.with_value(match toggle {
|
||||
true => "autofocus",
|
||||
false => "",
|
||||
|
|
@ -113,7 +160,7 @@ impl Button {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn with_disabled(mut self, toggle: bool) -> Self {
|
||||
pub fn alter_disabled(&mut self, toggle: bool) -> &mut Self {
|
||||
self.disabled.with_value(match toggle {
|
||||
true => "disabled",
|
||||
false => "",
|
||||
|
|
@ -121,17 +168,12 @@ impl Button {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn set_classes(mut self, classes: &str) -> Self {
|
||||
self.classes.set_classes(classes);
|
||||
pub fn alter_classes(&mut self, classes: &str, op: ClassesOp) -> &mut Self {
|
||||
self.classes.alter(classes, op);
|
||||
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 alter_template(&mut self, template: &str) -> &mut Self {
|
||||
self.template = template.to_owned();
|
||||
self
|
||||
}
|
||||
|
|
@ -158,15 +200,11 @@ impl Button {
|
|||
self.disabled.option()
|
||||
}
|
||||
|
||||
pub fn classes(&self, default: &str) -> Option<String> {
|
||||
self.classes.option(default)
|
||||
pub fn classes(&self) -> &Option<String> {
|
||||
self.classes.option()
|
||||
}
|
||||
|
||||
pub fn template(&self) -> &str {
|
||||
self.template.as_str()
|
||||
}
|
||||
}
|
||||
|
||||
fn always() -> bool {
|
||||
true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,21 +20,22 @@ pub struct Date {
|
|||
impl PageComponent for Date {
|
||||
fn new() -> Self {
|
||||
Date {
|
||||
renderable : always,
|
||||
renderable : render_always,
|
||||
weight : 0,
|
||||
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(),
|
||||
classes : Classes::none(),
|
||||
name : OptAttr::new(),
|
||||
value : OptAttr::new(),
|
||||
label : OptAttr::new(),
|
||||
placeholder : OptAttr::new(),
|
||||
autofocus : OptAttr::new(),
|
||||
autocomplete: OptAttr::new(),
|
||||
disabled : OptAttr::new(),
|
||||
readonly : OptAttr::new(),
|
||||
required : OptAttr::new(),
|
||||
help_text : OptAttr::new(),
|
||||
classes : Classes::new_with_default("form-item"),
|
||||
template : "default".to_owned(),
|
||||
}
|
||||
.with_classes("form-type-date", ClassesOp::AddFirst)
|
||||
}
|
||||
|
||||
fn is_renderable(&self) -> bool {
|
||||
|
|
@ -46,18 +47,12 @@ impl PageComponent for Date {
|
|||
}
|
||||
|
||||
fn default_render(&self, _: &mut PageAssets) -> Markup {
|
||||
let (classes, id) = match self.name() {
|
||||
Some(name) => (
|
||||
concat_string!("form-item form-item-", name, " form-type-date"),
|
||||
Some(concat_string!("edit-", name))
|
||||
),
|
||||
None => (
|
||||
"form-item form-type-date".to_owned(),
|
||||
None
|
||||
)
|
||||
let id = match self.name() {
|
||||
Some(name) => Some(concat_string!("edit-", name)),
|
||||
None => None,
|
||||
};
|
||||
html! {
|
||||
div class=[self.classes(classes.as_str())] {
|
||||
div class=[self.classes()] {
|
||||
@match self.label() {
|
||||
Some(label) => label class="form-label" for=[&id] {
|
||||
(label) " "
|
||||
|
|
@ -96,36 +91,108 @@ impl Date {
|
|||
// Date BUILDER.
|
||||
|
||||
pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self {
|
||||
self.renderable = renderable;
|
||||
self.alter_renderable(renderable);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_weight(mut self, weight: i8) -> Self {
|
||||
self.weight = weight;
|
||||
self.alter_weight(weight);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_name(mut self, name: &str) -> Self {
|
||||
self.name.with_value(name);
|
||||
self.alter_name(name);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_value(mut self, value: &str) -> Self {
|
||||
self.value.with_value(value);
|
||||
self.alter_value(value);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_label(mut self, label: &str) -> Self {
|
||||
self.label.with_value(label);
|
||||
self.alter_label(label);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_placeholder(mut self, placeholder: &str) -> Self {
|
||||
self.placeholder.with_value(placeholder);
|
||||
self.alter_placeholder(placeholder);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_autofocus(mut self, toggle: bool) -> Self {
|
||||
self.alter_autofocus(toggle);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_autocomplete(mut self, toggle: bool) -> Self {
|
||||
self.alter_autocomplete(toggle);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_disabled(mut self, toggle: bool) -> Self {
|
||||
self.alter_disabled(toggle);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_readonly(mut self, toggle: bool) -> Self {
|
||||
self.alter_readonly(toggle);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_required(mut self, toggle: bool) -> Self {
|
||||
self.alter_required(toggle);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_help_text(mut self, help_text: &str) -> Self {
|
||||
self.alter_help_text(help_text);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_classes(mut self, classes: &str, op: ClassesOp) -> Self {
|
||||
self.alter_classes(classes, op);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn using_template(mut self, template: &str) -> Self {
|
||||
self.alter_template(template);
|
||||
self
|
||||
}
|
||||
|
||||
// Date ALTER.
|
||||
|
||||
pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self {
|
||||
self.renderable = renderable;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn alter_weight(&mut self, weight: i8) -> &mut Self {
|
||||
self.weight = weight;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn alter_name(&mut self, name: &str) -> &mut Self {
|
||||
self.name.with_value(name);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn alter_value(&mut self, value: &str) -> &mut Self {
|
||||
self.value.with_value(value);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn alter_label(&mut self, label: &str) -> &mut Self {
|
||||
self.label.with_value(label);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn alter_placeholder(&mut self, placeholder: &str) -> &mut Self {
|
||||
self.placeholder.with_value(placeholder);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn alter_autofocus(&mut self, toggle: bool) -> &mut Self {
|
||||
self.autofocus.with_value(match toggle {
|
||||
true => "autofocus",
|
||||
false => "",
|
||||
|
|
@ -133,7 +200,7 @@ impl Date {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn with_autocomplete(mut self, toggle: bool) -> Self {
|
||||
pub fn alter_autocomplete(&mut self, toggle: bool) -> &mut Self {
|
||||
self.autocomplete.with_value(match toggle {
|
||||
true => "",
|
||||
false => "off",
|
||||
|
|
@ -141,7 +208,7 @@ impl Date {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn with_disabled(mut self, toggle: bool) -> Self {
|
||||
pub fn alter_disabled(&mut self, toggle: bool) -> &mut Self {
|
||||
self.disabled.with_value(match toggle {
|
||||
true => "disabled",
|
||||
false => "",
|
||||
|
|
@ -149,7 +216,7 @@ impl Date {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn with_readonly(mut self, toggle: bool) -> Self {
|
||||
pub fn alter_readonly(&mut self, toggle: bool) -> &mut Self {
|
||||
self.readonly.with_value(match toggle {
|
||||
true => "readonly",
|
||||
false => "",
|
||||
|
|
@ -157,7 +224,7 @@ impl Date {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn with_required(mut self, toggle: bool) -> Self {
|
||||
pub fn alter_required(&mut self, toggle: bool) -> &mut Self {
|
||||
self.required.with_value(match toggle {
|
||||
true => "required",
|
||||
false => "",
|
||||
|
|
@ -165,22 +232,17 @@ impl Date {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn with_help_text(mut self, help_text: &str) -> Self {
|
||||
pub fn alter_help_text(&mut self, help_text: &str) -> &mut Self {
|
||||
self.help_text.with_value(help_text);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn set_classes(mut self, classes: &str) -> Self {
|
||||
self.classes.set_classes(classes);
|
||||
pub fn alter_classes(&mut self, classes: &str, op: ClassesOp) -> &mut Self {
|
||||
self.classes.alter(classes, op);
|
||||
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 alter_template(&mut self, template: &str) -> &mut Self {
|
||||
self.template = template.to_owned();
|
||||
self
|
||||
}
|
||||
|
|
@ -227,15 +289,11 @@ impl Date {
|
|||
self.help_text.option()
|
||||
}
|
||||
|
||||
pub fn classes(&self, default: &str) -> Option<String> {
|
||||
self.classes.option(default)
|
||||
pub fn classes(&self) -> &Option<String> {
|
||||
self.classes.option()
|
||||
}
|
||||
|
||||
pub fn template(&self) -> &str {
|
||||
self.template.as_str()
|
||||
}
|
||||
}
|
||||
|
||||
fn always() -> bool {
|
||||
true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,14 +17,14 @@ pub struct Form {
|
|||
impl PageComponent for Form {
|
||||
fn new() -> Self {
|
||||
Form {
|
||||
renderable: always,
|
||||
renderable: render_always,
|
||||
weight : 0,
|
||||
elements : PageContainer::new(),
|
||||
action : OptAttr::none(),
|
||||
charset : OptAttr::some("UTF-8"),
|
||||
action : OptAttr::new(),
|
||||
charset : OptAttr::new_with_value("UTF-8"),
|
||||
method : FormMethod::Post,
|
||||
id : OptIden::none(),
|
||||
classes : Classes::none(),
|
||||
id : OptIden::new(),
|
||||
classes : Classes::new_with_default("form"),
|
||||
template : "default".to_owned(),
|
||||
}
|
||||
}
|
||||
|
|
@ -45,7 +45,7 @@ impl PageComponent for Form {
|
|||
html! {
|
||||
form
|
||||
id=[self.id()]
|
||||
class=[self.classes("form")]
|
||||
class=[self.classes()]
|
||||
action=[self.action()]
|
||||
method=[method]
|
||||
accept-charset=[self.charset()]
|
||||
|
|
@ -72,46 +72,83 @@ impl Form {
|
|||
// Form BUILDER.
|
||||
|
||||
pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self {
|
||||
self.renderable = renderable;
|
||||
self.alter_renderable(renderable);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_weight(mut self, weight: i8) -> Self {
|
||||
self.weight = weight;
|
||||
self.alter_weight(weight);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_action(mut self, action: &str) -> Self {
|
||||
self.action.with_value(action);
|
||||
self.alter_action(action);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_charset(mut self, charset: &str) -> Self {
|
||||
self.charset.with_value(charset);
|
||||
self.alter_charset(charset);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_method(mut self, method: FormMethod) -> Self {
|
||||
self.method = method;
|
||||
self.alter_method(method);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_id(mut self, id: &str) -> Self {
|
||||
self.id.with_value(id);
|
||||
self.alter_id(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);
|
||||
pub fn with_classes(mut self, classes: &str, op: ClassesOp) -> Self {
|
||||
self.alter_classes(classes, op);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn using_template(mut self, template: &str) -> Self {
|
||||
self.alter_template(template);
|
||||
self
|
||||
}
|
||||
|
||||
// Form ALTER.
|
||||
|
||||
pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self {
|
||||
self.renderable = renderable;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn alter_weight(&mut self, weight: i8) -> &mut Self {
|
||||
self.weight = weight;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn alter_action(&mut self, action: &str) -> &mut Self {
|
||||
self.action.with_value(action);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn alter_charset(&mut self, charset: &str) -> &mut Self {
|
||||
self.charset.with_value(charset);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn alter_method(&mut self, method: FormMethod) -> &mut Self {
|
||||
self.method = method;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn alter_id(&mut self, id: &str) -> &mut Self {
|
||||
self.id.with_value(id);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn alter_classes(&mut self, classes: &str, op: ClassesOp) -> &mut Self {
|
||||
self.classes.alter(classes, op);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn alter_template(&mut self, template: &str) -> &mut Self {
|
||||
self.template = template.to_owned();
|
||||
self
|
||||
}
|
||||
|
|
@ -134,15 +171,11 @@ impl Form {
|
|||
self.id.option()
|
||||
}
|
||||
|
||||
pub fn classes(&self, default: &str) -> Option<String> {
|
||||
self.classes.option(default)
|
||||
pub fn classes(&self) -> &Option<String> {
|
||||
self.classes.option()
|
||||
}
|
||||
|
||||
pub fn template(&self) -> &str {
|
||||
self.template.as_str()
|
||||
}
|
||||
}
|
||||
|
||||
fn always() -> bool {
|
||||
true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@ impl PageComponent for Hidden {
|
|||
fn new() -> Self {
|
||||
Hidden {
|
||||
weight: 0,
|
||||
name : OptIden::none(),
|
||||
value : OptAttr::none(),
|
||||
name : OptIden::new(),
|
||||
value : OptAttr::new(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -32,24 +32,39 @@ impl PageComponent for Hidden {
|
|||
|
||||
impl Hidden {
|
||||
pub fn set(name: &str, value: &str) -> Self {
|
||||
Hidden::new()
|
||||
.with_name(name)
|
||||
.with_value(value)
|
||||
Hidden::new().with_name(name).with_value(value)
|
||||
}
|
||||
|
||||
// Hidden BUILDER.
|
||||
|
||||
pub fn with_weight(mut self, weight: i8) -> Self {
|
||||
self.weight = weight;
|
||||
self.alter_weight(weight);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_name(mut self, name: &str) -> Self {
|
||||
self.name.with_value(name);
|
||||
self.alter_name(name);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_value(mut self, value: &str) -> Self {
|
||||
self.alter_value(value);
|
||||
self
|
||||
}
|
||||
|
||||
// Hidden ALTER.
|
||||
|
||||
pub fn alter_weight(&mut self, weight: i8) -> &mut Self {
|
||||
self.weight = weight;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn alter_name(&mut self, name: &str) -> &mut Self {
|
||||
self.name.with_value(name);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn alter_value(&mut self, value: &str) -> &mut Self {
|
||||
self.value.with_value(value);
|
||||
self
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,25 +26,26 @@ pub struct Input {
|
|||
impl PageComponent for Input {
|
||||
fn new() -> Self {
|
||||
Input {
|
||||
renderable : always,
|
||||
renderable : render_always,
|
||||
weight : 0,
|
||||
input_type : InputType::Textfield,
|
||||
name : OptIden::none(),
|
||||
value : OptAttr::none(),
|
||||
label : OptAttr::none(),
|
||||
name : OptIden::new(),
|
||||
value : OptAttr::new(),
|
||||
label : OptAttr::new(),
|
||||
size : Some(60),
|
||||
minlength : None,
|
||||
maxlength : Some(128),
|
||||
placeholder : OptAttr::none(),
|
||||
autofocus : OptAttr::none(),
|
||||
autocomplete: OptAttr::none(),
|
||||
disabled : OptAttr::none(),
|
||||
readonly : OptAttr::none(),
|
||||
required : OptAttr::none(),
|
||||
help_text : OptAttr::none(),
|
||||
classes : Classes::none(),
|
||||
placeholder : OptAttr::new(),
|
||||
autofocus : OptAttr::new(),
|
||||
autocomplete: OptAttr::new(),
|
||||
disabled : OptAttr::new(),
|
||||
readonly : OptAttr::new(),
|
||||
required : OptAttr::new(),
|
||||
help_text : OptAttr::new(),
|
||||
classes : Classes::new_with_default("form-item"),
|
||||
template : "default".to_owned(),
|
||||
}
|
||||
.with_classes("form-type-textfield", ClassesOp::AddFirst)
|
||||
}
|
||||
|
||||
fn is_renderable(&self) -> bool {
|
||||
|
|
@ -55,27 +56,28 @@ impl PageComponent for Input {
|
|||
self.weight
|
||||
}
|
||||
|
||||
fn before_render(&mut self, _: &mut PageAssets) {
|
||||
if let Some(name) = self.name() {
|
||||
let class = concat_string!("form-item-", name);
|
||||
self.alter_classes(class.as_str(), ClassesOp::AddFirst);
|
||||
}
|
||||
}
|
||||
|
||||
fn default_render(&self, _: &mut PageAssets) -> Markup {
|
||||
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"),
|
||||
InputType::Telephone => ("tel", "form-type-telephone"),
|
||||
InputType::Textfield => ("text", "form-type-textfield"),
|
||||
InputType::Url => ("url", "form-type-url")
|
||||
let type_input = match self.input_type() {
|
||||
InputType::Email => "email",
|
||||
InputType::Password => "password",
|
||||
InputType::Search => "search",
|
||||
InputType::Telephone => "tel",
|
||||
InputType::Textfield => "text",
|
||||
InputType::Url => "url",
|
||||
};
|
||||
let (class, id) = match self.name() {
|
||||
Some(name) => (
|
||||
concat_string!("form-item form-item-", name, " ", type_class),
|
||||
Some(concat_string!("edit-", name))
|
||||
),
|
||||
None => (
|
||||
concat_string!("form-item ", type_class),
|
||||
None
|
||||
)
|
||||
let id = match self.name() {
|
||||
Some(name) => Some(concat_string!("edit-", name)),
|
||||
None => None,
|
||||
};
|
||||
html! {
|
||||
div class=(class) {
|
||||
div class=[self.classes()] {
|
||||
@match self.label() {
|
||||
Some(label) => label class="form-label" for=[&id] {
|
||||
(label) " "
|
||||
|
|
@ -118,31 +120,36 @@ impl Input {
|
|||
}
|
||||
|
||||
pub fn password() -> Self {
|
||||
let mut input = Input::new();
|
||||
let mut input = Input::new()
|
||||
.with_classes("form-type-password", ClassesOp::Replace("form-type-textfield"));
|
||||
input.input_type = InputType::Password;
|
||||
input
|
||||
}
|
||||
|
||||
pub fn search() -> Self {
|
||||
let mut input = Input::new();
|
||||
let mut input = Input::new()
|
||||
.with_classes("form-type-search", ClassesOp::Replace("form-type-textfield"));
|
||||
input.input_type = InputType::Search;
|
||||
input
|
||||
}
|
||||
|
||||
pub fn email() -> Self {
|
||||
let mut input = Input::new();
|
||||
let mut input = Input::new()
|
||||
.with_classes("form-type-email", ClassesOp::Replace("form-type-textfield"));
|
||||
input.input_type = InputType::Email;
|
||||
input
|
||||
}
|
||||
|
||||
pub fn telephone() -> Self {
|
||||
let mut input = Input::new();
|
||||
let mut input = Input::new()
|
||||
.with_classes("form-type-telephone", ClassesOp::Replace("form-type-textfield"));
|
||||
input.input_type = InputType::Telephone;
|
||||
input
|
||||
}
|
||||
|
||||
pub fn url() -> Self {
|
||||
let mut input = Input::new();
|
||||
let mut input = Input::new()
|
||||
.with_classes("form-type-url", ClassesOp::Replace("form-type-textfield"));
|
||||
input.input_type = InputType::Url;
|
||||
input
|
||||
}
|
||||
|
|
@ -150,51 +157,138 @@ impl Input {
|
|||
// Input BUILDER.
|
||||
|
||||
pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self {
|
||||
self.renderable = renderable;
|
||||
self.alter_renderable(renderable);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_weight(mut self, weight: i8) -> Self {
|
||||
self.weight = weight;
|
||||
self.alter_weight(weight);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_name(mut self, name: &str) -> Self {
|
||||
self.name.with_value(name);
|
||||
self.alter_name(name);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_value(mut self, value: &str) -> Self {
|
||||
self.value.with_value(value);
|
||||
self.alter_value(value);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_label(mut self, label: &str) -> Self {
|
||||
self.label.with_value(label);
|
||||
self.alter_label(label);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_size(mut self, size: Option<u16>) -> Self {
|
||||
self.size = size;
|
||||
self.alter_size(size);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_minlength(mut self, minlength: Option<u16>) -> Self {
|
||||
self.minlength = minlength;
|
||||
self.alter_minlength(minlength);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_maxlength(mut self, maxlength: Option<u16>) -> Self {
|
||||
self.maxlength = maxlength;
|
||||
self.alter_maxlength(maxlength);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_placeholder(mut self, placeholder: &str) -> Self {
|
||||
self.placeholder.with_value(placeholder);
|
||||
self.alter_placeholder(placeholder);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_autofocus(mut self, toggle: bool) -> Self {
|
||||
self.alter_autofocus(toggle);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_autocomplete(mut self, toggle: bool) -> Self {
|
||||
self.alter_autocomplete(toggle);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_disabled(mut self, toggle: bool) -> Self {
|
||||
self.alter_disabled(toggle);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_readonly(mut self, toggle: bool) -> Self {
|
||||
self.alter_readonly(toggle);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_required(mut self, toggle: bool) -> Self {
|
||||
self.alter_required(toggle);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_help_text(mut self, help_text: &str) -> Self {
|
||||
self.alter_help_text(help_text);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_classes(mut self, classes: &str, op: ClassesOp) -> Self {
|
||||
self.alter_classes(classes, op);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn using_template(mut self, template: &str) -> Self {
|
||||
self.alter_template(template);
|
||||
self
|
||||
}
|
||||
|
||||
// Input ALTER.
|
||||
|
||||
pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self {
|
||||
self.renderable = renderable;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn alter_weight(&mut self, weight: i8) -> &mut Self {
|
||||
self.weight = weight;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn alter_name(&mut self, name: &str) -> &mut Self {
|
||||
self.name.with_value(name);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn alter_value(&mut self, value: &str) -> &mut Self {
|
||||
self.value.with_value(value);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn alter_label(&mut self, label: &str) -> &mut Self {
|
||||
self.label.with_value(label);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn alter_size(&mut self, size: Option<u16>) -> &mut Self {
|
||||
self.size = size;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn alter_minlength(&mut self, minlength: Option<u16>) -> &mut Self {
|
||||
self.minlength = minlength;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn alter_maxlength(&mut self, maxlength: Option<u16>) -> &mut Self {
|
||||
self.maxlength = maxlength;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn alter_placeholder(&mut self, placeholder: &str) -> &mut Self {
|
||||
self.placeholder.with_value(placeholder);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn alter_autofocus(&mut self, toggle: bool) -> &mut Self {
|
||||
self.autofocus.with_value(match toggle {
|
||||
true => "autofocus",
|
||||
false => "",
|
||||
|
|
@ -202,7 +296,7 @@ impl Input {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn with_autocomplete(mut self, toggle: bool) -> Self {
|
||||
pub fn alter_autocomplete(&mut self, toggle: bool) -> &mut Self {
|
||||
self.autocomplete.with_value(match toggle {
|
||||
true => "",
|
||||
false => "off",
|
||||
|
|
@ -210,7 +304,7 @@ impl Input {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn with_disabled(mut self, toggle: bool) -> Self {
|
||||
pub fn alter_disabled(&mut self, toggle: bool) -> &mut Self {
|
||||
self.disabled.with_value(match toggle {
|
||||
true => "disabled",
|
||||
false => "",
|
||||
|
|
@ -218,7 +312,7 @@ impl Input {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn with_readonly(mut self, toggle: bool) -> Self {
|
||||
pub fn alter_readonly(&mut self, toggle: bool) -> &mut Self {
|
||||
self.readonly.with_value(match toggle {
|
||||
true => "readonly",
|
||||
false => "",
|
||||
|
|
@ -226,7 +320,7 @@ impl Input {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn with_required(mut self, toggle: bool) -> Self {
|
||||
pub fn alter_required(&mut self, toggle: bool) -> &mut Self {
|
||||
self.required.with_value(match toggle {
|
||||
true => "required",
|
||||
false => "",
|
||||
|
|
@ -234,22 +328,17 @@ impl Input {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn with_help_text(mut self, help_text: &str) -> Self {
|
||||
pub fn alter_help_text(&mut self, help_text: &str) -> &mut Self {
|
||||
self.help_text.with_value(help_text);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn set_classes(mut self, classes: &str) -> Self {
|
||||
self.classes.set_classes(classes);
|
||||
pub fn alter_classes(&mut self, classes: &str, op: ClassesOp) -> &mut Self {
|
||||
self.classes.alter(classes, op);
|
||||
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 alter_template(&mut self, template: &str) -> &mut Self {
|
||||
self.template = template.to_owned();
|
||||
self
|
||||
}
|
||||
|
|
@ -312,15 +401,11 @@ impl Input {
|
|||
self.help_text.option()
|
||||
}
|
||||
|
||||
pub fn classes(&self, default: &str) -> Option<String> {
|
||||
self.classes.option(default)
|
||||
pub fn classes(&self) -> &Option<String> {
|
||||
self.classes.option()
|
||||
}
|
||||
|
||||
pub fn template(&self) -> &str {
|
||||
self.template.as_str()
|
||||
}
|
||||
}
|
||||
|
||||
fn always() -> bool {
|
||||
true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,11 +12,11 @@ pub struct Column {
|
|||
impl PageComponent for Column {
|
||||
fn new() -> Self {
|
||||
Column {
|
||||
renderable: always,
|
||||
renderable: render_always,
|
||||
weight : 0,
|
||||
components: PageContainer::new(),
|
||||
id : OptIden::none(),
|
||||
classes : Classes::none(),
|
||||
id : OptIden::new(),
|
||||
classes : Classes::new_with_default("col"),
|
||||
template : "default".to_owned(),
|
||||
}
|
||||
}
|
||||
|
|
@ -35,7 +35,7 @@ impl PageComponent for Column {
|
|||
|
||||
fn default_render(&self, assets: &mut PageAssets) -> Markup {
|
||||
html! {
|
||||
div id=[self.id()] class=[self.classes("col")] {
|
||||
div id=[self.id()] class=[self.classes()] {
|
||||
(self.components().render(assets))
|
||||
}
|
||||
}
|
||||
|
|
@ -58,31 +58,53 @@ impl Column {
|
|||
// Column BUILDER.
|
||||
|
||||
pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self {
|
||||
self.renderable = renderable;
|
||||
self.alter_renderable(renderable);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_weight(mut self, weight: i8) -> Self {
|
||||
self.weight = weight;
|
||||
self.alter_weight(weight);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_id(mut self, id: &str) -> Self {
|
||||
self.id.with_value(id);
|
||||
self.alter_id(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);
|
||||
pub fn with_classes(mut self, classes: &str, op: ClassesOp) -> Self {
|
||||
self.alter_classes(classes, op);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn using_template(mut self, template: &str) -> Self {
|
||||
self.alter_template(template);
|
||||
self
|
||||
}
|
||||
|
||||
// Column ALTER.
|
||||
|
||||
pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self {
|
||||
self.renderable = renderable;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn alter_weight(&mut self, weight: i8) -> &mut Self {
|
||||
self.weight = weight;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn alter_id(&mut self, id: &str) -> &mut Self {
|
||||
self.id.with_value(id);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn alter_classes(&mut self, classes: &str, op: ClassesOp) -> &mut Self {
|
||||
self.classes.alter(classes, op);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn alter_template(&mut self, template: &str) -> &mut Self {
|
||||
self.template = template.to_owned();
|
||||
self
|
||||
}
|
||||
|
|
@ -93,15 +115,11 @@ impl Column {
|
|||
self.id.option()
|
||||
}
|
||||
|
||||
pub fn classes(&self, default: &str) -> Option<String> {
|
||||
self.classes.option(default)
|
||||
pub fn classes(&self) -> &Option<String> {
|
||||
self.classes.option()
|
||||
}
|
||||
|
||||
pub fn template(&self) -> &str {
|
||||
self.template.as_str()
|
||||
}
|
||||
}
|
||||
|
||||
fn always() -> bool {
|
||||
true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,11 +12,11 @@ pub struct Row {
|
|||
impl PageComponent for Row {
|
||||
fn new() -> Self {
|
||||
Row {
|
||||
renderable: always,
|
||||
renderable: render_always,
|
||||
weight : 0,
|
||||
columns : PageContainer::new(),
|
||||
id : OptIden::none(),
|
||||
classes : Classes::none(),
|
||||
id : OptIden::new(),
|
||||
classes : Classes::new_with_default("row"),
|
||||
template : "default".to_owned(),
|
||||
}
|
||||
}
|
||||
|
|
@ -35,7 +35,7 @@ impl PageComponent for Row {
|
|||
|
||||
fn default_render(&self, assets: &mut PageAssets) -> Markup {
|
||||
html! {
|
||||
div id=[self.id()] class=[self.classes("row")] {
|
||||
div id=[self.id()] class=[self.classes()] {
|
||||
(self.columns().render(assets))
|
||||
}
|
||||
}
|
||||
|
|
@ -58,36 +58,53 @@ impl Row {
|
|||
// Row BUILDER.
|
||||
|
||||
pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self {
|
||||
self.renderable = renderable;
|
||||
self.alter_renderable(renderable);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_weight(mut self, weight: i8) -> Self {
|
||||
self.weight = weight;
|
||||
self.alter_weight(weight);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_id(mut self, id: &str) -> Self {
|
||||
self.id.with_value(id);
|
||||
self.alter_id(id);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn set_classes(mut self, classes: &str) -> Self {
|
||||
self.classes.set_classes(classes);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn set_classes_ref(&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);
|
||||
pub fn with_classes(mut self, classes: &str, op: ClassesOp) -> Self {
|
||||
self.alter_classes(classes, op);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn using_template(mut self, template: &str) -> Self {
|
||||
self.alter_template(template);
|
||||
self
|
||||
}
|
||||
|
||||
// Row ALTER.
|
||||
|
||||
pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self {
|
||||
self.renderable = renderable;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn alter_weight(&mut self, weight: i8) -> &mut Self {
|
||||
self.weight = weight;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn alter_id(&mut self, id: &str) -> &mut Self {
|
||||
self.id.with_value(id);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn alter_classes(&mut self, classes: &str, op: ClassesOp) -> &mut Self {
|
||||
self.classes.alter(classes, op);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn alter_template(&mut self, template: &str) -> &mut Self {
|
||||
self.template = template.to_owned();
|
||||
self
|
||||
}
|
||||
|
|
@ -98,15 +115,11 @@ impl Row {
|
|||
self.id.option()
|
||||
}
|
||||
|
||||
pub fn classes(&self, default: &str) -> Option<String> {
|
||||
self.classes.option(default)
|
||||
pub fn classes(&self) -> &Option<String> {
|
||||
self.classes.option()
|
||||
}
|
||||
|
||||
pub fn template(&self) -> &str {
|
||||
self.template.as_str()
|
||||
}
|
||||
}
|
||||
|
||||
fn always() -> bool {
|
||||
true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,11 +12,11 @@ pub struct Image {
|
|||
impl PageComponent for Image {
|
||||
fn new() -> Self {
|
||||
Image {
|
||||
renderable: always,
|
||||
renderable: render_always,
|
||||
weight : 0,
|
||||
source : OptAttr::none(),
|
||||
id : OptIden::none(),
|
||||
classes : Classes::none(),
|
||||
source : OptAttr::new(),
|
||||
id : OptIden::new(),
|
||||
classes : Classes::new_with_default("img-fluid"),
|
||||
template : "default".to_owned(),
|
||||
}
|
||||
}
|
||||
|
|
@ -34,7 +34,7 @@ impl PageComponent for Image {
|
|||
img
|
||||
src=[self.source()]
|
||||
id=[self.id()]
|
||||
class=[self.classes("img-fluid")];
|
||||
class=[self.classes()];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -47,36 +47,63 @@ impl Image {
|
|||
// Image BUILDER.
|
||||
|
||||
pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self {
|
||||
self.renderable = renderable;
|
||||
self.alter_renderable(renderable);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_weight(mut self, weight: i8) -> Self {
|
||||
self.weight = weight;
|
||||
self.alter_weight(weight);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_source(mut self, source: &str) -> Self {
|
||||
self.source.with_value(source);
|
||||
self.alter_source(source);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_id(mut self, id: &str) -> Self {
|
||||
self.id.with_value(id);
|
||||
self.alter_id(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);
|
||||
pub fn with_classes(mut self, classes: &str, op: ClassesOp) -> Self {
|
||||
self.alter_classes(classes, op);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn using_template(mut self, template: &str) -> Self {
|
||||
self.alter_template(template);
|
||||
self
|
||||
}
|
||||
|
||||
// Image ALTER.
|
||||
|
||||
pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self {
|
||||
self.renderable = renderable;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn alter_weight(&mut self, weight: i8) -> &mut Self {
|
||||
self.weight = weight;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn alter_source(&mut self, source: &str) -> &mut Self {
|
||||
self.source.with_value(source);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn alter_id(&mut self, id: &str) -> &mut Self {
|
||||
self.id.with_value(id);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn alter_classes(&mut self, classes: &str, op: ClassesOp) -> &mut Self {
|
||||
self.classes.alter(classes, op);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn alter_template(&mut self, template: &str) -> &mut Self {
|
||||
self.template = template.to_owned();
|
||||
self
|
||||
}
|
||||
|
|
@ -91,15 +118,11 @@ impl Image {
|
|||
self.id.option()
|
||||
}
|
||||
|
||||
pub fn classes(&self, default: &str) -> Option<String> {
|
||||
self.classes.option(default)
|
||||
pub fn classes(&self) -> &Option<String> {
|
||||
self.classes.option()
|
||||
}
|
||||
|
||||
pub fn template(&self) -> &str {
|
||||
self.template.as_str()
|
||||
}
|
||||
}
|
||||
|
||||
fn always() -> bool {
|
||||
true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ pub struct MenuItem {
|
|||
impl PageComponent for MenuItem {
|
||||
fn new() -> Self {
|
||||
MenuItem {
|
||||
renderable: always,
|
||||
renderable: render_always,
|
||||
weight : 0,
|
||||
item_type : MenuItemType::Void,
|
||||
}
|
||||
|
|
@ -72,7 +72,7 @@ impl PageComponent for MenuItem {
|
|||
impl MenuItem {
|
||||
pub fn label(label: &str) -> Self {
|
||||
MenuItem {
|
||||
renderable: always,
|
||||
renderable: render_always,
|
||||
weight : 0,
|
||||
item_type : MenuItemType::Label(label.to_owned()),
|
||||
}
|
||||
|
|
@ -80,7 +80,7 @@ impl MenuItem {
|
|||
|
||||
pub fn link(label: &str, path: &str) -> Self {
|
||||
MenuItem {
|
||||
renderable: always,
|
||||
renderable: render_always,
|
||||
weight : 0,
|
||||
item_type : MenuItemType::Link(
|
||||
label.to_owned(),
|
||||
|
|
@ -91,7 +91,7 @@ impl MenuItem {
|
|||
|
||||
pub fn link_blank(label: &str, path: &str) -> Self {
|
||||
MenuItem {
|
||||
renderable: always,
|
||||
renderable: render_always,
|
||||
weight : 0,
|
||||
item_type : MenuItemType::LinkBlank(
|
||||
label.to_owned(),
|
||||
|
|
@ -102,7 +102,7 @@ impl MenuItem {
|
|||
|
||||
pub fn html(html: Markup) -> Self {
|
||||
MenuItem {
|
||||
renderable: always,
|
||||
renderable: render_always,
|
||||
weight : 0,
|
||||
item_type : MenuItemType::Html(html),
|
||||
}
|
||||
|
|
@ -110,7 +110,7 @@ impl MenuItem {
|
|||
|
||||
pub fn separator() -> Self {
|
||||
MenuItem {
|
||||
renderable: always,
|
||||
renderable: render_always,
|
||||
weight : 0,
|
||||
item_type : MenuItemType::Separator,
|
||||
}
|
||||
|
|
@ -118,7 +118,7 @@ impl MenuItem {
|
|||
|
||||
pub fn submenu(label: &str, menu: Menu) -> Self {
|
||||
MenuItem {
|
||||
renderable: always,
|
||||
renderable: render_always,
|
||||
weight : 0,
|
||||
item_type : MenuItemType::Submenu(
|
||||
label.to_owned(),
|
||||
|
|
@ -130,11 +130,23 @@ impl MenuItem {
|
|||
// MenuItem BUILDER.
|
||||
|
||||
pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self {
|
||||
self.renderable = renderable;
|
||||
self.alter_renderable(renderable);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_weight(mut self, weight: i8) -> Self {
|
||||
self.alter_weight(weight);
|
||||
self
|
||||
}
|
||||
|
||||
// MenuItem ALTER.
|
||||
|
||||
pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self {
|
||||
self.renderable = renderable;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn alter_weight(&mut self, weight: i8) -> &mut Self {
|
||||
self.weight = weight;
|
||||
self
|
||||
}
|
||||
|
|
@ -162,11 +174,11 @@ pub struct Menu {
|
|||
impl PageComponent for Menu {
|
||||
fn new() -> Self {
|
||||
Menu {
|
||||
renderable: always,
|
||||
renderable: render_always,
|
||||
weight : 0,
|
||||
items : PageContainer::new(),
|
||||
id : OptIden::none(),
|
||||
classes : Classes::none(),
|
||||
id : OptIden::new(),
|
||||
classes : Classes::new_with_default("sm sm-clean"),
|
||||
template : "default".to_owned(),
|
||||
}
|
||||
}
|
||||
|
|
@ -194,7 +206,7 @@ impl PageComponent for Menu {
|
|||
|
||||
let id = assets.serial_id(self.name(), self.id());
|
||||
html! {
|
||||
ul id=(id) class=[self.classes("sm sm-clean")] {
|
||||
ul id=(id) class=[self.classes()] {
|
||||
(self.items().render(assets))
|
||||
}
|
||||
script type="text/javascript" defer {
|
||||
|
|
@ -223,31 +235,53 @@ impl Menu {
|
|||
// Menu BUILDER.
|
||||
|
||||
pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self {
|
||||
self.renderable = renderable;
|
||||
self.alter_renderable(renderable);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_weight(mut self, weight: i8) -> Self {
|
||||
self.weight = weight;
|
||||
self.alter_weight(weight);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_id(mut self, id: &str) -> Self {
|
||||
self.id.with_value(id);
|
||||
self.alter_id(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);
|
||||
pub fn with_classes(mut self, classes: &str, op: ClassesOp) -> Self {
|
||||
self.alter_classes(classes, op);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn using_template(mut self, template: &str) -> Self {
|
||||
self.alter_template(template);
|
||||
self
|
||||
}
|
||||
|
||||
// Menu ALTER.
|
||||
|
||||
pub fn alter_renderable(&mut self, renderable: fn() -> bool) -> &mut Self {
|
||||
self.renderable = renderable;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn alter_weight(&mut self, weight: i8) -> &mut Self {
|
||||
self.weight = weight;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn alter_id(&mut self, id: &str) -> &mut Self {
|
||||
self.id.with_value(id);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn alter_classes(&mut self, classes: &str, op: ClassesOp) -> &mut Self {
|
||||
self.classes.alter(classes, op);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn alter_template(&mut self, template: &str) -> &mut Self {
|
||||
self.template = template.to_owned();
|
||||
self
|
||||
}
|
||||
|
|
@ -258,15 +292,11 @@ impl Menu {
|
|||
self.id.option()
|
||||
}
|
||||
|
||||
pub fn classes(&self, default: &str) -> Option<String> {
|
||||
self.classes.option(default)
|
||||
pub fn classes(&self) -> &Option<String> {
|
||||
self.classes.option()
|
||||
}
|
||||
|
||||
pub fn template(&self) -> &str {
|
||||
self.template.as_str()
|
||||
}
|
||||
}
|
||||
|
||||
fn always() -> bool {
|
||||
true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,33 +32,21 @@ impl ThemeTrait for BulmixTheme {
|
|||
.add_jquery();
|
||||
}
|
||||
|
||||
fn render_component(
|
||||
fn before_render_component(
|
||||
&self,
|
||||
component: &mut dyn PageComponent,
|
||||
assets: &mut PageAssets
|
||||
) -> Option<Markup> {
|
||||
_assets: &mut PageAssets
|
||||
) {
|
||||
match component.name() {
|
||||
"GridRow" => {
|
||||
let row = component.downcast_mut::<grid::Row>().unwrap();
|
||||
row.set_classes_ref("Prueba");
|
||||
None
|
||||
/*
|
||||
Some(html! {
|
||||
div id=[row.id()] class=[row.classes("columns")] {
|
||||
(row.columns().render(assets))
|
||||
}
|
||||
})
|
||||
*/
|
||||
row.alter_classes("columns", ClassesOp::SetDefault);
|
||||
},
|
||||
"GridColumn" => {
|
||||
let col = component.downcast_ref::<grid::Column>().unwrap();
|
||||
Some(html! {
|
||||
div id=[col.id()] class=[col.classes("column")] {
|
||||
(col.components().render(assets))
|
||||
}
|
||||
})
|
||||
let col = component.downcast_mut::<grid::Column>().unwrap();
|
||||
col.alter_classes("column", ClassesOp::SetDefault);
|
||||
},
|
||||
_ => None
|
||||
_ => {},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,23 +1,82 @@
|
|||
use crate::concat_string;
|
||||
|
||||
pub struct Classes(String);
|
||||
pub enum ClassesOp {
|
||||
Add,
|
||||
AddAfter(&'static str),
|
||||
AddBefore(&'static str),
|
||||
AddFirst,
|
||||
Replace(&'static str),
|
||||
Reset,
|
||||
SetDefault,
|
||||
}
|
||||
|
||||
pub struct Classes {
|
||||
default: String,
|
||||
added : String,
|
||||
option : Option<String>,
|
||||
}
|
||||
|
||||
impl Classes {
|
||||
pub fn none() -> Self {
|
||||
Classes("".to_owned())
|
||||
pub fn new() -> Self {
|
||||
Classes {
|
||||
default: "".to_owned(),
|
||||
added : "".to_owned(),
|
||||
option : None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_classes(&mut self, classes: &str) -> &mut Self {
|
||||
self.0 = classes.to_owned();
|
||||
pub fn new_with_default(default: &str) -> Self {
|
||||
let mut classes = Self::new();
|
||||
classes.alter(default, ClassesOp::SetDefault);
|
||||
classes
|
||||
}
|
||||
|
||||
pub fn alter(&mut self, classes: &str, op: ClassesOp) -> &Self {
|
||||
let classes = classes.trim();
|
||||
match op {
|
||||
ClassesOp::Add => self.added.push_str(concat_string!(" ", classes).as_str()),
|
||||
|
||||
ClassesOp::AddAfter(class) => {
|
||||
let mut v_added: Vec<&str> = self.added.split_ascii_whitespace().collect();
|
||||
match v_added.iter().position(|c| c.eq(&class)) {
|
||||
Some(pos) => v_added.insert(pos + 1, classes),
|
||||
_ => v_added.push(classes),
|
||||
}
|
||||
self.added = v_added.join(" ");
|
||||
},
|
||||
|
||||
ClassesOp::AddBefore(class) => {
|
||||
let mut v_added: Vec<&str> = self.added.split_ascii_whitespace().collect();
|
||||
match v_added.iter().position(|c| c.eq(&class)) {
|
||||
Some(pos) => v_added.insert(pos, classes),
|
||||
_ => v_added.insert(0, classes),
|
||||
}
|
||||
self.added = v_added.join(" ");
|
||||
},
|
||||
|
||||
ClassesOp::AddFirst => self.added = concat_string!(classes, " ", self.added),
|
||||
|
||||
ClassesOp::Replace(class) => {
|
||||
let mut v_added: Vec<&str> = self.added.split_ascii_whitespace().collect();
|
||||
match v_added.iter().position(|c| c.eq(&class)) {
|
||||
Some(pos) => {
|
||||
v_added.remove(pos);
|
||||
v_added.insert(pos, classes);
|
||||
},
|
||||
_ => v_added.push(classes),
|
||||
}
|
||||
self.added = v_added.join(" ");
|
||||
},
|
||||
|
||||
ClassesOp::Reset => self.added = classes.to_owned(),
|
||||
|
||||
ClassesOp::SetDefault => self.default = classes.to_owned(),
|
||||
}
|
||||
self.option = Some(concat_string!(self.default, " ", self.added).trim().to_owned());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn add_classes(&mut self, classes: &str) -> &mut Self {
|
||||
self.0 = concat_string!(self.0, " ", classes).trim().to_owned();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn option(&self, default: &str) -> Option<String> {
|
||||
Some(concat_string!(default.to_owned(), " ", self.0).trim().to_owned())
|
||||
pub fn option(&self) -> &Option<String> {
|
||||
&self.option
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,4 +5,4 @@ pub use optiden::OptIden;
|
|||
mod optattr;
|
||||
pub use optattr::OptAttr;
|
||||
mod classes;
|
||||
pub use classes::Classes;
|
||||
pub use classes::{Classes, ClassesOp};
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
pub struct OptAttr(Option<String>);
|
||||
|
||||
impl OptAttr {
|
||||
pub fn none() -> Self {
|
||||
pub fn new() -> Self {
|
||||
OptAttr(None)
|
||||
}
|
||||
|
||||
pub fn some(value: &str) -> Self {
|
||||
let mut o = OptAttr(None);
|
||||
o.with_value(value);
|
||||
o
|
||||
pub fn new_with_value(value: &str) -> Self {
|
||||
let mut option = Self::new();
|
||||
option.with_value(value);
|
||||
option
|
||||
}
|
||||
|
||||
pub fn with_value(&mut self, value: &str) -> &mut Self {
|
||||
|
|
|
|||
|
|
@ -1,17 +1,17 @@
|
|||
pub struct OptIden(Option<String>);
|
||||
|
||||
impl OptIden {
|
||||
pub fn none() -> Self {
|
||||
pub fn new() -> Self {
|
||||
OptIden(None)
|
||||
}
|
||||
|
||||
pub fn some(id: &str) -> Self {
|
||||
let mut o = OptIden(None);
|
||||
o.with_value(id);
|
||||
o
|
||||
pub fn new_with_value(id: &str) -> Self {
|
||||
let mut option = Self::new();
|
||||
option.with_value(id);
|
||||
option
|
||||
}
|
||||
|
||||
pub fn with_value(&mut self, id: &str) -> &mut Self {
|
||||
pub fn with_value(&mut self, id: &str) -> &Self {
|
||||
let id = id.trim();
|
||||
self.0 = match id.is_empty() {
|
||||
true => None,
|
||||
|
|
|
|||
|
|
@ -257,7 +257,7 @@ impl PageAssets {
|
|||
|
||||
/// Assets GETTERS.
|
||||
|
||||
pub fn theme(&mut self) -> &'static dyn ThemeTrait {
|
||||
pub(crate) fn theme(&mut self) -> &'static dyn ThemeTrait {
|
||||
self.theme
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,6 +33,10 @@ pub trait PageComponent: Downcast + Send + Sync {
|
|||
0
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn before_render(&mut self, assets: &mut PageAssets) {
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn default_render(&self, assets: &mut PageAssets) -> Markup {
|
||||
html! {}
|
||||
|
|
|
|||
|
|
@ -17,3 +17,6 @@ pub use page::Page;
|
|||
pub use page::render_component;
|
||||
pub use page::add_component_to;
|
||||
|
||||
pub fn render_always() -> bool { true }
|
||||
|
||||
pub fn render_never() -> bool { false }
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
use crate::{Lazy, app, trace};
|
||||
use crate::config::SETTINGS;
|
||||
use crate::html::{Classes, DOCTYPE, Markup, OptAttr, html};
|
||||
use crate::html::*;
|
||||
use crate::response::page::*;
|
||||
|
||||
use std::sync::RwLock;
|
||||
|
|
@ -55,18 +55,18 @@ impl<'a> Page<'a> {
|
|||
pub fn new() -> Self {
|
||||
Page {
|
||||
language : match &*DEFAULT_LANGUAGE {
|
||||
Some(language) => OptAttr::some(language),
|
||||
_ => OptAttr::none(),
|
||||
Some(language) => OptAttr::new_with_value(language),
|
||||
_ => OptAttr::new(),
|
||||
},
|
||||
direction : match &*DEFAULT_DIRECTION {
|
||||
Some(direction) => OptAttr::some(direction),
|
||||
_ => OptAttr::none(),
|
||||
Some(direction) => OptAttr::new_with_value(direction),
|
||||
_ => OptAttr::new(),
|
||||
},
|
||||
title : OptAttr::none(),
|
||||
description : OptAttr::none(),
|
||||
title : OptAttr::new(),
|
||||
description : OptAttr::new(),
|
||||
assets : PageAssets::new(),
|
||||
regions : COMPONENTS.read().unwrap().clone(),
|
||||
body_classes: Classes::none(),
|
||||
body_classes: Classes::new_with_default("body"),
|
||||
template : "default".to_owned(),
|
||||
}
|
||||
}
|
||||
|
|
@ -110,13 +110,8 @@ impl<'a> Page<'a> {
|
|||
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);
|
||||
pub fn alter_body_classes(&mut self, classes: &str, op: ClassesOp) -> &mut Self {
|
||||
self.body_classes.alter(classes, op);
|
||||
self
|
||||
}
|
||||
|
||||
|
|
@ -147,8 +142,8 @@ impl<'a> Page<'a> {
|
|||
&mut self.assets
|
||||
}
|
||||
|
||||
pub fn body_classes(&self, default: &str) -> Option<String> {
|
||||
self.body_classes.option(default)
|
||||
pub fn body_classes(&self) -> &Option<String> {
|
||||
self.body_classes.option()
|
||||
}
|
||||
|
||||
pub fn template(&self) -> &str {
|
||||
|
|
@ -192,14 +187,15 @@ impl<'a> Page<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn render_component(
|
||||
component: &mut dyn PageComponent,
|
||||
assets: &mut PageAssets
|
||||
) -> Markup {
|
||||
pub fn render_component(component: &mut dyn PageComponent, assets: &mut PageAssets) -> Markup {
|
||||
component.before_render(assets);
|
||||
assets.theme().before_render_component(component, assets);
|
||||
match component.is_renderable() {
|
||||
true => match assets.theme().render_component(component, assets) {
|
||||
true => {
|
||||
match assets.theme().render_component(component, assets) {
|
||||
Some(html) => html,
|
||||
None => component.default_render(assets)
|
||||
}
|
||||
},
|
||||
false => html! {}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ pub trait ThemeTrait: Send + Sync {
|
|||
|
||||
fn render_page_body(&self, page: &mut Page) -> Markup {
|
||||
html! {
|
||||
body class=[page.body_classes("body")] {
|
||||
body class=[page.body_classes()] {
|
||||
@match page.template() {
|
||||
"admin" => {
|
||||
@for region in &["top-menu", "side-menu", "content"] {
|
||||
|
|
@ -75,10 +75,29 @@ pub trait ThemeTrait: Send + Sync {
|
|||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn render_component(
|
||||
fn before_render_component(
|
||||
&self,
|
||||
component: &mut dyn PageComponent,
|
||||
assets: &mut PageAssets
|
||||
) {
|
||||
/*
|
||||
Cómo usarlo:
|
||||
|
||||
match component.name() {
|
||||
"Block" => {
|
||||
let block = component.downcast_mut::<Block>().unwrap();
|
||||
block.alter_title("New title");
|
||||
},
|
||||
_ => {},
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn render_component(
|
||||
&self,
|
||||
component: &dyn PageComponent,
|
||||
assets: &mut PageAssets
|
||||
) -> Option<Markup> {
|
||||
None
|
||||
/*
|
||||
|
|
@ -89,10 +108,10 @@ pub trait ThemeTrait: Send + Sync {
|
|||
let block = component.downcast_ref::<Block>().unwrap();
|
||||
match block.template() {
|
||||
"default" => Some(block_default(block)),
|
||||
_ => None
|
||||
_ => None,
|
||||
}
|
||||
},
|
||||
_ => None
|
||||
_ => None,
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue