diff --git a/Cargo.toml b/Cargo.toml index 3e647964..57bc0683 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,6 +2,7 @@ members = [ "pagetop", + "pagetop-macros", "pagetop-build", # Modules. "pagetop-admin", diff --git a/pagetop/Cargo.toml b/pagetop/Cargo.toml index ea87b851..b9d956c0 100644 --- a/pagetop/Cargo.toml +++ b/pagetop/Cargo.toml @@ -49,6 +49,8 @@ actix-web-files = { package = "actix-files", version = "0.6.2" } actix-web-static-files = "4.0.0" static-files = "0.2.3" +pagetop-macros = { path = "../pagetop-macros", version = "0.0" } + maud = { version = "0.24.0", features = ["actix-web"] } serde = { version = "1.0", features = ["derive"] } diff --git a/pagetop/src/base/component/anchor.rs b/pagetop/src/base/component/anchor.rs index 07c6c1af..b5e46117 100644 --- a/pagetop/src/base/component/anchor.rs +++ b/pagetop/src/base/component/anchor.rs @@ -105,83 +105,31 @@ impl Anchor { // Anchor BUILDER. - pub fn with_weight(mut self, weight: isize) -> Self { - self.alter_weight(weight); - self - } - - pub fn with_renderable(mut self, check: IsRenderable) -> Self { - self.alter_renderable(check); - self - } - - pub fn with_id(mut self, id: &str) -> Self { - self.alter_id(id); - self - } - - pub fn with_classes(mut self, op: ClassesOp, classes: &str) -> Self { - self.alter_classes(op, classes); - self - } - - pub fn with_type(mut self, anchor_type: AnchorType) -> Self { - self.alter_type(anchor_type); - self - } - - pub fn with_href(mut self, href: &str) -> Self { - self.alter_href(href); - self - } - - pub fn with_html(mut self, html: Markup) -> Self { - self.alter_html(html); - self - } - - pub fn with_left_icon(mut self, icon: Icon) -> Self { - self.alter_left_icon(icon); - self - } - - pub fn with_right_icon(mut self, icon: Icon) -> Self { - self.alter_right_icon(icon); - self - } - - pub fn with_target(mut self, target: AnchorTarget) -> Self { - self.alter_target(target); - self - } - - pub fn using_template(mut self, template: &str) -> Self { - self.alter_template(template); - self - } - - // Anchor ALTER. - + #[fn_with] pub fn alter_weight(&mut self, weight: isize) -> &mut Self { self.weight = weight; self } + #[fn_with] pub fn alter_renderable(&mut self, check: IsRenderable) -> &mut Self { self.renderable.check = check; self } + #[fn_with] pub fn alter_id(&mut self, id: &str) -> &mut Self { self.id.alter_value(id); self } + #[fn_with] pub fn alter_classes(&mut self, op: ClassesOp, classes: &str) -> &mut Self { self.classes.alter_value(op, classes); self } + #[fn_with] pub fn alter_type(&mut self, anchor_type: AnchorType) -> &mut Self { self.anchor_type = anchor_type; self.classes.alter_value( @@ -194,33 +142,39 @@ impl Anchor { self } + #[fn_with] pub fn alter_href(&mut self, href: &str) -> &mut Self { self.href.alter_value(href); self } + #[fn_with] pub fn alter_html(&mut self, html: Markup) -> &mut Self { self.html.markup = html; self } + #[fn_with] pub fn alter_left_icon(&mut self, icon: Icon) -> &mut Self { self.left_icon.clear(); self.left_icon.add(icon); self } + #[fn_with] pub fn alter_right_icon(&mut self, icon: Icon) -> &mut Self { self.right_icon.clear(); self.right_icon.add(icon); self } + #[fn_with] pub fn alter_target(&mut self, target: AnchorTarget) -> &mut Self { self.target = target; self } + #[fn_with] pub fn alter_template(&mut self, template: &str) -> &mut Self { self.template = template.to_owned(); self diff --git a/pagetop/src/base/component/block.rs b/pagetop/src/base/component/block.rs index f6094fc5..412a147c 100644 --- a/pagetop/src/base/component/block.rs +++ b/pagetop/src/base/component/block.rs @@ -63,73 +63,43 @@ impl ComponentTrait for Block { impl Block { // Block BUILDER. - pub fn with_weight(mut self, weight: isize) -> Self { - self.alter_weight(weight); - self - } - - pub fn with_renderable(mut self, check: IsRenderable) -> Self { - self.alter_renderable(check); - self - } - - pub fn with_id(mut self, id: &str) -> Self { - self.alter_id(id); - self - } - - pub fn with_classes(mut self, op: ClassesOp, classes: &str) -> Self { - self.alter_classes(op, classes); - self - } - - pub fn with_title(mut self, title: &str) -> Self { - self.alter_title(title); - self - } - - pub fn with_component(mut self, component: impl ComponentTrait) -> Self { - self.alter_component(component); - self - } - - pub fn using_template(mut self, template: &str) -> Self { - self.alter_template(template); - self - } - - // Block ALTER. - + #[fn_with] pub fn alter_weight(&mut self, weight: isize) -> &mut Self { self.weight = weight; self } + #[fn_with] pub fn alter_renderable(&mut self, check: IsRenderable) -> &mut Self { self.renderable.check = check; self } + #[fn_with] pub fn alter_id(&mut self, id: &str) -> &mut Self { self.id.alter_value(id); self } + #[fn_with] pub fn alter_classes(&mut self, op: ClassesOp, classes: &str) -> &mut Self { self.classes.alter_value(op, classes); self } + #[fn_with] pub fn alter_title(&mut self, title: &str) -> &mut Self { self.title.alter_value(title); self } + #[fn_with] pub fn alter_component(&mut self, component: impl ComponentTrait) -> &mut Self { self.components.add(component); self } + #[fn_with] pub fn alter_template(&mut self, template: &str) -> &mut Self { self.template = template.to_owned(); self diff --git a/pagetop/src/base/component/container.rs b/pagetop/src/base/component/container.rs index a502eda8..53aff0a8 100644 --- a/pagetop/src/base/component/container.rs +++ b/pagetop/src/base/component/container.rs @@ -124,73 +124,43 @@ impl Container { // Container BUILDER. - pub fn with_weight(mut self, weight: isize) -> Self { - self.alter_weight(weight); - self - } - - pub fn with_renderable(mut self, check: IsRenderable) -> Self { - self.alter_renderable(check); - self - } - - pub fn with_id(mut self, id: &str) -> Self { - self.alter_id(id); - self - } - - pub fn with_classes(mut self, op: ClassesOp, classes: &str) -> Self { - self.alter_classes(op, classes); - self - } - - pub fn with_inner_classes(mut self, op: ClassesOp, classes: &str) -> Self { - self.alter_inner_classes(op, classes); - self - } - - pub fn with_component(mut self, component: impl ComponentTrait) -> Self { - self.alter_component(component); - self - } - - pub fn using_template(mut self, template: &str) -> Self { - self.alter_template(template); - self - } - - // Container ALTER. - + #[fn_with] pub fn alter_weight(&mut self, weight: isize) -> &mut Self { self.weight = weight; self } + #[fn_with] pub fn alter_renderable(&mut self, check: IsRenderable) -> &mut Self { self.renderable.check = check; self } + #[fn_with] pub fn alter_id(&mut self, id: &str) -> &mut Self { self.id.alter_value(id); self } + #[fn_with] pub fn alter_classes(&mut self, op: ClassesOp, classes: &str) -> &mut Self { self.classes.alter_value(op, classes); self } + #[fn_with] pub fn alter_inner_classes(&mut self, op: ClassesOp, classes: &str) -> &mut Self { self.inner_classes.alter_value(op, classes); self } + #[fn_with] pub fn alter_component(&mut self, component: impl ComponentTrait) -> &mut Self { self.components.add(component); self } + #[fn_with] pub fn alter_template(&mut self, template: &str) -> &mut Self { self.template = template.to_owned(); self diff --git a/pagetop/src/base/component/form_element/button.rs b/pagetop/src/base/component/form_element/button.rs index f32f5082..ba6d2a66 100644 --- a/pagetop/src/base/component/form_element/button.rs +++ b/pagetop/src/base/component/form_element/button.rs @@ -97,73 +97,37 @@ impl Button { // Button BUILDER. - pub fn with_weight(mut self, weight: isize) -> Self { - self.alter_weight(weight); - self - } - - pub fn with_renderable(mut self, check: IsRenderable) -> Self { - self.alter_renderable(check); - self - } - - pub fn with_classes(mut self, op: ClassesOp, classes: &str) -> Self { - self.alter_classes(op, classes); - self - } - - pub fn with_name(mut self, name: &str) -> Self { - self.alter_name(name); - self - } - - pub fn with_value(mut self, value: &str) -> Self { - 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 using_template(mut self, template: &str) -> Self { - self.alter_template(template); - self - } - - // Button ALTER. - + #[fn_with] pub fn alter_weight(&mut self, weight: isize) -> &mut Self { self.weight = weight; self } + #[fn_with] pub fn alter_renderable(&mut self, check: IsRenderable) -> &mut Self { self.renderable.check = check; self } + #[fn_with] pub fn alter_classes(&mut self, op: ClassesOp, classes: &str) -> &mut Self { self.classes.alter_value(op, classes); self } + #[fn_with] pub fn alter_name(&mut self, name: &str) -> &mut Self { self.name.alter_value(name); self } + #[fn_with] pub fn alter_value(&mut self, value: &str) -> &mut Self { self.value.alter_value(value); self } + #[fn_with] pub fn alter_autofocus(&mut self, toggle: bool) -> &mut Self { self.autofocus.alter_value(match toggle { true => "autofocus", @@ -172,6 +136,7 @@ impl Button { self } + #[fn_with] pub fn alter_disabled(&mut self, toggle: bool) -> &mut Self { self.disabled.alter_value(match toggle { true => "disabled", @@ -180,6 +145,7 @@ impl Button { self } + #[fn_with] pub fn alter_template(&mut self, template: &str) -> &mut Self { self.template = template.to_owned(); self diff --git a/pagetop/src/base/component/form_element/date.rs b/pagetop/src/base/component/form_element/date.rs index a6e5b598..d49762d6 100644 --- a/pagetop/src/base/component/form_element/date.rs +++ b/pagetop/src/base/component/form_element/date.rs @@ -85,113 +85,49 @@ impl ComponentTrait for Date { impl Date { // Date BUILDER. - pub fn with_weight(mut self, weight: isize) -> Self { - self.alter_weight(weight); - self - } - - pub fn with_renderable(mut self, check: IsRenderable) -> Self { - self.alter_renderable(check); - self - } - - pub fn with_classes(mut self, op: ClassesOp, classes: &str) -> Self { - self.alter_classes(op, classes); - self - } - - pub fn with_name(mut self, name: &str) -> Self { - self.alter_name(name); - self - } - - pub fn with_value(mut self, value: &str) -> Self { - self.alter_value(value); - self - } - - pub fn with_label(mut self, label: &str) -> Self { - self.alter_label(label); - self - } - - pub fn with_placeholder(mut self, placeholder: &str) -> Self { - 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 using_template(mut self, template: &str) -> Self { - self.alter_template(template); - self - } - - // Date ALTER. - + #[fn_with] pub fn alter_weight(&mut self, weight: isize) -> &mut Self { self.weight = weight; self } + #[fn_with] pub fn alter_renderable(&mut self, check: IsRenderable) -> &mut Self { self.renderable.check = check; self } + #[fn_with] pub fn alter_classes(&mut self, op: ClassesOp, classes: &str) -> &mut Self { self.classes.alter_value(op, classes); self } + #[fn_with] pub fn alter_name(&mut self, name: &str) -> &mut Self { self.name.alter_value(name); self } + #[fn_with] pub fn alter_value(&mut self, value: &str) -> &mut Self { self.value.alter_value(value); self } + #[fn_with] pub fn alter_label(&mut self, label: &str) -> &mut Self { self.label.alter_value(label); self } + #[fn_with] pub fn alter_placeholder(&mut self, placeholder: &str) -> &mut Self { self.placeholder.alter_value(placeholder); self } + #[fn_with] pub fn alter_autofocus(&mut self, toggle: bool) -> &mut Self { self.autofocus.alter_value(match toggle { true => "autofocus", @@ -200,6 +136,7 @@ impl Date { self } + #[fn_with] pub fn alter_autocomplete(&mut self, toggle: bool) -> &mut Self { self.autocomplete.alter_value(match toggle { true => "", @@ -208,6 +145,7 @@ impl Date { self } + #[fn_with] pub fn alter_disabled(&mut self, toggle: bool) -> &mut Self { self.disabled.alter_value(match toggle { true => "disabled", @@ -216,6 +154,7 @@ impl Date { self } + #[fn_with] pub fn alter_readonly(&mut self, toggle: bool) -> &mut Self { self.readonly.alter_value(match toggle { true => "readonly", @@ -224,6 +163,7 @@ impl Date { self } + #[fn_with] pub fn alter_required(&mut self, toggle: bool) -> &mut Self { self.required.alter_value(match toggle { true => "required", @@ -232,11 +172,13 @@ impl Date { self } + #[fn_with] pub fn alter_help_text(&mut self, help_text: &str) -> &mut Self { self.help_text.alter_value(help_text); self } + #[fn_with] pub fn alter_template(&mut self, template: &str) -> &mut Self { self.template = template.to_owned(); self diff --git a/pagetop/src/base/component/form_element/form.rs b/pagetop/src/base/component/form_element/form.rs index d658cc64..f1661455 100644 --- a/pagetop/src/base/component/form_element/form.rs +++ b/pagetop/src/base/component/form_element/form.rs @@ -78,93 +78,55 @@ impl ComponentTrait for Form { impl Form { // Form BUILDER. - pub fn with_weight(mut self, weight: isize) -> Self { - self.alter_weight(weight); - self - } - - pub fn with_renderable(mut self, check: IsRenderable) -> Self { - self.alter_renderable(check); - self - } - - pub fn with_id(mut self, id: &str) -> Self { - self.alter_id(id); - self - } - - pub fn with_classes(mut self, op: ClassesOp, classes: &str) -> Self { - self.alter_classes(op, classes); - self - } - - pub fn with_action(mut self, action: &str) -> Self { - self.alter_action(action); - self - } - - pub fn with_charset(mut self, charset: &str) -> Self { - self.alter_charset(charset); - self - } - - pub fn with_method(mut self, method: FormMethod) -> Self { - self.alter_method(method); - self - } - - pub fn with_element(mut self, element: impl ComponentTrait) -> Self { - self.alter_element(element); - self - } - - pub fn using_template(mut self, template: &str) -> Self { - self.alter_template(template); - self - } - - // Form ALTER. - + #[fn_with] pub fn alter_weight(&mut self, weight: isize) -> &mut Self { self.weight = weight; self } + #[fn_with] pub fn alter_renderable(&mut self, check: IsRenderable) -> &mut Self { self.renderable.check = check; self } + #[fn_with] pub fn alter_id(&mut self, id: &str) -> &mut Self { self.id.alter_value(id); self } + #[fn_with] pub fn alter_classes(&mut self, op: ClassesOp, classes: &str) -> &mut Self { self.classes.alter_value(op, classes); self } + #[fn_with] pub fn alter_action(&mut self, action: &str) -> &mut Self { self.action.alter_value(action); self } + #[fn_with] pub fn alter_charset(&mut self, charset: &str) -> &mut Self { self.charset.alter_value(charset); self } + #[fn_with] pub fn alter_method(&mut self, method: FormMethod) -> &mut Self { self.method = method; self } + #[fn_with] pub fn alter_element(&mut self, element: impl ComponentTrait) -> &mut Self { self.elements.add(element); self } + #[fn_with] pub fn alter_template(&mut self, template: &str) -> &mut Self { self.template = template.to_owned(); self diff --git a/pagetop/src/base/component/form_element/hidden.rs b/pagetop/src/base/component/form_element/hidden.rs index f7c554e6..6fb063c1 100644 --- a/pagetop/src/base/component/form_element/hidden.rs +++ b/pagetop/src/base/component/form_element/hidden.rs @@ -46,33 +46,19 @@ impl Hidden { // Hidden BUILDER. - pub fn with_weight(mut self, weight: isize) -> Self { - self.alter_weight(weight); - self - } - - pub fn with_name(mut self, name: &str) -> Self { - self.alter_name(name); - self - } - - pub fn with_value(mut self, value: &str) -> Self { - self.alter_value(value); - self - } - - // Hidden ALTER. - + #[fn_with] pub fn alter_weight(&mut self, weight: isize) -> &mut Self { self.weight = weight; self } + #[fn_with] pub fn alter_name(&mut self, name: &str) -> &mut Self { self.name.alter_value(name); self } + #[fn_with] pub fn alter_value(&mut self, value: &str) -> &mut Self { self.value.alter_value(value); self diff --git a/pagetop/src/base/component/form_element/input.rs b/pagetop/src/base/component/form_element/input.rs index ee79d1bf..1177df93 100644 --- a/pagetop/src/base/component/form_element/input.rs +++ b/pagetop/src/base/component/form_element/input.rs @@ -168,108 +168,25 @@ impl Input { // Input BUILDER. - pub fn with_weight(mut self, weight: isize) -> Self { - self.alter_weight(weight); - self - } - - pub fn with_renderable(mut self, check: IsRenderable) -> Self { - self.alter_renderable(check); - self - } - - pub fn with_classes(mut self, op: ClassesOp, classes: &str) -> Self { - self.alter_classes(op, classes); - self - } - - pub fn with_name(mut self, name: &str) -> Self { - self.alter_name(name); - self - } - - pub fn with_value(mut self, value: &str) -> Self { - self.alter_value(value); - self - } - - pub fn with_label(mut self, label: &str) -> Self { - self.alter_label(label); - self - } - - pub fn with_size(mut self, size: Option) -> Self { - self.alter_size(size); - self - } - - pub fn with_minlength(mut self, minlength: Option) -> Self { - self.alter_minlength(minlength); - self - } - - pub fn with_maxlength(mut self, maxlength: Option) -> Self { - self.alter_maxlength(maxlength); - self - } - - pub fn with_placeholder(mut self, placeholder: &str) -> Self { - 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 using_template(mut self, template: &str) -> Self { - self.alter_template(template); - self - } - - // Input ALTER. - + #[fn_with] pub fn alter_weight(&mut self, weight: isize) -> &mut Self { self.weight = weight; self } + #[fn_with] pub fn alter_renderable(&mut self, check: IsRenderable) -> &mut Self { self.renderable.check = check; self } + #[fn_with] pub fn alter_classes(&mut self, op: ClassesOp, classes: &str) -> &mut Self { self.classes.alter_value(op, classes); self } + #[fn_with] pub fn alter_name(&mut self, name: &str) -> &mut Self { self.name.alter_value(name); self.alter_classes( @@ -279,36 +196,43 @@ impl Input { self } + #[fn_with] pub fn alter_value(&mut self, value: &str) -> &mut Self { self.value.alter_value(value); self } + #[fn_with] pub fn alter_label(&mut self, label: &str) -> &mut Self { self.label.alter_value(label); self } + #[fn_with] pub fn alter_size(&mut self, size: Option) -> &mut Self { self.size = size; self } + #[fn_with] pub fn alter_minlength(&mut self, minlength: Option) -> &mut Self { self.minlength = minlength; self } + #[fn_with] pub fn alter_maxlength(&mut self, maxlength: Option) -> &mut Self { self.maxlength = maxlength; self } + #[fn_with] pub fn alter_placeholder(&mut self, placeholder: &str) -> &mut Self { self.placeholder.alter_value(placeholder); self } + #[fn_with] pub fn alter_autofocus(&mut self, toggle: bool) -> &mut Self { self.autofocus.alter_value(match toggle { true => "autofocus", @@ -317,6 +241,7 @@ impl Input { self } + #[fn_with] pub fn alter_autocomplete(&mut self, toggle: bool) -> &mut Self { self.autocomplete.alter_value(match toggle { true => "", @@ -325,6 +250,7 @@ impl Input { self } + #[fn_with] pub fn alter_disabled(&mut self, toggle: bool) -> &mut Self { self.disabled.alter_value(match toggle { true => "disabled", @@ -333,6 +259,7 @@ impl Input { self } + #[fn_with] pub fn alter_readonly(&mut self, toggle: bool) -> &mut Self { self.readonly.alter_value(match toggle { true => "readonly", @@ -341,6 +268,7 @@ impl Input { self } + #[fn_with] pub fn alter_required(&mut self, toggle: bool) -> &mut Self { self.required.alter_value(match toggle { true => "required", @@ -349,11 +277,13 @@ impl Input { self } + #[fn_with] pub fn alter_help_text(&mut self, help_text: &str) -> &mut Self { self.help_text.alter_value(help_text); self } + #[fn_with] pub fn alter_template(&mut self, template: &str) -> &mut Self { self.template = template.to_owned(); self diff --git a/pagetop/src/base/component/grid/column.rs b/pagetop/src/base/component/grid/column.rs index 95e92e57..738b9c7f 100644 --- a/pagetop/src/base/component/grid/column.rs +++ b/pagetop/src/base/component/grid/column.rs @@ -89,64 +89,32 @@ impl ComponentTrait for Column { impl Column { // Column BUILDER. - pub fn with_weight(mut self, weight: isize) -> Self { - self.alter_weight(weight); - self - } - - pub fn with_renderable(mut self, check: IsRenderable) -> Self { - self.alter_renderable(check); - self - } - - pub fn with_id(mut self, id: &str) -> Self { - self.alter_id(id); - self - } - - pub fn with_classes(mut self, op: ClassesOp, classes: &str) -> Self { - self.alter_classes(op, classes); - self - } - - pub fn with_size(mut self, size: ColumnSize) -> Self { - self.alter_size(size); - self - } - - pub fn with_component(mut self, component: impl ComponentTrait) -> Self { - self.alter_component(component); - self - } - - pub fn using_template(mut self, template: &str) -> Self { - self.alter_template(template); - self - } - - // Column ALTER. - + #[fn_with] pub fn alter_weight(&mut self, weight: isize) -> &mut Self { self.weight = weight; self } + #[fn_with] pub fn alter_renderable(&mut self, check: IsRenderable) -> &mut Self { self.renderable.check = check; self } + #[fn_with] pub fn alter_id(&mut self, id: &str) -> &mut Self { self.id.alter_value(id); self } + #[fn_with] pub fn alter_classes(&mut self, op: ClassesOp, classes: &str) -> &mut Self { self.classes.alter_value(op, classes); self } #[rustfmt::skip] + #[fn_with] pub fn alter_size(&mut self, size: ColumnSize) -> &mut Self { match size { ColumnSize::Default => self.alter_classes(ClassesOp::SetDefault, SIZE__DEFAULT), @@ -167,10 +135,13 @@ impl Column { self } + #[fn_with] pub fn alter_component(&mut self, component: impl ComponentTrait) -> &mut Self { self.components.add(component); self } + + #[fn_with] pub fn alter_template(&mut self, template: &str) -> &mut Self { self.template = template.to_owned(); self diff --git a/pagetop/src/base/component/grid/row.rs b/pagetop/src/base/component/grid/row.rs index ba9ccd93..dd50f08e 100644 --- a/pagetop/src/base/component/grid/row.rs +++ b/pagetop/src/base/component/grid/row.rs @@ -56,63 +56,37 @@ impl ComponentTrait for Row { impl Row { // Row BUILDER. - pub fn with_weight(mut self, weight: isize) -> Self { - self.alter_weight(weight); - self - } - - pub fn with_renderable(mut self, check: IsRenderable) -> Self { - self.alter_renderable(check); - self - } - - pub fn with_id(mut self, id: &str) -> Self { - self.alter_id(id); - self - } - - pub fn with_classes(mut self, op: ClassesOp, classes: &str) -> Self { - self.alter_classes(op, classes); - self - } - - pub fn with_column(mut self, column: grid::Column) -> Self { - self.alter_column(column); - self - } - - pub fn using_template(mut self, template: &str) -> Self { - self.alter_template(template); - self - } - - // Row ALTER. - + #[fn_with] pub fn alter_weight(&mut self, weight: isize) -> &mut Self { self.weight = weight; self } + #[fn_with] pub fn alter_renderable(&mut self, check: IsRenderable) -> &mut Self { self.renderable.check = check; self } + #[fn_with] pub fn alter_id(&mut self, id: &str) -> &mut Self { self.id.alter_value(id); self } + #[fn_with] pub fn alter_classes(&mut self, op: ClassesOp, classes: &str) -> &mut Self { self.classes.alter_value(op, classes); self } + #[fn_with] pub fn alter_column(&mut self, column: grid::Column) -> &mut Self { self.columns.add(column); self } + #[fn_with] pub fn alter_template(&mut self, template: &str) -> &mut Self { self.template = template.to_owned(); self diff --git a/pagetop/src/base/component/heading.rs b/pagetop/src/base/component/heading.rs index de396e46..b2de7ebe 100644 --- a/pagetop/src/base/component/heading.rs +++ b/pagetop/src/base/component/heading.rs @@ -116,79 +116,44 @@ impl Heading { // Heading BUILDER. - pub fn with_weight(mut self, weight: isize) -> Self { - self.alter_weight(weight); - self - } - - pub fn with_renderable(mut self, check: IsRenderable) -> Self { - self.alter_renderable(check); - self - } - - pub fn with_id(mut self, id: &str) -> Self { - self.alter_id(id); - self - } - - pub fn with_classes(mut self, op: ClassesOp, classes: &str) -> Self { - self.alter_classes(op, classes); - self - } - - pub fn with_heading_type(mut self, heading_type: HeadingType) -> Self { - self.alter_heading_type(heading_type); - self - } - - pub fn with_html(mut self, html: Markup) -> Self { - self.alter_html(html); - self - } - - pub fn with_display(mut self, display: HeadingDisplay) -> Self { - self.alter_display(display); - self - } - - pub fn using_template(mut self, template: &str) -> Self { - self.alter_template(template); - self - } - - // Heading ALTER. - + #[fn_with] pub fn alter_weight(&mut self, weight: isize) -> &mut Self { self.weight = weight; self } + #[fn_with] pub fn alter_renderable(&mut self, check: IsRenderable) -> &mut Self { self.renderable.check = check; self } + #[fn_with] pub fn alter_id(&mut self, id: &str) -> &mut Self { self.id.alter_value(id); self } + #[fn_with] pub fn alter_classes(&mut self, op: ClassesOp, classes: &str) -> &mut Self { self.classes.alter_value(op, classes); self } + #[fn_with] pub fn alter_heading_type(&mut self, heading_type: HeadingType) -> &mut Self { self.heading_type = heading_type; self } + #[fn_with] pub fn alter_html(&mut self, html: Markup) -> &mut Self { self.html.markup = html; self } #[rustfmt::skip] + #[fn_with] pub fn alter_display(&mut self, display: HeadingDisplay) -> &mut Self { self.display = display; self.classes.alter_value( @@ -206,6 +171,7 @@ impl Heading { self } + #[fn_with] pub fn alter_template(&mut self, template: &str) -> &mut Self { self.template = template.to_owned(); self diff --git a/pagetop/src/base/component/html.rs b/pagetop/src/base/component/html.rs index 6e7f8bdc..1f23b00e 100644 --- a/pagetop/src/base/component/html.rs +++ b/pagetop/src/base/component/html.rs @@ -48,43 +48,25 @@ impl Html { // Html BUILDER. - pub fn with_weight(mut self, weight: isize) -> Self { - self.alter_weight(weight); - self - } - - pub fn with_renderable(mut self, check: IsRenderable) -> Self { - self.alter_renderable(check); - 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 - } - - // Html ALTER. - + #[fn_with] pub fn alter_weight(&mut self, weight: isize) -> &mut Self { self.weight = weight; self } + #[fn_with] pub fn alter_renderable(&mut self, check: IsRenderable) -> &mut Self { self.renderable.check = check; self } + #[fn_with] pub fn alter_html(&mut self, html: Markup) -> &mut Self { self.html.markup = html; self } + #[fn_with] pub fn alter_template(&mut self, template: &str) -> &mut Self { self.template = template.to_owned(); self diff --git a/pagetop/src/base/component/icon.rs b/pagetop/src/base/component/icon.rs index db028475..e953549c 100644 --- a/pagetop/src/base/component/icon.rs +++ b/pagetop/src/base/component/icon.rs @@ -54,38 +54,19 @@ impl Icon { // Icon BUILDER. - pub fn with_weight(mut self, weight: isize) -> Self { - self.alter_weight(weight); - self - } - - pub fn with_renderable(mut self, check: IsRenderable) -> Self { - self.alter_renderable(check); - self - } - - pub fn with_icon_name(mut self, name: &str) -> Self { - self.alter_icon_name(name); - self - } - - pub fn with_classes(mut self, op: ClassesOp, classes: &str) -> Self { - self.alter_classes(op, classes); - self - } - - // Icon ALTER. - + #[fn_with] pub fn alter_weight(&mut self, weight: isize) -> &mut Self { self.weight = weight; self } + #[fn_with] pub fn alter_renderable(&mut self, check: IsRenderable) -> &mut Self { self.renderable.check = check; self } + #[fn_with] pub fn alter_icon_name(&mut self, name: &str) -> &mut Self { self.icon_name = name.to_owned(); self.alter_classes( @@ -95,6 +76,7 @@ impl Icon { self } + #[fn_with] pub fn alter_classes(&mut self, op: ClassesOp, classes: &str) -> &mut Self { self.classes.alter_value(op, classes); self diff --git a/pagetop/src/base/component/image.rs b/pagetop/src/base/component/image.rs index 0cd54804..6f1a2c0d 100644 --- a/pagetop/src/base/component/image.rs +++ b/pagetop/src/base/component/image.rs @@ -55,63 +55,37 @@ impl Image { // Image BUILDER. - pub fn with_weight(mut self, weight: isize) -> Self { - self.alter_weight(weight); - self - } - - pub fn with_renderable(mut self, check: IsRenderable) -> Self { - self.alter_renderable(check); - self - } - - pub fn with_id(mut self, id: &str) -> Self { - self.alter_id(id); - self - } - - pub fn with_classes(mut self, op: ClassesOp, classes: &str) -> Self { - self.alter_classes(op, classes); - self - } - - pub fn with_source(mut self, source: &str) -> Self { - self.alter_source(source); - self - } - - pub fn using_template(mut self, template: &str) -> Self { - self.alter_template(template); - self - } - - // Image ALTER. - + #[fn_with] pub fn alter_weight(&mut self, weight: isize) -> &mut Self { self.weight = weight; self } + #[fn_with] pub fn alter_renderable(&mut self, check: IsRenderable) -> &mut Self { self.renderable.check = check; self } + #[fn_with] pub fn alter_id(&mut self, id: &str) -> &mut Self { self.id.alter_value(id); self } + #[fn_with] pub fn alter_classes(&mut self, op: ClassesOp, classes: &str) -> &mut Self { self.classes.alter_value(op, classes); self } + #[fn_with] pub fn alter_source(&mut self, source: &str) -> &mut Self { self.source.alter_value(source); self } + #[fn_with] pub fn alter_template(&mut self, template: &str) -> &mut Self { self.template = template.to_owned(); self diff --git a/pagetop/src/base/component/menu.rs b/pagetop/src/base/component/menu.rs index d5df0272..34ab7efc 100644 --- a/pagetop/src/base/component/menu.rs +++ b/pagetop/src/base/component/menu.rs @@ -127,23 +127,13 @@ impl MenuItem { // MenuItem BUILDER. - pub fn with_weight(mut self, weight: isize) -> Self { - self.alter_weight(weight); - self - } - - pub fn with_renderable(mut self, check: IsRenderable) -> Self { - self.alter_renderable(check); - self - } - - // MenuItem ALTER. - + #[fn_with] pub fn alter_weight(&mut self, weight: isize) -> &mut Self { self.weight = weight; self } + #[fn_with] pub fn alter_renderable(&mut self, check: IsRenderable) -> &mut Self { self.renderable.check = check; self @@ -233,63 +223,37 @@ impl ComponentTrait for Menu { impl Menu { // Menu BUILDER. - pub fn with_weight(mut self, weight: isize) -> Self { - self.alter_weight(weight); - self - } - - pub fn with_renderable(mut self, check: IsRenderable) -> Self { - self.alter_renderable(check); - self - } - - pub fn with_id(mut self, id: &str) -> Self { - self.alter_id(id); - self - } - - pub fn with_classes(mut self, op: ClassesOp, classes: &str) -> Self { - self.alter_classes(op, classes); - self - } - - pub fn with_item(mut self, item: MenuItem) -> Self { - self.alter_item(item); - self - } - - pub fn using_template(mut self, template: &str) -> Self { - self.alter_template(template); - self - } - - // Menu ALTER. - + #[fn_with] pub fn alter_weight(&mut self, weight: isize) -> &mut Self { self.weight = weight; self } + #[fn_with] pub fn alter_renderable(&mut self, check: IsRenderable) -> &mut Self { self.renderable.check = check; self } + #[fn_with] pub fn alter_id(&mut self, id: &str) -> &mut Self { self.id.alter_value(id); self } + #[fn_with] pub fn alter_classes(&mut self, op: ClassesOp, classes: &str) -> &mut Self { self.classes.alter_value(op, classes); self } + #[fn_with] pub fn alter_item(&mut self, item: MenuItem) -> &mut Self { self.items.add(item); self } + #[fn_with] pub fn alter_template(&mut self, template: &str) -> &mut Self { self.template = template.to_owned(); self diff --git a/pagetop/src/base/component/paragraph.rs b/pagetop/src/base/component/paragraph.rs index 6ab208f0..5a4eef80 100644 --- a/pagetop/src/base/component/paragraph.rs +++ b/pagetop/src/base/component/paragraph.rs @@ -69,69 +69,38 @@ impl Paragraph { // Paragraph BUILDER. - pub fn with_weight(mut self, weight: isize) -> Self { - self.alter_weight(weight); - self - } - - pub fn with_renderable(mut self, check: IsRenderable) -> Self { - self.alter_renderable(check); - self - } - - pub fn with_id(mut self, id: &str) -> Self { - self.alter_id(id); - self - } - - pub fn with_classes(mut self, op: ClassesOp, classes: &str) -> Self { - self.alter_classes(op, classes); - self - } - - pub fn with_component(mut self, component: impl ComponentTrait) -> Self { - self.alter_component(component); - self - } - - pub fn with_display(mut self, display: ParagraphDisplay) -> Self { - self.alter_display(display); - self - } - - pub fn using_template(mut self, template: &str) -> Self { - self.alter_template(template); - self - } - - // Paragraph ALTER. - + #[fn_with] pub fn alter_weight(&mut self, weight: isize) -> &mut Self { self.weight = weight; self } + #[fn_with] pub fn alter_renderable(&mut self, check: IsRenderable) -> &mut Self { self.renderable.check = check; self } + #[fn_with] pub fn alter_id(&mut self, id: &str) -> &mut Self { self.id.alter_value(id); self } + #[fn_with] pub fn alter_classes(&mut self, op: ClassesOp, classes: &str) -> &mut Self { self.classes.alter_value(op, classes); self } + #[fn_with] pub fn alter_component(&mut self, component: impl ComponentTrait) -> &mut Self { self.components.add(component); self } #[rustfmt::skip] + #[fn_with] pub fn alter_display(&mut self, display: ParagraphDisplay) -> &mut Self { self.display = display; self.classes.alter_value( @@ -148,6 +117,7 @@ impl Paragraph { self } + #[fn_with] pub fn alter_template(&mut self, template: &str) -> &mut Self { self.template = template.to_owned(); self diff --git a/pagetop/src/lib.rs b/pagetop/src/lib.rs index fb92a186..2d74b95c 100644 --- a/pagetop/src/lib.rs +++ b/pagetop/src/lib.rs @@ -44,6 +44,8 @@ pub use doc_comment::doc_comment; pub use once_cell::sync::Lazy as LazyStatic; pub use tracing_unwrap::ResultExt; +pub use pagetop_macros::fn_with; + // LOCAL. #[allow(unused_imports)] diff --git a/pagetop/src/prelude.rs b/pagetop/src/prelude.rs index e2d66bc8..b44f7de6 100644 --- a/pagetop/src/prelude.rs +++ b/pagetop/src/prelude.rs @@ -1,5 +1,5 @@ // Re-exports. -pub use crate::{concat_string, LazyStatic, ResultExt}; +pub use crate::{concat_string, fn_with, LazyStatic, ResultExt}; // Macros. pub use crate::{args, pub_config, pub_handle, pub_locale, serve_static_files};