diff --git a/pagetop/src/html.rs b/pagetop/src/html.rs
index 8e8e43ef..ade65cf1 100644
--- a/pagetop/src/html.rs
+++ b/pagetop/src/html.rs
@@ -22,6 +22,9 @@ pub use opt_name::OptionName;
mod opt_string;
pub use opt_string::OptionString;
+mod opt_translate;
+pub use opt_translate::OptionTranslate;
+
mod opt_classes;
pub use opt_classes::{ClassesOp, OptionClasses};
diff --git a/pagetop/src/html/opt_id.rs b/pagetop/src/html/opt_id.rs
index ab16aa6b..f78ab816 100644
--- a/pagetop/src/html/opt_id.rs
+++ b/pagetop/src/html/opt_id.rs
@@ -1,7 +1,7 @@
use crate::fn_builder;
#[derive(Default)]
-pub struct OptionId(String);
+pub struct OptionId(Option);
impl OptionId {
pub fn new() -> Self {
@@ -18,17 +18,18 @@ impl OptionId {
#[fn_builder]
pub fn alter_value(&mut self, value: impl Into) -> &mut Self {
- self.0 = value.into().trim().replace(' ', "_");
+ self.0 = Some(value.into().trim().replace(' ', "_"));
self
}
// OptionId GETTERS.
pub fn get(&self) -> Option {
- if self.0.is_empty() {
- None
- } else {
- Some(self.0.to_owned())
+ if let Some(value) = &self.0 {
+ if !value.is_empty() {
+ return Some(value.to_owned());
+ }
}
+ None
}
}
diff --git a/pagetop/src/html/opt_name.rs b/pagetop/src/html/opt_name.rs
index e3cfb124..508db2c2 100644
--- a/pagetop/src/html/opt_name.rs
+++ b/pagetop/src/html/opt_name.rs
@@ -1,7 +1,7 @@
use crate::fn_builder;
#[derive(Default)]
-pub struct OptionName(String);
+pub struct OptionName(Option);
impl OptionName {
pub fn new() -> Self {
@@ -18,17 +18,18 @@ impl OptionName {
#[fn_builder]
pub fn alter_value(&mut self, value: impl Into) -> &mut Self {
- self.0 = value.into().trim().replace(' ', "_");
+ self.0 = Some(value.into().trim().replace(' ', "_"));
self
}
// OptionName GETTERS.
pub fn get(&self) -> Option {
- if self.0.is_empty() {
- None
- } else {
- Some(self.0.to_owned())
+ if let Some(value) = &self.0 {
+ if !value.is_empty() {
+ return Some(value.to_owned());
+ }
}
+ None
}
}
diff --git a/pagetop/src/html/opt_string.rs b/pagetop/src/html/opt_string.rs
index 35fe2ba8..b060728f 100644
--- a/pagetop/src/html/opt_string.rs
+++ b/pagetop/src/html/opt_string.rs
@@ -1,7 +1,7 @@
use crate::fn_builder;
#[derive(Default)]
-pub struct OptionString(String);
+pub struct OptionString(Option);
impl OptionString {
pub fn new() -> Self {
@@ -18,17 +18,18 @@ impl OptionString {
#[fn_builder]
pub fn alter_value(&mut self, value: impl Into) -> &mut Self {
- self.0 = value.into().trim().to_owned();
+ self.0 = Some(value.into().trim().to_owned());
self
}
// OptionString GETTERS.
pub fn get(&self) -> Option {
- if self.0.is_empty() {
- None
- } else {
- Some(self.0.to_owned())
+ if let Some(value) = &self.0 {
+ if !value.is_empty() {
+ return Some(value.to_owned());
+ }
}
+ None
}
}
diff --git a/pagetop/src/html/opt_translate.rs b/pagetop/src/html/opt_translate.rs
new file mode 100644
index 00000000..20f62061
--- /dev/null
+++ b/pagetop/src/html/opt_translate.rs
@@ -0,0 +1,40 @@
+use crate::fn_builder;
+use crate::html::{html, Markup};
+use crate::locale::{L10n, LanguageIdentifier};
+
+#[derive(Default)]
+pub struct OptionTranslate(Option);
+
+impl OptionTranslate {
+ pub fn new() -> Self {
+ OptionTranslate::default()
+ }
+
+ pub fn with(value: L10n) -> Self {
+ OptionTranslate(Some(value))
+ }
+
+ // OptionTranslate BUILDER.
+
+ #[fn_builder]
+ pub fn alter_value(&mut self, value: L10n) -> &mut Self {
+ self.0 = Some(value);
+ self
+ }
+
+ // OptionTranslate GETTERS.
+
+ pub fn using(&self, langid: &LanguageIdentifier) -> Option {
+ if let Some(value) = &self.0 {
+ return value.using(langid);
+ }
+ None
+ }
+
+ pub fn escaped(&self, langid: &LanguageIdentifier) -> Markup {
+ if let Some(value) = &self.0 {
+ return value.escaped(langid);
+ }
+ html! {}
+ }
+}