use super::*;
pub struct Page {
pub content: Vec<El>,
}
impl Page {
pub fn new(content: &[El]) -> Self {
Page {
content: content.to_vec(),
}
}
pub fn add(mut self, child: El) -> Self {
self.content.push(child);
self
}
pub fn id_find(&mut self, id: &str) -> Option<&mut El> {
for child in self.content.iter_mut() {
let find = child.id_find(id);
match find {
Some(_) => { return find; },
None => (),
}
}
None
}
pub fn format(&self, make_pretty: bool) -> String {
let mut f = Formatter {
make_pretty,
buf: String::new(),
};
f.parse_and_format(&self.content, 0);
f.buf
}
}
impl std::fmt::Display for Page {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{}", self.format(true))
}
}