Skip to content

Commit

Permalink
Filter empty string classes
Browse files Browse the repository at this point in the history
  • Loading branch information
jstarry committed Dec 3, 2019
1 parent f1459a8 commit 9ed69e4
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions src/virtual_dom/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ impl Classes {
///
/// Prevents duplication of class names.
pub fn push(&mut self, class: &str) {
self.set.insert(class.into());
if !class.is_empty() {
self.set.insert(class.into());
}
}

/// Check the set contains a class.
Expand All @@ -69,7 +71,8 @@ impl Classes {
///
/// Takes the logical union of both `Classes`.
pub fn extend<T: Into<Classes>>(mut self, other: T) -> Self {
self.set.extend(other.into().set.into_iter());
self.set
.extend(other.into().set.into_iter().filter(|c| !c.is_empty()));
self
}
}
Expand All @@ -88,28 +91,44 @@ impl ToString for Classes {

impl From<&str> for Classes {
fn from(t: &str) -> Self {
let set = t.split_whitespace().map(String::from).collect();
let set = t
.split_whitespace()
.map(String::from)
.filter(|c| !c.is_empty())
.collect();
Self { set }
}
}

impl From<String> for Classes {
fn from(t: String) -> Self {
let set = t.split_whitespace().map(String::from).collect();
let set = t
.split_whitespace()
.map(String::from)
.filter(|c| !c.is_empty())
.collect();
Self { set }
}
}

impl From<&String> for Classes {
fn from(t: &String) -> Self {
let set = t.split_whitespace().map(String::from).collect();
let set = t
.split_whitespace()
.map(String::from)
.filter(|c| !c.is_empty())
.collect();
Self { set }
}
}

impl<T: AsRef<str>> From<Vec<T>> for Classes {
fn from(t: Vec<T>) -> Self {
let set = t.iter().map(|x| x.as_ref().to_string()).collect();
let set = t
.iter()
.map(|x| x.as_ref().to_string())
.filter(|c| !c.is_empty())
.collect();
Self { set }
}
}
Expand Down

0 comments on commit 9ed69e4

Please sign in to comment.