I think I have the full extraction code.

This commit is contained in:
Tom Alexander 2020-05-09 21:30:54 -04:00
parent ae74ce411a
commit d2904913ad
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
3 changed files with 51 additions and 4 deletions

View File

@ -100,8 +100,8 @@ pub struct Container<'a> {
#[derive(Clone, Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
pub struct NamedBlock<'a> { pub struct NamedBlock<'a> {
name: &'a str, pub name: &'a str,
contents: Option<Body<'a>>, pub contents: Option<Body<'a>>,
} }
#[derive(Clone, Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]

View File

@ -10,10 +10,13 @@ struct InlinePartialTreeElement<'a> {
} }
impl<'a> InlinePartialTreeElement<'a> { impl<'a> InlinePartialTreeElement<'a> {
pub fn new(parent: Option<&'a InlinePartialTreeElement<'a>>) -> InlinePartialTreeElement<'a> { pub fn new(
parent: Option<&'a InlinePartialTreeElement<'a>>,
blocks: HashMap<&'a str, &'a Option<Body<'a>>>,
) -> InlinePartialTreeElement<'a> {
InlinePartialTreeElement { InlinePartialTreeElement {
parent: parent, parent: parent,
blocks: HashMap::new(), blocks: blocks,
} }
} }
} }
@ -49,6 +52,43 @@ fn extract_inline_partials_from_tag<'a, 'b>(
) { ) {
match tag { match tag {
DustTag::DTComment(..) => (), DustTag::DTComment(..) => (),
DustTag::DTSpecial(..) => (),
DustTag::DTReference(..) => (),
DustTag::DTSection(container) => {
match &container.contents {
None => (),
Some(body) => extract_inline_partials_from_body(blocks, &body),
};
match &container.else_contents {
None => (),
Some(body) => extract_inline_partials_from_body(blocks, &body),
};
}
DustTag::DTExists(container) => {
match &container.contents {
None => (),
Some(body) => extract_inline_partials_from_body(blocks, &body),
};
match &container.else_contents {
None => (),
Some(body) => extract_inline_partials_from_body(blocks, &body),
};
}
DustTag::DTNotExists(container) => {
match &container.contents {
None => (),
Some(body) => extract_inline_partials_from_body(blocks, &body),
};
match &container.else_contents {
None => (),
Some(body) => extract_inline_partials_from_body(blocks, &body),
};
}
DustTag::DTPartial(..) => (),
DustTag::DTInlinePartial(named_block) => {
blocks.insert(&named_block.name, &named_block.contents);
}
DustTag::DTBlock(..) => (),
_ => (), // TODO: Implement the rest _ => (), // TODO: Implement the rest
} }
} }

View File

@ -183,6 +183,13 @@ impl<'a> DustRenderer<'a> {
return Ok(rendered_content); return Ok(rendered_content);
} }
} }
DustTag::DTInlinePartial(named_block) => {
// Inline partials are blank during rendering (they get injected into blocks)
return Ok("".to_owned());
}
DustTag::DTBlock(named_block) => {
// TODO: Implement
}
_ => (), // TODO: Implement the rest _ => (), // TODO: Implement the rest
} }
Ok("".to_owned()) Ok("".to_owned())