Rename NewParametersContext to ParametersContext.
This commit is contained in:
parent
75ba35a422
commit
6297fa0189
@ -48,16 +48,16 @@ impl From<&RValue<'_>> for OwnedRValue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct NewParametersContext {
|
pub struct ParametersContext {
|
||||||
params: HashMap<String, OwnedRValue>,
|
params: HashMap<String, OwnedRValue>,
|
||||||
breadcrumbs: Vec<Box<dyn ContextElement>>,
|
breadcrumbs: Vec<Box<dyn ContextElement>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NewParametersContext {
|
impl ParametersContext {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
breadcrumbs: &Vec<&dyn ContextElement>,
|
breadcrumbs: &Vec<&dyn ContextElement>,
|
||||||
params: &Vec<KVPair>,
|
params: &Vec<KVPair>,
|
||||||
) -> NewParametersContext {
|
) -> ParametersContext {
|
||||||
let owned_params: HashMap<String, OwnedRValue> = params
|
let owned_params: HashMap<String, OwnedRValue> = params
|
||||||
.iter()
|
.iter()
|
||||||
.map(|kvpair| (kvpair.key.to_string(), OwnedRValue::from(&kvpair.value)))
|
.map(|kvpair| (kvpair.key.to_string(), OwnedRValue::from(&kvpair.value)))
|
||||||
@ -65,16 +65,16 @@ impl NewParametersContext {
|
|||||||
let owned_breadcrumbs: Vec<Box<dyn ContextElement>> =
|
let owned_breadcrumbs: Vec<Box<dyn ContextElement>> =
|
||||||
breadcrumbs.iter().map(|ce| ce.clone_to_box()).collect();
|
breadcrumbs.iter().map(|ce| ce.clone_to_box()).collect();
|
||||||
|
|
||||||
NewParametersContext {
|
ParametersContext {
|
||||||
params: owned_params,
|
params: owned_params,
|
||||||
breadcrumbs: owned_breadcrumbs,
|
breadcrumbs: owned_breadcrumbs,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ContextElement for NewParametersContext {}
|
impl ContextElement for ParametersContext {}
|
||||||
|
|
||||||
impl Renderable for NewParametersContext {
|
impl Renderable for ParametersContext {
|
||||||
fn render(&self, _filters: &Vec<Filter>) -> Result<String, RenderError> {
|
fn render(&self, _filters: &Vec<Filter>) -> Result<String, RenderError> {
|
||||||
// TODO: Would this even ever be called? Won't matter, but I'd
|
// TODO: Would this even ever be called? Won't matter, but I'd
|
||||||
// like to know. Since it is injected 1 above the current
|
// like to know. Since it is injected 1 above the current
|
||||||
@ -83,7 +83,7 @@ impl Renderable for NewParametersContext {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Loopable for NewParametersContext {
|
impl Loopable for ParametersContext {
|
||||||
fn get_loop_elements(&self) -> Vec<&dyn ContextElement> {
|
fn get_loop_elements(&self) -> Vec<&dyn ContextElement> {
|
||||||
// TODO: Would this even ever be called? Won't matter, but I'd
|
// TODO: Would this even ever be called? Won't matter, but I'd
|
||||||
// like to know. Since it is injected 1 above the current
|
// like to know. Since it is injected 1 above the current
|
||||||
@ -92,7 +92,7 @@ impl Loopable for NewParametersContext {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Walkable for NewParametersContext {
|
impl Walkable for ParametersContext {
|
||||||
fn walk(&self, segment: &str) -> Result<&dyn ContextElement, WalkError> {
|
fn walk(&self, segment: &str) -> Result<&dyn ContextElement, WalkError> {
|
||||||
let rval = self.params.get(segment).ok_or(WalkError::CantWalk)?;
|
let rval = self.params.get(segment).ok_or(WalkError::CantWalk)?;
|
||||||
match rval {
|
match rval {
|
||||||
@ -102,17 +102,17 @@ impl Walkable for NewParametersContext {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Clone for NewParametersContext {
|
impl Clone for ParametersContext {
|
||||||
fn clone(&self) -> Self {
|
fn clone(&self) -> Self {
|
||||||
// TODO: Implement clone
|
// TODO: Implement clone
|
||||||
NewParametersContext {
|
ParametersContext {
|
||||||
params: HashMap::new(),
|
params: HashMap::new(),
|
||||||
breadcrumbs: Vec::new(),
|
breadcrumbs: Vec::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CompareContextElement for NewParametersContext {
|
impl CompareContextElement for ParametersContext {
|
||||||
fn equals(&self, other: &dyn ContextElement) -> bool {
|
fn equals(&self, other: &dyn ContextElement) -> bool {
|
||||||
// TODO: Does this ever happen? perhaps I should have a panic here.
|
// TODO: Does this ever happen? perhaps I should have a panic here.
|
||||||
false
|
false
|
||||||
|
@ -12,7 +12,7 @@ use crate::renderer::errors::RenderError;
|
|||||||
use crate::renderer::errors::WalkError;
|
use crate::renderer::errors::WalkError;
|
||||||
use crate::renderer::inline_partial_tree::extract_inline_partials;
|
use crate::renderer::inline_partial_tree::extract_inline_partials;
|
||||||
use crate::renderer::inline_partial_tree::InlinePartialTreeElement;
|
use crate::renderer::inline_partial_tree::InlinePartialTreeElement;
|
||||||
use crate::renderer::parameters_context::NewParametersContext;
|
use crate::renderer::parameters_context::ParametersContext;
|
||||||
use crate::renderer::walking::walk_path;
|
use crate::renderer::walking::walk_path;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
@ -194,7 +194,7 @@ impl<'a> DustRenderer<'a> {
|
|||||||
self.render_template(&partial.name, breadcrumbs, Some(blocks))?;
|
self.render_template(&partial.name, breadcrumbs, Some(blocks))?;
|
||||||
return Ok(rendered_content);
|
return Ok(rendered_content);
|
||||||
} else {
|
} else {
|
||||||
let injected_context = NewParametersContext::new(breadcrumbs, &partial.params);
|
let injected_context = ParametersContext::new(breadcrumbs, &partial.params);
|
||||||
let mut new_breadcrumbs = breadcrumbs.clone();
|
let mut new_breadcrumbs = breadcrumbs.clone();
|
||||||
new_breadcrumbs.insert(new_breadcrumbs.len() - 1, &injected_context);
|
new_breadcrumbs.insert(new_breadcrumbs.len() - 1, &injected_context);
|
||||||
let rendered_content =
|
let rendered_content =
|
||||||
|
Loading…
Reference in New Issue
Block a user