Starting an IntoContextElement trait to allow for delayed evaluation.

This commit is contained in:
Tom Alexander
2020-05-30 16:34:32 -04:00
parent 581f9f7e97
commit 975ab278ef
5 changed files with 53 additions and 1 deletions

View File

@@ -9,6 +9,7 @@ use crate::parser::Special;
use crate::parser::Template;
use crate::parser::{Filter, TemplateElement};
use crate::renderer::context_element::ContextElement;
use crate::renderer::context_element::IntoContextElement;
use crate::renderer::errors::CompileError;
use crate::renderer::errors::RenderError;
use crate::renderer::errors::WalkError;
@@ -664,6 +665,23 @@ impl<'a> DustRenderer<'a> {
.collect()
}
fn new_get_rval<'b>(
breadcrumbs: &'b Vec<&'b dyn ContextElement>,
param_map: &HashMap<&str, &'b RValue<'b>>,
key: &str,
) -> Option<Result<&'b dyn IntoContextElement, WalkError>> {
match param_map.get(key) {
None => None,
Some(rval) => match rval {
RValue::RVLiteral(literal) => Some(Ok(literal)),
RValue::RVTemplate(template) => Some(Ok(template)),
RValue::RVPath(path) => {
Some(walk_path(breadcrumbs, &path.keys).map(|ce| ce.from_context_element()))
}
},
}
}
fn get_rval<'b>(
breadcrumbs: &'b Vec<&'b dyn ContextElement>,
param_map: &HashMap<&str, &'b RValue<'b>>,
@@ -673,6 +691,7 @@ impl<'a> DustRenderer<'a> {
None => None,
Some(rval) => match rval {
RValue::RVLiteral(literal) => Some(Ok(literal)),
RValue::RVTemplate(template) => None,
RValue::RVPath(path) => Some(walk_path(breadcrumbs, &path.keys)),
},
}