Generating the new treeX
This commit is contained in:
parent
d2904913ad
commit
9a33195c42
@ -4,7 +4,7 @@ use crate::parser::Template;
|
|||||||
use crate::parser::TemplateElement;
|
use crate::parser::TemplateElement;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
struct InlinePartialTreeElement<'a> {
|
pub struct InlinePartialTreeElement<'a> {
|
||||||
parent: Option<&'a InlinePartialTreeElement<'a>>,
|
parent: Option<&'a InlinePartialTreeElement<'a>>,
|
||||||
blocks: HashMap<&'a str, &'a Option<Body<'a>>>,
|
blocks: HashMap<&'a str, &'a Option<Body<'a>>>,
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,8 @@ use crate::renderer::context_element::ContextElement;
|
|||||||
use crate::renderer::errors::CompileError;
|
use crate::renderer::errors::CompileError;
|
||||||
use crate::renderer::errors::RenderError;
|
use crate::renderer::errors::RenderError;
|
||||||
use crate::renderer::errors::WalkError;
|
use crate::renderer::errors::WalkError;
|
||||||
|
use crate::renderer::inline_partial_tree::extract_inline_partials;
|
||||||
|
use crate::renderer::inline_partial_tree::InlinePartialTreeElement;
|
||||||
use crate::renderer::parameters_context::ParametersContext;
|
use crate::renderer::parameters_context::ParametersContext;
|
||||||
use crate::renderer::walking::walk_path;
|
use crate::renderer::walking::walk_path;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
@ -52,6 +54,15 @@ impl<'a> DustRenderer<'a> {
|
|||||||
&'a self,
|
&'a self,
|
||||||
name: &str,
|
name: &str,
|
||||||
breadcrumbs: &Vec<&'a dyn ContextElement>,
|
breadcrumbs: &Vec<&'a dyn ContextElement>,
|
||||||
|
) -> Result<String, RenderError> {
|
||||||
|
self.render_template(name, breadcrumbs, None)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn render_template(
|
||||||
|
&'a self,
|
||||||
|
name: &str,
|
||||||
|
breadcrumbs: &Vec<&'a dyn ContextElement>,
|
||||||
|
blocks: Option<&'a InlinePartialTreeElement<'a>>,
|
||||||
) -> Result<String, RenderError> {
|
) -> Result<String, RenderError> {
|
||||||
let main_template = match self.templates.get(name) {
|
let main_template = match self.templates.get(name) {
|
||||||
Some(tmpl) => tmpl,
|
Some(tmpl) => tmpl,
|
||||||
@ -59,6 +70,8 @@ impl<'a> DustRenderer<'a> {
|
|||||||
return Err(RenderError::TemplateNotFound(name.to_owned()));
|
return Err(RenderError::TemplateNotFound(name.to_owned()));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,13 +186,13 @@ impl<'a> DustRenderer<'a> {
|
|||||||
}
|
}
|
||||||
DustTag::DTPartial(partial) => {
|
DustTag::DTPartial(partial) => {
|
||||||
if partial.params.is_empty() {
|
if partial.params.is_empty() {
|
||||||
let rendered_content = self.render(&partial.name, breadcrumbs)?;
|
let rendered_content = self.render_template(&partial.name, breadcrumbs)?;
|
||||||
return Ok(rendered_content);
|
return Ok(rendered_content);
|
||||||
} else {
|
} else {
|
||||||
let injected_context = ParametersContext::new(breadcrumbs, &partial.params);
|
let injected_context = ParametersContext::new(breadcrumbs, &partial.params);
|
||||||
let mut new_breadcrumbs = breadcrumbs.clone();
|
let mut new_breadcrumbs = breadcrumbs.clone();
|
||||||
new_breadcrumbs.insert(new_breadcrumbs.len() - 1, &injected_context);
|
new_breadcrumbs.insert(new_breadcrumbs.len() - 1, &injected_context);
|
||||||
let rendered_content = self.render(&partial.name, &new_breadcrumbs)?;
|
let rendered_content = self.render_template(&partial.name, &new_breadcrumbs)?;
|
||||||
return Ok(rendered_content);
|
return Ok(rendered_content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user