Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter empty string classes #770

Merged
merged 4 commits into from
Dec 4, 2019
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 25 additions & 6 deletions src/virtual_dom/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,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 @@ -70,7 +72,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()));
jstarry marked this conversation as resolved.
Show resolved Hide resolved
self
}
}
Expand All @@ -89,28 +92,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