♻️ (util): Extrae non_blank() y normalize_token()
This commit is contained in:
parent
747e64ce34
commit
dc2ed27da4
8 changed files with 71 additions and 37 deletions
|
|
@ -1,5 +1,5 @@
|
|||
use crate::locale::{L10n, LangId};
|
||||
use crate::{AutoDefault, builder_fn};
|
||||
use crate::{AutoDefault, builder_fn, util};
|
||||
|
||||
/// Valor opcional para atributos HTML.
|
||||
///
|
||||
|
|
@ -163,12 +163,10 @@ impl AttrName {
|
|||
/// Establece un nombre nuevo normalizando el valor.
|
||||
#[builder_fn]
|
||||
pub fn with_name(mut self, name: impl AsRef<str>) -> Self {
|
||||
let name = name.as_ref().trim();
|
||||
if name.is_empty() {
|
||||
self.0 = Attr::default();
|
||||
} else {
|
||||
self.0 = Attr::some(name.to_ascii_lowercase().replace(' ', "_"));
|
||||
}
|
||||
self.0 = match util::normalize_token(name) {
|
||||
Some(name) => Attr::some(name),
|
||||
None => Attr::default(),
|
||||
};
|
||||
self
|
||||
}
|
||||
|
||||
|
|
@ -228,12 +226,10 @@ impl AttrValue {
|
|||
/// Establece una cadena nueva normalizando el valor.
|
||||
#[builder_fn]
|
||||
pub fn with_str(mut self, value: impl AsRef<str>) -> Self {
|
||||
let value = value.as_ref().trim();
|
||||
if value.is_empty() {
|
||||
self.0 = Attr::default();
|
||||
} else {
|
||||
self.0 = Attr::some(value.to_string());
|
||||
}
|
||||
self.0 = match util::non_blank(value.as_ref()) {
|
||||
Some(value) => Attr::some(value.to_string()),
|
||||
None => Attr::default(),
|
||||
};
|
||||
self
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -734,12 +734,7 @@ impl Props {
|
|||
// **< Props PRIVATE >**************************************************************************
|
||||
|
||||
fn apply_id(&mut self, id: &str) {
|
||||
let id = id.trim();
|
||||
self.id = if id.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(id.to_ascii_lowercase().replace(' ', "_"))
|
||||
};
|
||||
self.id = util::normalize_token(id);
|
||||
}
|
||||
|
||||
fn insert_classes<'a, I>(&mut self, classes: I, mut pos: usize)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use crate::AutoDefault;
|
||||
use crate::{AutoDefault, util};
|
||||
|
||||
use serde::{Deserialize, Deserializer};
|
||||
|
||||
|
|
@ -201,10 +201,9 @@ impl FromStr for UnitValue {
|
|||
type Err = String;
|
||||
|
||||
fn from_str(input: &str) -> Result<Self, Self::Err> {
|
||||
let s = input.trim();
|
||||
if s.is_empty() {
|
||||
let Some(s) = util::non_blank(input) else {
|
||||
return Ok(UnitValue::None);
|
||||
}
|
||||
};
|
||||
if s.eq_ignore_ascii_case("auto") {
|
||||
return Ok(UnitValue::Auto);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue