Update IterationContext to be an IntoContextElement and finish implementing section.

This commit is contained in:
Tom Alexander
2020-06-06 23:08:21 -04:00
parent 00699b84ba
commit e28ebaf26a
3 changed files with 102 additions and 52 deletions

View File

@@ -1,6 +1,9 @@
use crate::renderer::breadcrumb_tree::BreadcrumbTreeElement;
use crate::renderer::context_element::CompareContextElement;
use crate::renderer::context_element::ContextElement;
use crate::renderer::context_element::IceResult;
use crate::renderer::context_element::IntoContextElement;
use crate::renderer::DustRenderer;
use crate::renderer::Loopable;
use crate::renderer::RenderError;
use crate::renderer::Renderable;
@@ -16,7 +19,7 @@ use std::cmp::Ordering;
/// Functions the same as the injected parameters contexts for
/// helpers/partials with parameters but this has no need for storing
/// breadcrumbs since its simply storing two integers.
#[derive(Debug, Clone)]
#[derive(Debug)]
pub struct IterationContext {
idx: OwnedLiteral,
len: OwnedLiteral,
@@ -32,32 +35,13 @@ 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
// like to know. Since it is injected 1 above the current
// context, we wouldn't be able to access it with `{.}`.
Ok("[object Object]".to_owned())
}
}
impl Loopable for IterationContext {
fn get_loop_elements(&self) -> Vec<&dyn ContextElement> {
// 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 `{.}`.
Vec::new()
impl IntoContextElement for IterationContext {
fn into_context_element<'b>(
&'b self,
renderer: &DustRenderer,
breadcrumbs: &'b Vec<BreadcrumbTreeElement<'b>>,
) -> Option<IceResult<'b>> {
panic!("into_context_element cannot be called on pseudo elements");
}
}
@@ -74,15 +58,3 @@ impl Walkable for IterationContext {
true
}
}
impl CompareContextElement for IterationContext {
fn equals(&self, other: &dyn ContextElement) -> bool {
// TODO: Does this ever happen? perhaps I should have a panic here.
false
}
fn partial_compare(&self, other: &dyn ContextElement) -> Option<Ordering> {
// TODO: Does this ever happen? perhaps I should have a panic here.
None
}
}