Implement IntoContextElement for ParametersContext.
This commit is contained in:
parent
02259b9bd6
commit
77b842f8de
@ -16,6 +16,7 @@ use crate::renderer::Renderable;
|
||||
use crate::renderer::Truthiness;
|
||||
use crate::renderer::WalkError;
|
||||
use crate::renderer::Walkable;
|
||||
use std::borrow::Borrow;
|
||||
use std::cmp::Ordering;
|
||||
use std::collections::HashMap;
|
||||
use std::rc::Rc;
|
||||
@ -57,6 +58,7 @@ impl<'a> ParametersContext<'a> {
|
||||
};
|
||||
v.map(|some_v| (k, some_v))
|
||||
})
|
||||
// TODO: Should a None value here be the same as a key not existing, or should we store the Nones?
|
||||
.filter_map(|pair| pair)
|
||||
.collect();
|
||||
|
||||
@ -66,6 +68,29 @@ impl<'a> ParametersContext<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> IntoContextElement for ParametersContext<'a> {
|
||||
fn into_context_element<'b>(
|
||||
&'b self,
|
||||
renderer: &DustRenderer,
|
||||
breadcrumbs: Option<&'b BreadcrumbTree<'b>>,
|
||||
) -> Option<IceResult<'b>> {
|
||||
panic!("into_context_element cannot be called on pseudo elements");
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Walkable for ParametersContext<'a> {
|
||||
fn walk(&self, segment: &str) -> Result<&dyn IntoContextElement, WalkError> {
|
||||
self.params
|
||||
.get(segment)
|
||||
.map(|bte| bte.borrow())
|
||||
.ok_or(WalkError::CantWalk)
|
||||
}
|
||||
|
||||
fn is_pseudo_element(&self) -> bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> IntoContextElement for RValue<'a> {
|
||||
fn into_context_element<'b>(
|
||||
&'b self,
|
||||
|
@ -16,6 +16,7 @@ use crate::renderer::errors::RenderError;
|
||||
use crate::renderer::errors::WalkError;
|
||||
use crate::renderer::inline_partial_tree::extract_inline_partials;
|
||||
use crate::renderer::inline_partial_tree::InlinePartialTreeElement;
|
||||
use crate::renderer::parameters_context::ParametersContext;
|
||||
use crate::renderer::tree_walking::walk_path;
|
||||
use std::borrow::Borrow;
|
||||
use std::collections::HashMap;
|
||||
@ -165,12 +166,19 @@ impl<'a> DustRenderer<'a> {
|
||||
}
|
||||
}
|
||||
DustTag::DTSection(container) => {
|
||||
//let injected_context = ParametersContext::new(breadcrumbs, &container.params);
|
||||
let injected_context = ParametersContext::new(self, breadcrumbs, &container.params);
|
||||
let val = walk_path(breadcrumbs, &container.path.keys)
|
||||
.map(|ice| ice.into_context_element(self, breadcrumbs));
|
||||
match val {
|
||||
Err(WalkError::CantWalk) => {
|
||||
// TODO
|
||||
let new_breadcrumbs = self.new_breadcrumbs_section(
|
||||
breadcrumbs,
|
||||
None,
|
||||
Some(&injected_context),
|
||||
&container.explicit_context,
|
||||
None,
|
||||
);
|
||||
}
|
||||
Ok(final_val) => {
|
||||
// TODO
|
||||
@ -348,6 +356,13 @@ impl<'a> DustRenderer<'a> {
|
||||
}
|
||||
final_filters
|
||||
}
|
||||
|
||||
fn append_new_elements_onto_tree<'b>(
|
||||
original_parent: Option<&'b BreadcrumbTree>,
|
||||
new_elements: Vec<BreadcrumbTreeElement<'b>>,
|
||||
) -> Option<BreadcrumbTree<'b>> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
struct BlockContext<'a> {
|
||||
|
Loading…
x
Reference in New Issue
Block a user