Add a new trait to ContextElement for Truthiness.
Before I was relying on Loopable to both determine truthiness and get a list of elements to loop over. This will no longer work since I need to only set $idx and $len when iterating over actual arrays, as opposed to all truthy values, so I've finally made truthiness explicit.
This commit is contained in:
@@ -3,6 +3,7 @@ use crate::renderer::context_element::ContextElement;
|
||||
use crate::renderer::Loopable;
|
||||
use crate::renderer::RenderError;
|
||||
use crate::renderer::Renderable;
|
||||
use crate::renderer::Truthiness;
|
||||
use crate::renderer::WalkError;
|
||||
use crate::{parser::Filter, parser::OwnedLiteral, renderer::Walkable};
|
||||
|
||||
@@ -30,6 +31,15 @@ impl IterationContext {
|
||||
|
||||
impl ContextElement for IterationContext {}
|
||||
|
||||
impl Truthiness for IterationContext {
|
||||
fn is_truthy(&self) -> bool {
|
||||
// TODO: Would this even ever be called? Won't matter, but I'd
|
||||
// like to know. Since it is injected 1 above the current
|
||||
// context, we wouldn't be able to access it with `{.}`.
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
impl Renderable for IterationContext {
|
||||
fn render(&self, _filters: &Vec<Filter>) -> Result<String, RenderError> {
|
||||
// TODO: Would this even ever be called? Won't matter, but I'd
|
||||
|
||||
Reference in New Issue
Block a user