mod attributes;
pub use attributes::*;
mod properties;
pub use properties::*;
mod tags;
pub use tags::*;
#[derive(Clone)]
pub struct El {
pub name: String,
pub is_text: bool,
pub paired: bool,
pub attributes: Vec<Attr>,
pub style: Vec<Prop>,
pub content: Vec<El>,
}
impl El {
pub fn text<N: Into<String>>(text: N) -> Self {
El {
is_text: true,
paired: false,
name: text.into(),
attributes: vec![],
style: vec![],
content: vec![],
}
}
pub fn attributes(mut self, values: &[Attr]) -> Self {
for val in values {
self.attributes.push(val.clone());
}
self
}
pub fn style(mut self, values: &[Prop]) -> Self {
for val in values {
self.style.push(val.clone());
}
self
}
pub fn content(mut self, values: &[El]) -> Self {
for val in values {
self.content.push(val.clone());
}
self
}
pub fn id_find(&mut self, id: &str) -> Option<&mut El> {
for attr in self.attributes.iter() {
if let Attr::Id(val) = attr {
if *val == *id {
return Some(self);
}
}
}
if !self.is_text && self.paired {
for child in self.content.iter_mut() {
let find = child.id_find(id);
match find {
Some(_) => { return find; },
None => (),
}
}
}
None
}
}