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:
@@ -6,6 +6,7 @@ use crate::renderer::walking::walk_path;
|
||||
use crate::renderer::Loopable;
|
||||
use crate::renderer::RenderError;
|
||||
use crate::renderer::Renderable;
|
||||
use crate::renderer::Truthiness;
|
||||
use crate::renderer::WalkError;
|
||||
use crate::renderer::Walkable;
|
||||
use std::{cmp::Ordering, collections::HashMap};
|
||||
@@ -67,6 +68,15 @@ impl ParametersContext {
|
||||
|
||||
impl ContextElement for ParametersContext {}
|
||||
|
||||
impl Truthiness for ParametersContext {
|
||||
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 ParametersContext {
|
||||
fn render(&self, _filters: &Vec<Filter>) -> Result<String, RenderError> {
|
||||
// TODO: Would this even ever be called? Won't matter, but I'd
|
||||
@@ -128,6 +138,15 @@ impl CompareContextElement for ParametersContext {
|
||||
|
||||
impl ContextElement for OwnedLiteral {}
|
||||
|
||||
impl Truthiness for OwnedLiteral {
|
||||
fn is_truthy(&self) -> bool {
|
||||
match self {
|
||||
OwnedLiteral::LString(text) => !text.is_empty(),
|
||||
OwnedLiteral::LPositiveInteger(num) => true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Renderable for OwnedLiteral {
|
||||
fn render(&self, _filters: &Vec<Filter>) -> Result<String, RenderError> {
|
||||
match self {
|
||||
|
||||
Reference in New Issue
Block a user