Actualiza y simplifica la estructura del código

Revisión general del código fuente para asegurar los elementos que deben
ser públicos y estandarizar el uso de funciones globales.
This commit is contained in:
Manuel Cillero 2022-03-02 23:19:16 +01:00
parent 67952f6840
commit b6dd473578
34 changed files with 250 additions and 237 deletions

View file

@ -4,7 +4,7 @@ pub struct Block {
renderable: fn() -> bool,
weight : i8,
id : Option<String>,
title : String,
title : Option<String>,
markup : Vec<Markup>,
template : String,
}
@ -16,9 +16,9 @@ impl PageComponent for Block {
renderable: always,
weight : 0,
id : None,
title : "".to_string(),
title : None,
markup : Vec::new(),
template : "default".to_string(),
template : "default".to_owned(),
}
}
@ -34,8 +34,8 @@ impl PageComponent for Block {
let id = assets.serial_id(self.name(), self.id());
html! {
div id=(id) class="block" {
@if !self.title.is_empty() {
h2 class="block-title" { (self.title) }
@if self.title != None {
h2 class="block-title" { (self.title()) }
}
div class="block-body" {
@for markup in self.markup.iter() {
@ -71,7 +71,7 @@ impl Block {
}
pub fn with_title(mut self, title: &str) -> Self {
self.title = title.to_string();
self.title = util::optional_str(title);
self
}
@ -81,18 +81,18 @@ impl Block {
}
pub fn using_template(mut self, template: &str) -> Self {
self.template = template.to_string();
self.template = template.to_owned();
self
}
// Block GETTERS.
pub fn id(&self) -> &str {
util::assigned_value(&self.id)
util::assigned_str(&self.id)
}
pub fn title(&self) -> &str {
self.title.as_str()
util::assigned_str(&self.title)
}
pub fn template(&self) -> &str {

View file

@ -14,7 +14,7 @@ impl PageComponent for Chunck {
renderable: always,
weight : 0,
markup : Vec::new(),
template : "default".to_string(),
template : "default".to_owned(),
}
}
@ -59,7 +59,7 @@ impl Chunck {
}
pub fn using_template(mut self, template: &str) -> Self {
self.template = template.to_string();
self.template = template.to_owned();
self
}

View file

@ -20,7 +20,7 @@ impl PageComponent for Container {
id : None,
container : ContainerType::Wrapper,
components: PageContainer::new(),
template : "default".to_string(),
template : "default".to_owned(),
}
}
@ -83,14 +83,14 @@ impl Container {
}
pub fn using_template(mut self, template: &str) -> Self {
self.template = template.to_string();
self.template = template.to_owned();
self
}
// Container GETTERS.
pub fn id(&self) -> &str {
util::assigned_value(&self.id)
util::assigned_str(&self.id)
}
pub fn template(&self) -> &str {

View file

@ -24,7 +24,7 @@ impl PageComponent for Button {
value : None,
autofocus : None,
disabled : None,
template : "default".to_string(),
template : "default".to_owned(),
}
}
@ -101,13 +101,13 @@ impl Button {
}
pub fn with_value(mut self, value: &str) -> Self {
self.value = util::optional_value(value);
self.value = util::optional_str(value);
self
}
pub fn autofocus(mut self, toggle: bool) -> Self {
self.autofocus = match toggle {
true => Some("autofocus".to_string()),
true => Some("autofocus".to_owned()),
false => None
};
self
@ -115,25 +115,25 @@ impl Button {
pub fn disabled(mut self, toggle: bool) -> Self {
self.disabled = match toggle {
true => Some("disabled".to_string()),
true => Some("disabled".to_owned()),
false => None
};
self
}
pub fn using_template(mut self, template: &str) -> Self {
self.template = template.to_string();
self.template = template.to_owned();
self
}
// Button GETTERS.
pub fn name(&self) -> &str {
util::assigned_value(&self.name)
util::assigned_str(&self.name)
}
pub fn value(&self) -> &str {
util::assigned_value(&self.value)
util::assigned_str(&self.value)
}
pub fn has_autofocus(&self) -> bool {

View file

@ -5,14 +5,14 @@ pub struct Date {
weight : i8,
name : Option<String>,
value : Option<String>,
label : String,
label : Option<String>,
placeholder : Option<String>,
autofocus : Option<String>,
autocomplete: Option<String>,
disabled : Option<String>,
readonly : Option<String>,
required : Option<String>,
help_text : String,
help_text : Option<String>,
template : String,
}
@ -24,15 +24,15 @@ impl PageComponent for Date {
weight : 0,
name : None,
value : None,
label : "".to_string(),
label : None,
placeholder : None,
autofocus : None,
autocomplete: None,
disabled : None,
readonly : None,
required : None,
help_text : "".to_string(),
template : "default".to_string(),
help_text : None,
template : "default".to_owned(),
}
}
@ -51,15 +51,15 @@ impl PageComponent for Date {
Some(format!("edit-{}", name))
),
None => (
"form-item form-type-date".to_string(),
"form-item form-type-date".to_owned(),
None
)
};
html! {
div class=(class_item) {
@if !self.label.is_empty() {
@if self.label != None {
label class="form-label" for=[&id_item] {
(self.label) " "
(self.label()) " "
@if self.required != None {
span
class="form-required"
@ -82,9 +82,9 @@ impl PageComponent for Date {
readonly=[&self.readonly]
required=[&self.required]
disabled=[&self.disabled];
@if !self.help_text.is_empty() {
@if self.help_text != None {
div class="form-text" {
(self.help_text)
(self.help_text())
}
}
}
@ -112,23 +112,23 @@ impl Date {
}
pub fn with_value(mut self, value: &str) -> Self {
self.value = util::optional_value(value);
self.value = util::optional_str(value);
self
}
pub fn with_label(mut self, label: &str) -> Self {
self.label = label.to_string();
self.label = util::optional_str(label);
self
}
pub fn with_placeholder(mut self, placeholder: &str) -> Self {
self.placeholder = util::optional_value(placeholder);
self.placeholder = util::optional_str(placeholder);
self
}
pub fn autofocus(mut self, toggle: bool) -> Self {
self.autofocus = match toggle {
true => Some("autofocus".to_string()),
true => Some("autofocus".to_owned()),
false => None
};
self
@ -137,14 +137,14 @@ impl Date {
pub fn autocomplete(mut self, toggle: bool) -> Self {
self.autocomplete = match toggle {
true => None,
false => Some("off".to_string())
false => Some("off".to_owned())
};
self
}
pub fn disabled(mut self, toggle: bool) -> Self {
self.disabled = match toggle {
true => Some("disabled".to_string()),
true => Some("disabled".to_owned()),
false => None
};
self
@ -152,7 +152,7 @@ impl Date {
pub fn readonly(mut self, toggle: bool) -> Self {
self.readonly = match toggle {
true => Some("readonly".to_string()),
true => Some("readonly".to_owned()),
false => None
};
self
@ -160,38 +160,38 @@ impl Date {
pub fn required(mut self, toggle: bool) -> Self {
self.required = match toggle {
true => Some("required".to_string()),
true => Some("required".to_owned()),
false => None
};
self
}
pub fn with_help_text(mut self, help_text: &str) -> Self {
self.help_text = help_text.to_string();
self.help_text = util::optional_str(help_text);
self
}
pub fn using_template(mut self, template: &str) -> Self {
self.template = template.to_string();
self.template = template.to_owned();
self
}
// Date GETTERS.
pub fn name(&self) -> &str {
util::assigned_value(&self.name)
util::assigned_str(&self.name)
}
pub fn value(&self) -> &str {
util::assigned_value(&self.value)
util::assigned_str(&self.value)
}
pub fn label(&self) -> &str {
self.label.as_str()
util::assigned_str(&self.label)
}
pub fn placeholder(&self) -> &str {
util::assigned_value(&self.placeholder)
util::assigned_str(&self.placeholder)
}
pub fn has_autofocus(&self) -> bool {
@ -230,7 +230,7 @@ impl Date {
}
pub fn help_text(&self) -> &str {
self.help_text.as_str()
util::assigned_str(&self.help_text)
}
pub fn template(&self) -> &str {

View file

@ -22,9 +22,9 @@ impl PageComponent for Form {
id : None,
action : None,
method : FormMethod::Post,
charset : Some("UTF-8".to_string()),
charset : Some("UTF-8".to_owned()),
elements : PageContainer::new(),
template : "default".to_string(),
template : "default".to_owned(),
}
}
@ -39,7 +39,7 @@ impl PageComponent for Form {
fn default_render(&self, assets: &mut PageAssets) -> Markup {
let method = match self.method {
FormMethod::Get => None,
FormMethod::Post => Some("post".to_string())
FormMethod::Post => Some("post".to_owned())
};
html! {
form
@ -76,7 +76,7 @@ impl Form {
}
pub fn with_action(mut self, action: &str) -> Self {
self.action = util::optional_value(action);
self.action = util::optional_str(action);
self
}
@ -86,7 +86,7 @@ impl Form {
}
pub fn with_charset(mut self, charset: &str) -> Self {
self.charset = util::optional_value(charset);
self.charset = util::optional_str(charset);
self
}
@ -96,18 +96,18 @@ impl Form {
}
pub fn using_template(mut self, template: &str) -> Self {
self.template = template.to_string();
self.template = template.to_owned();
self
}
// Form GETTERS.
pub fn id(&self) -> &str {
util::assigned_value(&self.id)
util::assigned_str(&self.id)
}
pub fn action(&self) -> &str {
util::assigned_value(&self.action)
util::assigned_str(&self.action)
}
pub fn method(&self) -> &str {
@ -118,7 +118,7 @@ impl Form {
}
pub fn charset(&self) -> &str {
util::assigned_value(&self.charset)
util::assigned_str(&self.charset)
}
pub fn template(&self) -> &str {

View file

@ -54,17 +54,17 @@ impl Hidden {
}
pub fn with_value(mut self, value: &str) -> Self {
self.value = util::optional_value(value);
self.value = util::optional_str(value);
self
}
// Hidden GETTERS.
pub fn name(&self) -> &str {
util::assigned_value(&self.name)
util::assigned_str(&self.name)
}
pub fn value(&self) -> &str {
util::assigned_value(&self.value)
util::assigned_str(&self.value)
}
}

View file

@ -8,7 +8,7 @@ pub struct Input {
input_type : InputType,
name : Option<String>,
value : Option<String>,
label : String,
label : Option<String>,
size : Option<u16>,
minlength : Option<u16>,
maxlength : Option<u16>,
@ -18,7 +18,7 @@ pub struct Input {
disabled : Option<String>,
readonly : Option<String>,
required : Option<String>,
help_text : String,
help_text : Option<String>,
template : String,
}
@ -31,7 +31,7 @@ impl PageComponent for Input {
input_type : InputType::Textfield,
name : None,
value : None,
label : "".to_string(),
label : None,
size : Some(60),
minlength : None,
maxlength : Some(128),
@ -41,8 +41,8 @@ impl PageComponent for Input {
disabled : None,
readonly : None,
required : None,
help_text : "".to_string(),
template : "default".to_string(),
help_text : None,
template : "default".to_owned(),
}
}
@ -75,9 +75,9 @@ impl PageComponent for Input {
};
html! {
div class=(class_item) {
@if !self.label.is_empty() {
@if self.label != None {
label class="form-label" for=[&id_item] {
(self.label) " "
(self.label()) " "
@if self.required != None {
span
class="form-required"
@ -103,9 +103,9 @@ impl PageComponent for Input {
readonly=[&self.readonly]
required=[&self.required]
disabled=[&self.disabled];
@if !self.help_text.is_empty() {
@if self.help_text != None {
div class="form-text" {
(self.help_text)
(self.help_text())
}
}
}
@ -167,12 +167,12 @@ impl Input {
}
pub fn with_value(mut self, value: &str) -> Self {
self.value = util::optional_value(value);
self.value = util::optional_str(value);
self
}
pub fn with_label(mut self, label: &str) -> Self {
self.label = label.to_string();
self.label = util::optional_str(label);
self
}
@ -192,13 +192,13 @@ impl Input {
}
pub fn with_placeholder(mut self, placeholder: &str) -> Self {
self.placeholder = util::optional_value(placeholder);
self.placeholder = util::optional_str(placeholder);
self
}
pub fn autofocus(mut self, toggle: bool) -> Self {
self.autofocus = match toggle {
true => Some("autofocus".to_string()),
true => Some("autofocus".to_owned()),
false => None
};
self
@ -207,14 +207,14 @@ impl Input {
pub fn autocomplete(mut self, toggle: bool) -> Self {
self.autocomplete = match toggle {
true => None,
false => Some("off".to_string())
false => Some("off".to_owned())
};
self
}
pub fn disabled(mut self, toggle: bool) -> Self {
self.disabled = match toggle {
true => Some("disabled".to_string()),
true => Some("disabled".to_owned()),
false => None
};
self
@ -222,7 +222,7 @@ impl Input {
pub fn readonly(mut self, toggle: bool) -> Self {
self.readonly = match toggle {
true => Some("readonly".to_string()),
true => Some("readonly".to_owned()),
false => None
};
self
@ -230,34 +230,34 @@ impl Input {
pub fn required(mut self, toggle: bool) -> Self {
self.required = match toggle {
true => Some("required".to_string()),
true => Some("required".to_owned()),
false => None
};
self
}
pub fn with_help_text(mut self, help_text: &str) -> Self {
self.help_text = help_text.to_string();
self.help_text = util::optional_str(help_text);
self
}
pub fn using_template(mut self, template: &str) -> Self {
self.template = template.to_string();
self.template = template.to_owned();
self
}
// Input GETTERS.
pub fn name(&self) -> &str {
util::assigned_value(&self.name)
util::assigned_str(&self.name)
}
pub fn value(&self) -> &str {
util::assigned_value(&self.value)
util::assigned_str(&self.value)
}
pub fn label(&self) -> &str {
self.label.as_str()
util::assigned_str(&self.label)
}
pub fn size(&self) -> Option<u16> {
@ -273,7 +273,7 @@ impl Input {
}
pub fn placeholder(&self) -> &str {
util::assigned_value(&self.placeholder)
util::assigned_str(&self.placeholder)
}
pub fn has_autofocus(&self) -> bool {
@ -312,7 +312,7 @@ impl Input {
}
pub fn help_text(&self) -> &str {
self.help_text.as_str()
util::assigned_str(&self.help_text)
}
pub fn template(&self) -> &str {

View file

@ -75,7 +75,7 @@ impl MenuItem {
MenuItem {
renderable: always,
weight : 0,
item_type : Some(MenuItemType::Label(label.to_string())),
item_type : Some(MenuItemType::Label(label.to_owned())),
}
}
@ -84,8 +84,8 @@ impl MenuItem {
renderable: always,
weight : 0,
item_type : Some(MenuItemType::Link(
label.to_string(),
path.to_string(),
label.to_owned(),
path.to_owned(),
)),
}
}
@ -95,8 +95,8 @@ impl MenuItem {
renderable: always,
weight : 0,
item_type : Some(MenuItemType::LinkBlank(
label.to_string(),
path.to_string(),
label.to_owned(),
path.to_owned(),
)),
}
}
@ -122,7 +122,7 @@ impl MenuItem {
renderable: always,
weight : 0,
item_type : Some(MenuItemType::Submenu(
label.to_string(),
label.to_owned(),
menu
)),
}
@ -161,7 +161,7 @@ impl PageComponent for Menu {
weight : 0,
id : None,
items : PageContainer::new(),
template : "default".to_string(),
template : "default".to_owned(),
}
}
@ -226,14 +226,14 @@ impl Menu {
}
pub fn using_template(mut self, template: &str) -> Self {
self.template = template.to_string();
self.template = template.to_owned();
self
}
// Menu GETTERS.
pub fn id(&self) -> &str {
util::assigned_value(&self.id)
util::assigned_str(&self.id)
}
pub fn template(&self) -> &str {

View file

@ -15,8 +15,8 @@ impl Module for AdminModule {
l("module_fullname")
}
fn description(&self) -> String {
l("module_description")
fn description(&self) -> Option<String> {
Some(l("module_description"))
}
fn configure_module(&self, cfg: &mut server::web::ServiceConfig) {

View file

@ -13,8 +13,8 @@ impl Module for HomepageModule {
l("module_fullname")
}
fn description(&self) -> String {
l("module_description")
fn description(&self) -> Option<String> {
Some(l("module_description"))
}
fn configure_module(&self, cfg: &mut server::web::ServiceConfig) {

View file

@ -13,8 +13,8 @@ impl Module for UserModule {
l("module_fullname")
}
fn description(&self) -> String {
l("module_description")
fn description(&self) -> Option<String> {
Some(l("module_description"))
}
fn configure_module(&self, cfg: &mut server::web::ServiceConfig) {
@ -29,7 +29,7 @@ fn form_login() -> impl PageComponent {
.with_name("name")
.with_label(l("username").as_str())
.with_help_text(t("username_help", &args![
"app" => SETTINGS.app.name.to_string()
"app" => SETTINGS.app.name.to_owned()
]).as_str())
.autofocus(true)
)

View file

@ -10,7 +10,7 @@ impl Theme for AlinerTheme {
}
fn fullname(&self) -> String {
"Aliner".to_string()
"Aliner".to_owned()
}
fn configure_theme(&self, cfg: &mut server::web::ServiceConfig) {

View file

@ -12,7 +12,7 @@ impl Theme for BootsierTheme {
}
fn fullname(&self) -> String {
"Bootsier".to_string()
"Bootsier".to_owned()
}
fn configure_theme(&self, cfg: &mut server::web::ServiceConfig) {

View file

@ -8,6 +8,6 @@ impl Theme for MinimalTheme {
}
fn fullname(&self) -> String {
"Minimal".to_string()
"Minimal".to_owned()
}
}