♻️ Use new() with arguments, default() without
This commit is contained in:
parent
258d42049f
commit
f208da1b7b
13 changed files with 35 additions and 66 deletions
|
|
@ -26,7 +26,7 @@ impl<C: ComponentTrait> ActionTrait for AfterPrepareComponent<C> {
|
|||
}
|
||||
|
||||
impl<C: ComponentTrait> AfterPrepareComponent<C> {
|
||||
pub fn with(f: FnAction<C>) -> Self {
|
||||
pub fn new(f: FnAction<C>) -> Self {
|
||||
AfterPrepareComponent {
|
||||
f,
|
||||
referer_handle: Some(C::static_handle()),
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ impl<C: ComponentTrait> ActionTrait for BeforePrepareComponent<C> {
|
|||
}
|
||||
|
||||
impl<C: ComponentTrait> BeforePrepareComponent<C> {
|
||||
pub fn with(f: FnAction<C>) -> Self {
|
||||
pub fn new(f: FnAction<C>) -> Self {
|
||||
BeforePrepareComponent {
|
||||
f,
|
||||
referer_handle: Some(C::static_handle()),
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ impl ActionTrait for AfterPrepareBody {
|
|||
}
|
||||
|
||||
impl AfterPrepareBody {
|
||||
pub fn with(f: FnActionPage) -> Self {
|
||||
pub fn new(f: FnActionPage) -> Self {
|
||||
AfterPrepareBody { f, weight: 0 }
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ impl ActionTrait for BeforePrepareBody {
|
|||
}
|
||||
|
||||
impl BeforePrepareBody {
|
||||
pub fn with(f: FnActionPage) -> Self {
|
||||
pub fn new(f: FnActionPage) -> Self {
|
||||
BeforePrepareBody { f, weight: 0 }
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ pub fn add_action(action: Action) {
|
|||
if let Some(list) = actions.get_mut(&key_action) {
|
||||
list.add(action);
|
||||
} else {
|
||||
actions.insert(key_action, ActionsList::with(action));
|
||||
actions.insert(key_action, ActionsList::new(action));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,15 +4,12 @@ use std::sync::{Arc, RwLock};
|
|||
|
||||
pub type Action = Box<dyn ActionTrait>;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct ActionsList(Arc<RwLock<Vec<Action>>>);
|
||||
|
||||
impl ActionsList {
|
||||
pub fn new() -> Self {
|
||||
ActionsList(Arc::new(RwLock::new(Vec::new())))
|
||||
}
|
||||
|
||||
pub fn with(action: Action) -> Self {
|
||||
let mut list = ActionsList::new();
|
||||
pub fn new(action: Action) -> Self {
|
||||
let mut list = ActionsList::default();
|
||||
list.add(action);
|
||||
list
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ pub trait ThemeTrait: ModuleTrait + Send + Sync {
|
|||
if render_region.is_empty() {
|
||||
html! {}
|
||||
} else {
|
||||
let id = OptionId::with(region).get().unwrap();
|
||||
let id = OptionId::new(region).get().unwrap();
|
||||
let id_inner = concat_string!(id, "__inner");
|
||||
html! {
|
||||
div id=(id) class="pt-region" {
|
||||
|
|
|
|||
|
|
@ -24,14 +24,8 @@ pub enum ClassesOp {
|
|||
pub struct OptionClasses(Vec<String>);
|
||||
|
||||
impl OptionClasses {
|
||||
pub fn new() -> Self {
|
||||
OptionClasses::default()
|
||||
}
|
||||
|
||||
pub fn with(op: ClassesOp, classes: impl Into<String>) -> Self {
|
||||
let mut opt = OptionClasses::default();
|
||||
opt.alter_value(op, classes);
|
||||
opt
|
||||
pub fn new(classes: impl Into<String>) -> Self {
|
||||
OptionClasses::default().with_value(ClassesOp::AddFirst, classes)
|
||||
}
|
||||
|
||||
// OptionClasses BUILDER.
|
||||
|
|
@ -96,11 +90,6 @@ impl OptionClasses {
|
|||
|
||||
// OptionClasses GETTERS.
|
||||
|
||||
pub fn exists(&self, class: impl Into<String>) -> bool {
|
||||
let class: String = class.into();
|
||||
self.0.iter().any(|c| c.eq(&class))
|
||||
}
|
||||
|
||||
pub fn get(&self) -> Option<String> {
|
||||
if self.0.is_empty() {
|
||||
None
|
||||
|
|
@ -108,4 +97,9 @@ impl OptionClasses {
|
|||
Some(self.0.join(" "))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn contains(&self, class: impl Into<String>) -> bool {
|
||||
let class: String = class.into();
|
||||
self.0.iter().any(|c| c.eq(&class))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,14 +4,8 @@ use crate::fn_builder;
|
|||
pub struct OptionId(Option<String>);
|
||||
|
||||
impl OptionId {
|
||||
pub fn new() -> Self {
|
||||
OptionId::default()
|
||||
}
|
||||
|
||||
pub fn with(value: impl Into<String>) -> Self {
|
||||
let mut opt = OptionId::default();
|
||||
opt.alter_value(value);
|
||||
opt
|
||||
pub fn new(value: impl Into<String>) -> Self {
|
||||
OptionId::default().with_value(value)
|
||||
}
|
||||
|
||||
// OptionId BUILDER.
|
||||
|
|
|
|||
|
|
@ -4,14 +4,8 @@ use crate::fn_builder;
|
|||
pub struct OptionName(Option<String>);
|
||||
|
||||
impl OptionName {
|
||||
pub fn new() -> Self {
|
||||
OptionName::default()
|
||||
}
|
||||
|
||||
pub fn with(value: impl Into<String>) -> Self {
|
||||
let mut opt = OptionName::default();
|
||||
opt.alter_value(value);
|
||||
opt
|
||||
pub fn new(value: impl Into<String>) -> Self {
|
||||
OptionName::default().with_value(value)
|
||||
}
|
||||
|
||||
// OptionName BUILDER.
|
||||
|
|
|
|||
|
|
@ -4,14 +4,8 @@ use crate::fn_builder;
|
|||
pub struct OptionString(Option<String>);
|
||||
|
||||
impl OptionString {
|
||||
pub fn new() -> Self {
|
||||
OptionString::default()
|
||||
}
|
||||
|
||||
pub fn with(value: impl Into<String>) -> Self {
|
||||
let mut opt = OptionString::default();
|
||||
opt.alter_value(value);
|
||||
opt
|
||||
pub fn new(value: impl Into<String>) -> Self {
|
||||
OptionString::default().with_value(value)
|
||||
}
|
||||
|
||||
// OptionString BUILDER.
|
||||
|
|
|
|||
|
|
@ -1,17 +1,13 @@
|
|||
use crate::fn_builder;
|
||||
use crate::html::{html, Markup};
|
||||
use crate::html::Markup;
|
||||
use crate::locale::{L10n, LanguageIdentifier};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct OptionTranslated(Option<L10n>);
|
||||
|
||||
impl OptionTranslated {
|
||||
pub fn new() -> Self {
|
||||
OptionTranslated::default()
|
||||
}
|
||||
|
||||
pub fn with(value: L10n) -> Self {
|
||||
OptionTranslated(Some(value))
|
||||
pub fn new(value: L10n) -> Self {
|
||||
OptionTranslated::default().with_value(value)
|
||||
}
|
||||
|
||||
// OptionTranslated BUILDER.
|
||||
|
|
@ -31,10 +27,10 @@ impl OptionTranslated {
|
|||
None
|
||||
}
|
||||
|
||||
pub fn escaped(&self, langid: &LanguageIdentifier) -> Markup {
|
||||
pub fn escaped(&self, langid: &LanguageIdentifier) -> Option<Markup> {
|
||||
if let Some(value) = &self.0 {
|
||||
return value.escaped(langid);
|
||||
return Some(value.escaped(langid));
|
||||
}
|
||||
html! {}
|
||||
None
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,15 +30,15 @@ impl Page {
|
|||
#[rustfmt::skip]
|
||||
pub fn new(request: service::HttpRequest) -> Self {
|
||||
Page {
|
||||
title : OptionTranslated::new(),
|
||||
description : OptionTranslated::new(),
|
||||
metadata : Vec::new(),
|
||||
properties : Vec::new(),
|
||||
title : OptionTranslated::default(),
|
||||
description : OptionTranslated::default(),
|
||||
metadata : Vec::default(),
|
||||
properties : Vec::default(),
|
||||
favicon : None,
|
||||
context : Context::new(request),
|
||||
body_classes: OptionClasses::new(),
|
||||
skip_to : OptionId::new(),
|
||||
regions : ComponentsRegions::new(),
|
||||
body_classes: OptionClasses::default(),
|
||||
skip_to : OptionId::default(),
|
||||
regions : ComponentsRegions::default(),
|
||||
template : "default".to_owned(),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue