Implement get and tap functions.
This commit is contained in:
parent
3ef2facc92
commit
3fb91566bb
@ -41,6 +41,9 @@ pub enum DustTag<'a> {
|
|||||||
DTHelperLessThan(ParameterizedBlock<'a>),
|
DTHelperLessThan(ParameterizedBlock<'a>),
|
||||||
DTHelperGreaterThanOrEquals(ParameterizedBlock<'a>),
|
DTHelperGreaterThanOrEquals(ParameterizedBlock<'a>),
|
||||||
DTHelperLessThanOrEquals(ParameterizedBlock<'a>),
|
DTHelperLessThanOrEquals(ParameterizedBlock<'a>),
|
||||||
|
DTHelperSep(ParameterizedBlock<'a>),
|
||||||
|
DTHelperFirst(ParameterizedBlock<'a>),
|
||||||
|
DTHelperLast(ParameterizedBlock<'a>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
@ -240,6 +243,18 @@ fn dust_tag(i: &str) -> IResult<&str, DustTag> {
|
|||||||
parameterized_block("{@", &tag_to_path("lt")),
|
parameterized_block("{@", &tag_to_path("lt")),
|
||||||
DustTag::DTHelperLessThan,
|
DustTag::DTHelperLessThan,
|
||||||
),
|
),
|
||||||
|
map(
|
||||||
|
parameterized_block("{@", &tag_to_path("sep")),
|
||||||
|
DustTag::DTHelperSep,
|
||||||
|
),
|
||||||
|
map(
|
||||||
|
parameterized_block("{@", &tag_to_path("first")),
|
||||||
|
DustTag::DTHelperFirst,
|
||||||
|
),
|
||||||
|
map(
|
||||||
|
parameterized_block("{@", &tag_to_path("last")),
|
||||||
|
DustTag::DTHelperLast,
|
||||||
|
),
|
||||||
))(i)
|
))(i)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,5 +160,35 @@ fn extract_inline_partials_from_tag<'a, 'b>(
|
|||||||
Some(body) => extract_inline_partials_from_body(blocks, &body),
|
Some(body) => extract_inline_partials_from_body(blocks, &body),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
DustTag::DTHelperSep(parameterized_block) => {
|
||||||
|
match ¶meterized_block.contents {
|
||||||
|
None => (),
|
||||||
|
Some(body) => extract_inline_partials_from_body(blocks, &body),
|
||||||
|
};
|
||||||
|
match ¶meterized_block.else_contents {
|
||||||
|
None => (),
|
||||||
|
Some(body) => extract_inline_partials_from_body(blocks, &body),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
DustTag::DTHelperFirst(parameterized_block) => {
|
||||||
|
match ¶meterized_block.contents {
|
||||||
|
None => (),
|
||||||
|
Some(body) => extract_inline_partials_from_body(blocks, &body),
|
||||||
|
};
|
||||||
|
match ¶meterized_block.else_contents {
|
||||||
|
None => (),
|
||||||
|
Some(body) => extract_inline_partials_from_body(blocks, &body),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
DustTag::DTHelperLast(parameterized_block) => {
|
||||||
|
match ¶meterized_block.contents {
|
||||||
|
None => (),
|
||||||
|
Some(body) => extract_inline_partials_from_body(blocks, &body),
|
||||||
|
};
|
||||||
|
match ¶meterized_block.else_contents {
|
||||||
|
None => (),
|
||||||
|
Some(body) => extract_inline_partials_from_body(blocks, &body),
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@ use crate::renderer::inline_partial_tree::InlinePartialTreeElement;
|
|||||||
use crate::renderer::iteration_context::IterationContext;
|
use crate::renderer::iteration_context::IterationContext;
|
||||||
use crate::renderer::parameters_context::ParametersContext;
|
use crate::renderer::parameters_context::ParametersContext;
|
||||||
use crate::renderer::walking::walk_path;
|
use crate::renderer::walking::walk_path;
|
||||||
|
use std::borrow::Borrow;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
@ -644,11 +645,57 @@ impl<'a> DustRenderer<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
DustTag::DTHelperSep(parameterized_block) => {}
|
||||||
|
DustTag::DTHelperFirst(parameterized_block) => {}
|
||||||
|
DustTag::DTHelperLast(parameterized_block) => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok("".to_owned())
|
Ok("".to_owned())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Read a value from the context tree
|
||||||
|
pub fn get<P>(
|
||||||
|
&'a self,
|
||||||
|
breadcrumbs: &'a Vec<BreadcrumbTreeElement<'a>>,
|
||||||
|
name: &Vec<P>,
|
||||||
|
) -> Result<IceResult<'a>, WalkError>
|
||||||
|
where
|
||||||
|
P: Borrow<str>,
|
||||||
|
{
|
||||||
|
let val =
|
||||||
|
walk_path(breadcrumbs, name).map(|ice| ice.into_context_element(self, breadcrumbs));
|
||||||
|
match val {
|
||||||
|
Ok(Some(ice_result)) => Ok(ice_result),
|
||||||
|
Ok(None) => Err(WalkError::CantWalk),
|
||||||
|
Err(walk_error) => Err(walk_error),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Read a value from the parameters context
|
||||||
|
///
|
||||||
|
/// Returns None if the key is not present at all
|
||||||
|
pub fn tap<P>(
|
||||||
|
&'a self,
|
||||||
|
breadcrumbs: &'a Vec<BreadcrumbTreeElement<'a>>,
|
||||||
|
parameters: &'a ParametersContext<'a>,
|
||||||
|
name: &P,
|
||||||
|
) -> Option<Result<IceResult<'a>, WalkError>>
|
||||||
|
where
|
||||||
|
P: Borrow<str>,
|
||||||
|
{
|
||||||
|
if !parameters.contains_key(name.borrow()) {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
let val = parameters
|
||||||
|
.walk("key")
|
||||||
|
.map(|ice| ice.into_context_element(self, breadcrumbs));
|
||||||
|
match val {
|
||||||
|
Ok(Some(ice_result)) => Some(Ok(ice_result)),
|
||||||
|
Ok(None) => Some(Err(WalkError::CantWalk)),
|
||||||
|
Err(walk_error) => Some(Err(walk_error)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn new_breadcrumbs_section<'b>(
|
fn new_breadcrumbs_section<'b>(
|
||||||
&'b self,
|
&'b self,
|
||||||
breadcrumbs: &'b Vec<BreadcrumbTreeElement<'b>>,
|
breadcrumbs: &'b Vec<BreadcrumbTreeElement<'b>>,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user