2020-05-09 21:01:37 -04:00
|
|
|
use crate::parser::Body;
|
2020-05-09 21:09:46 -04:00
|
|
|
use crate::parser::DustTag;
|
2020-05-09 21:01:37 -04:00
|
|
|
use crate::parser::Template;
|
2020-05-09 21:09:46 -04:00
|
|
|
use crate::parser::TemplateElement;
|
2020-05-09 21:01:37 -04:00
|
|
|
use std::collections::HashMap;
|
|
|
|
|
|
|
|
struct InlinePartialTreeElement<'a> {
|
|
|
|
parent: Option<&'a InlinePartialTreeElement<'a>>,
|
|
|
|
blocks: HashMap<&'a str, &'a Option<Body<'a>>>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> InlinePartialTreeElement<'a> {
|
|
|
|
pub fn new(parent: Option<&'a InlinePartialTreeElement<'a>>) -> InlinePartialTreeElement<'a> {
|
|
|
|
InlinePartialTreeElement {
|
|
|
|
parent: parent,
|
|
|
|
blocks: HashMap::new(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn extract_inline_partials<'a>(
|
|
|
|
template: &'a Template<'a>,
|
|
|
|
) -> HashMap<&'a str, &'a Option<Body<'a>>> {
|
|
|
|
let mut blocks: HashMap<&'a str, &'a Option<Body<'a>>> = HashMap::new();
|
|
|
|
|
|
|
|
extract_inline_partials_from_body(&mut blocks, &template.contents);
|
|
|
|
|
|
|
|
blocks
|
|
|
|
}
|
|
|
|
|
|
|
|
fn extract_inline_partials_from_body<'a, 'b>(
|
|
|
|
blocks: &'b mut HashMap<&'a str, &'a Option<Body<'a>>>,
|
|
|
|
body: &'a Body<'a>,
|
|
|
|
) {
|
2020-05-09 21:09:46 -04:00
|
|
|
for elem in &body.elements {
|
|
|
|
match elem {
|
|
|
|
TemplateElement::TEIgnoredWhitespace(_) => (),
|
|
|
|
TemplateElement::TESpan(span) => (),
|
|
|
|
TemplateElement::TETag(dt) => {
|
|
|
|
extract_inline_partials_from_tag(blocks, dt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn extract_inline_partials_from_tag<'a, 'b>(
|
|
|
|
blocks: &'b mut HashMap<&'a str, &'a Option<Body<'a>>>,
|
|
|
|
tag: &'a DustTag,
|
|
|
|
) {
|
|
|
|
match tag {
|
|
|
|
DustTag::DTComment(..) => (),
|
|
|
|
_ => (), // TODO: Implement the rest
|
|
|
|
}
|
2020-05-09 21:01:37 -04:00
|
|
|
}
|