Passing the block tree through the render functions.
This commit is contained in:
parent
9a33195c42
commit
6837fba489
@ -72,13 +72,14 @@ impl<'a> DustRenderer<'a> {
|
||||
};
|
||||
let extracted_inline_partials = extract_inline_partials(main_template);
|
||||
let new_blocks = InlinePartialTreeElement::new(blocks, extracted_inline_partials);
|
||||
self.render_body(&main_template.contents, breadcrumbs)
|
||||
self.render_body(&main_template.contents, breadcrumbs, &new_blocks)
|
||||
}
|
||||
|
||||
fn render_body(
|
||||
&'a self,
|
||||
body: &'a Body,
|
||||
breadcrumbs: &Vec<&'a dyn ContextElement>,
|
||||
blocks: &'a InlinePartialTreeElement<'a>,
|
||||
) -> Result<String, RenderError> {
|
||||
let mut output = String::new();
|
||||
for elem in &body.elements {
|
||||
@ -86,7 +87,7 @@ impl<'a> DustRenderer<'a> {
|
||||
TemplateElement::TEIgnoredWhitespace(_) => {}
|
||||
TemplateElement::TESpan(span) => output.push_str(span.contents),
|
||||
TemplateElement::TETag(dt) => {
|
||||
output.push_str(&self.render_tag(dt, breadcrumbs)?);
|
||||
output.push_str(&self.render_tag(dt, breadcrumbs, blocks)?);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -97,6 +98,7 @@ impl<'a> DustRenderer<'a> {
|
||||
&'a self,
|
||||
tag: &'a DustTag,
|
||||
breadcrumbs: &Vec<&'a dyn ContextElement>,
|
||||
blocks: &'a InlinePartialTreeElement<'a>,
|
||||
) -> Result<String, RenderError> {
|
||||
match tag {
|
||||
DustTag::DTComment(_comment) => (),
|
||||
@ -133,7 +135,7 @@ impl<'a> DustRenderer<'a> {
|
||||
// original context before walking the path as
|
||||
// the context for rendering the else block
|
||||
return match &container.else_contents {
|
||||
Some(body) => self.render_body(&body, breadcrumbs),
|
||||
Some(body) => self.render_body(&body, breadcrumbs, blocks),
|
||||
None => Ok("".to_owned()),
|
||||
};
|
||||
} else {
|
||||
@ -145,7 +147,7 @@ impl<'a> DustRenderer<'a> {
|
||||
.map(|array_elem| {
|
||||
let mut new_breadcumbs = breadcrumbs.clone();
|
||||
new_breadcumbs.push(array_elem);
|
||||
self.render_body(&body, &new_breadcumbs)
|
||||
self.render_body(&body, &new_breadcumbs, blocks)
|
||||
})
|
||||
.collect();
|
||||
let rendered_slice: &[String] = &rendered_results?;
|
||||
@ -159,13 +161,13 @@ impl<'a> DustRenderer<'a> {
|
||||
let loop_elements: Vec<&dyn ContextElement> = self.get_loop_elements(val);
|
||||
if loop_elements.is_empty() {
|
||||
return match &container.else_contents {
|
||||
Some(body) => self.render_body(&body, breadcrumbs),
|
||||
Some(body) => self.render_body(&body, breadcrumbs, blocks),
|
||||
None => Ok("".to_owned()),
|
||||
};
|
||||
} else {
|
||||
return match &container.contents {
|
||||
None => Ok("".to_owned()),
|
||||
Some(body) => self.render_body(&body, breadcrumbs),
|
||||
Some(body) => self.render_body(&body, breadcrumbs, blocks),
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -174,25 +176,27 @@ impl<'a> DustRenderer<'a> {
|
||||
let loop_elements: Vec<&dyn ContextElement> = self.get_loop_elements(val);
|
||||
if !loop_elements.is_empty() {
|
||||
return match &container.else_contents {
|
||||
Some(body) => self.render_body(&body, breadcrumbs),
|
||||
Some(body) => self.render_body(&body, breadcrumbs, blocks),
|
||||
None => Ok("".to_owned()),
|
||||
};
|
||||
} else {
|
||||
return match &container.contents {
|
||||
None => Ok("".to_owned()),
|
||||
Some(body) => self.render_body(&body, breadcrumbs),
|
||||
Some(body) => self.render_body(&body, breadcrumbs, blocks),
|
||||
};
|
||||
}
|
||||
}
|
||||
DustTag::DTPartial(partial) => {
|
||||
if partial.params.is_empty() {
|
||||
let rendered_content = self.render_template(&partial.name, breadcrumbs)?;
|
||||
let rendered_content =
|
||||
self.render_template(&partial.name, breadcrumbs, Some(blocks))?;
|
||||
return Ok(rendered_content);
|
||||
} else {
|
||||
let injected_context = ParametersContext::new(breadcrumbs, &partial.params);
|
||||
let mut new_breadcrumbs = breadcrumbs.clone();
|
||||
new_breadcrumbs.insert(new_breadcrumbs.len() - 1, &injected_context);
|
||||
let rendered_content = self.render_template(&partial.name, &new_breadcrumbs)?;
|
||||
let rendered_content =
|
||||
self.render_template(&partial.name, &new_breadcrumbs, Some(blocks))?;
|
||||
return Ok(rendered_content);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user