Implemented early termination.
This commit is contained in:
parent
0fac063c8d
commit
88887bff0f
@ -80,7 +80,7 @@ impl<'a> DustRenderer<'a> {
|
|||||||
&main_template.contents,
|
&main_template.contents,
|
||||||
breadcrumbs,
|
breadcrumbs,
|
||||||
&new_block_context,
|
&new_block_context,
|
||||||
None,
|
&mut None,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,7 +89,7 @@ impl<'a> DustRenderer<'a> {
|
|||||||
body: &'a Option<Body>,
|
body: &'a Option<Body>,
|
||||||
breadcrumbs: &'a Vec<BreadcrumbTreeElement<'a>>,
|
breadcrumbs: &'a Vec<BreadcrumbTreeElement<'a>>,
|
||||||
blocks: &'a BlockContext<'a>,
|
blocks: &'a BlockContext<'a>,
|
||||||
select_context: Option<&'a SelectContext<'a>>,
|
select_context: &mut Option<SelectContext<'a>>,
|
||||||
) -> Result<String, RenderError> {
|
) -> Result<String, RenderError> {
|
||||||
match body {
|
match body {
|
||||||
None => Ok("".to_owned()),
|
None => Ok("".to_owned()),
|
||||||
@ -102,7 +102,7 @@ impl<'a> DustRenderer<'a> {
|
|||||||
body: &'a Body,
|
body: &'a Body,
|
||||||
breadcrumbs: &'a Vec<BreadcrumbTreeElement<'a>>,
|
breadcrumbs: &'a Vec<BreadcrumbTreeElement<'a>>,
|
||||||
blocks: &'a BlockContext<'a>,
|
blocks: &'a BlockContext<'a>,
|
||||||
select_context: Option<&'a SelectContext<'a>>,
|
select_context: &mut Option<SelectContext<'a>>,
|
||||||
) -> Result<String, RenderError> {
|
) -> Result<String, RenderError> {
|
||||||
let mut output = String::new();
|
let mut output = String::new();
|
||||||
for elem in &body.elements {
|
for elem in &body.elements {
|
||||||
@ -138,7 +138,7 @@ impl<'a> DustRenderer<'a> {
|
|||||||
},
|
},
|
||||||
breadcrumbs,
|
breadcrumbs,
|
||||||
&empty_block_context,
|
&empty_block_context,
|
||||||
None,
|
&mut None,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,7 +147,7 @@ impl<'a> DustRenderer<'a> {
|
|||||||
tag: &'a DustTag,
|
tag: &'a DustTag,
|
||||||
breadcrumbs: &'a Vec<BreadcrumbTreeElement<'a>>,
|
breadcrumbs: &'a Vec<BreadcrumbTreeElement<'a>>,
|
||||||
blocks: &'a BlockContext<'a>,
|
blocks: &'a BlockContext<'a>,
|
||||||
select_context: Option<&'a SelectContext<'a>>,
|
select_context: &mut Option<SelectContext<'a>>,
|
||||||
) -> Result<String, RenderError> {
|
) -> Result<String, RenderError> {
|
||||||
match tag {
|
match tag {
|
||||||
DustTag::DTComment(_comment) => (),
|
DustTag::DTComment(_comment) => (),
|
||||||
@ -196,7 +196,7 @@ impl<'a> DustRenderer<'a> {
|
|||||||
&container.else_contents,
|
&container.else_contents,
|
||||||
new_breadcrumbs.as_ref().unwrap_or(breadcrumbs),
|
new_breadcrumbs.as_ref().unwrap_or(breadcrumbs),
|
||||||
blocks,
|
blocks,
|
||||||
None,
|
&mut None,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Ok(Some(final_val)) => {
|
Ok(Some(final_val)) => {
|
||||||
@ -220,7 +220,7 @@ impl<'a> DustRenderer<'a> {
|
|||||||
body,
|
body,
|
||||||
new_breadcrumbs.as_ref().unwrap_or(breadcrumbs),
|
new_breadcrumbs.as_ref().unwrap_or(breadcrumbs),
|
||||||
blocks,
|
blocks,
|
||||||
None,
|
&mut None,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
// Array-like value
|
// Array-like value
|
||||||
@ -246,7 +246,7 @@ impl<'a> DustRenderer<'a> {
|
|||||||
.as_ref()
|
.as_ref()
|
||||||
.unwrap_or(breadcrumbs),
|
.unwrap_or(breadcrumbs),
|
||||||
blocks,
|
blocks,
|
||||||
None,
|
&mut None,
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
@ -271,7 +271,7 @@ impl<'a> DustRenderer<'a> {
|
|||||||
&container.else_contents,
|
&container.else_contents,
|
||||||
new_breadcrumbs.as_ref().unwrap_or(breadcrumbs),
|
new_breadcrumbs.as_ref().unwrap_or(breadcrumbs),
|
||||||
blocks,
|
blocks,
|
||||||
None,
|
&mut None,
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -292,13 +292,13 @@ impl<'a> DustRenderer<'a> {
|
|||||||
&container.contents,
|
&container.contents,
|
||||||
new_breadcrumbs.as_ref().unwrap_or(breadcrumbs),
|
new_breadcrumbs.as_ref().unwrap_or(breadcrumbs),
|
||||||
blocks,
|
blocks,
|
||||||
None,
|
&mut None,
|
||||||
),
|
),
|
||||||
_ => self.render_maybe_body(
|
_ => self.render_maybe_body(
|
||||||
&container.else_contents,
|
&container.else_contents,
|
||||||
new_breadcrumbs.as_ref().unwrap_or(breadcrumbs),
|
new_breadcrumbs.as_ref().unwrap_or(breadcrumbs),
|
||||||
blocks,
|
blocks,
|
||||||
None,
|
&mut None,
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -317,13 +317,13 @@ impl<'a> DustRenderer<'a> {
|
|||||||
&container.else_contents,
|
&container.else_contents,
|
||||||
new_breadcrumbs.as_ref().unwrap_or(breadcrumbs),
|
new_breadcrumbs.as_ref().unwrap_or(breadcrumbs),
|
||||||
blocks,
|
blocks,
|
||||||
None,
|
&mut None,
|
||||||
),
|
),
|
||||||
_ => self.render_maybe_body(
|
_ => self.render_maybe_body(
|
||||||
&container.contents,
|
&container.contents,
|
||||||
new_breadcrumbs.as_ref().unwrap_or(breadcrumbs),
|
new_breadcrumbs.as_ref().unwrap_or(breadcrumbs),
|
||||||
blocks,
|
blocks,
|
||||||
None,
|
&mut None,
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -375,13 +375,13 @@ impl<'a> DustRenderer<'a> {
|
|||||||
&named_block.contents,
|
&named_block.contents,
|
||||||
new_breadcrumbs.as_ref().unwrap_or(breadcrumbs),
|
new_breadcrumbs.as_ref().unwrap_or(breadcrumbs),
|
||||||
blocks,
|
blocks,
|
||||||
None,
|
&mut None,
|
||||||
),
|
),
|
||||||
Some(inline_partial) => self.render_maybe_body(
|
Some(inline_partial) => self.render_maybe_body(
|
||||||
inline_partial,
|
inline_partial,
|
||||||
new_breadcrumbs.as_ref().unwrap_or(breadcrumbs),
|
new_breadcrumbs.as_ref().unwrap_or(breadcrumbs),
|
||||||
blocks,
|
blocks,
|
||||||
None,
|
&mut None,
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -391,6 +391,12 @@ impl<'a> DustRenderer<'a> {
|
|||||||
| DustTag::DTHelperLessThan(parameterized_block)
|
| DustTag::DTHelperLessThan(parameterized_block)
|
||||||
| DustTag::DTHelperGreaterThanOrEquals(parameterized_block)
|
| DustTag::DTHelperGreaterThanOrEquals(parameterized_block)
|
||||||
| DustTag::DTHelperLessThanOrEquals(parameterized_block) => {
|
| DustTag::DTHelperLessThanOrEquals(parameterized_block) => {
|
||||||
|
match select_context {
|
||||||
|
Some(sc) if sc.allowed_to_render_any_more_conditionals == false => {
|
||||||
|
return Ok("".to_owned())
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
let new_breadcrumbs = self.new_breadcrumbs_partial(
|
let new_breadcrumbs = self.new_breadcrumbs_partial(
|
||||||
breadcrumbs,
|
breadcrumbs,
|
||||||
breadcrumbs,
|
breadcrumbs,
|
||||||
@ -402,22 +408,25 @@ impl<'a> DustRenderer<'a> {
|
|||||||
.perform_comparison_check(
|
.perform_comparison_check(
|
||||||
tag,
|
tag,
|
||||||
breadcrumbs,
|
breadcrumbs,
|
||||||
select_context.map(|sc| sc.select_parameters),
|
select_context.as_ref().map(|sc| sc.select_parameters),
|
||||||
)
|
)
|
||||||
.map(|check_result| {
|
.map(|check_result| {
|
||||||
if check_result {
|
if check_result {
|
||||||
|
select_context.as_mut().map(|sc| {
|
||||||
|
sc.allowed_to_render_any_more_conditionals = false;
|
||||||
|
});
|
||||||
self.render_maybe_body(
|
self.render_maybe_body(
|
||||||
¶meterized_block.contents,
|
¶meterized_block.contents,
|
||||||
new_breadcrumbs.as_ref().unwrap_or(breadcrumbs),
|
new_breadcrumbs.as_ref().unwrap_or(breadcrumbs),
|
||||||
blocks,
|
blocks,
|
||||||
None,
|
&mut None,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
self.render_maybe_body(
|
self.render_maybe_body(
|
||||||
¶meterized_block.else_contents,
|
¶meterized_block.else_contents,
|
||||||
new_breadcrumbs.as_ref().unwrap_or(breadcrumbs),
|
new_breadcrumbs.as_ref().unwrap_or(breadcrumbs),
|
||||||
blocks,
|
blocks,
|
||||||
None,
|
&mut None,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -439,7 +448,7 @@ impl<'a> DustRenderer<'a> {
|
|||||||
¶meterized_block.contents,
|
¶meterized_block.contents,
|
||||||
new_breadcrumbs.as_ref().unwrap_or(breadcrumbs),
|
new_breadcrumbs.as_ref().unwrap_or(breadcrumbs),
|
||||||
blocks,
|
blocks,
|
||||||
None,
|
&mut None,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
(Ok(index_resolved), Ok(len_resolved)) => {
|
(Ok(index_resolved), Ok(len_resolved)) => {
|
||||||
@ -464,7 +473,7 @@ impl<'a> DustRenderer<'a> {
|
|||||||
¶meterized_block.contents,
|
¶meterized_block.contents,
|
||||||
new_breadcrumbs.as_ref().unwrap_or(breadcrumbs),
|
new_breadcrumbs.as_ref().unwrap_or(breadcrumbs),
|
||||||
blocks,
|
blocks,
|
||||||
None,
|
&mut None,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -499,7 +508,7 @@ impl<'a> DustRenderer<'a> {
|
|||||||
¶meterized_block.contents,
|
¶meterized_block.contents,
|
||||||
new_breadcrumbs.as_ref().unwrap_or(breadcrumbs),
|
new_breadcrumbs.as_ref().unwrap_or(breadcrumbs),
|
||||||
blocks,
|
blocks,
|
||||||
None,
|
&mut None,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -542,7 +551,7 @@ impl<'a> DustRenderer<'a> {
|
|||||||
¶meterized_block.contents,
|
¶meterized_block.contents,
|
||||||
new_breadcrumbs.as_ref().unwrap_or(breadcrumbs),
|
new_breadcrumbs.as_ref().unwrap_or(breadcrumbs),
|
||||||
blocks,
|
blocks,
|
||||||
None,
|
&mut None,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -591,12 +600,13 @@ impl<'a> DustRenderer<'a> {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
.any(|check_result| check_result.unwrap_or(false));
|
.any(|check_result| check_result.unwrap_or(false));
|
||||||
let select_context = SelectContext::new(¶m_map, are_any_checks_true);
|
let mut select_context =
|
||||||
|
SelectContext::new(¶m_map, are_any_checks_true);
|
||||||
return self.render_maybe_body(
|
return self.render_maybe_body(
|
||||||
¶meterized_block.contents,
|
¶meterized_block.contents,
|
||||||
new_breadcrumbs_ref,
|
new_breadcrumbs_ref,
|
||||||
blocks,
|
blocks,
|
||||||
Some(&select_context),
|
&mut Some(select_context),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -613,7 +623,7 @@ impl<'a> DustRenderer<'a> {
|
|||||||
¶meterized_block.contents,
|
¶meterized_block.contents,
|
||||||
new_breadcrumbs.as_ref().unwrap_or(breadcrumbs),
|
new_breadcrumbs.as_ref().unwrap_or(breadcrumbs),
|
||||||
blocks,
|
blocks,
|
||||||
None,
|
&mut None,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
_ => return Ok("".to_owned()),
|
_ => return Ok("".to_owned()),
|
||||||
@ -630,7 +640,7 @@ impl<'a> DustRenderer<'a> {
|
|||||||
¶meterized_block.contents,
|
¶meterized_block.contents,
|
||||||
new_breadcrumbs.as_ref().unwrap_or(breadcrumbs),
|
new_breadcrumbs.as_ref().unwrap_or(breadcrumbs),
|
||||||
blocks,
|
blocks,
|
||||||
None,
|
&mut None,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
_ => return Ok("".to_owned()),
|
_ => return Ok("".to_owned()),
|
||||||
|
@ -4,6 +4,7 @@ use crate::renderer::parameters_context::ParametersContext;
|
|||||||
pub struct SelectContext<'a> {
|
pub struct SelectContext<'a> {
|
||||||
pub select_parameters: &'a ParametersContext<'a>,
|
pub select_parameters: &'a ParametersContext<'a>,
|
||||||
pub were_any_true: bool,
|
pub were_any_true: bool,
|
||||||
|
pub allowed_to_render_any_more_conditionals: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> SelectContext<'a> {
|
impl<'a> SelectContext<'a> {
|
||||||
@ -11,6 +12,7 @@ impl<'a> SelectContext<'a> {
|
|||||||
SelectContext {
|
SelectContext {
|
||||||
select_parameters: select_parameters,
|
select_parameters: select_parameters,
|
||||||
were_any_true: were_any_true,
|
were_any_true: were_any_true,
|
||||||
|
allowed_to_render_any_more_conditionals: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user