use crate::*;
impl Style {
pub fn property<N, V>(mut self, name: N, value: V) -> Self
where
N: AsRef<str>,
V: AsRef<str>,
{
self.get_mut_properties().push(StyleProperty::new(
name.as_ref().replace('_', "-"),
value.as_ref().to_string(),
));
self
}
pub fn to_css_string(&self) -> String {
self.get_properties()
.iter()
.map(|p| format!("{}: {};", p.get_name(), p.get_value()))
.collect::<Vec<String>>()
.join(" ")
}
}
impl Default for Style {
fn default() -> Self {
Self::new(Vec::new())
}
}