Forking the partial code for reuse as helper code
This commit is contained in:
parent
ad33f98404
commit
b7120a34de
@ -136,7 +136,7 @@ fn dust_tag(i: &str) -> IResult<&str, DustTag> {
|
||||
conditional("{^", DustTag::DTNotExists),
|
||||
named_block("{+", DustTag::DTBlock),
|
||||
named_block("{<", DustTag::DTInlinePartial),
|
||||
parameterized_self_closing_block("{>", DustTag::DTPartial),
|
||||
partial("{>", DustTag::DTPartial),
|
||||
))(i)
|
||||
}
|
||||
|
||||
@ -357,6 +357,33 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
fn partial<'a, F>(
|
||||
open_matcher: &'static str,
|
||||
constructor: F,
|
||||
) -> impl Fn(&'a str) -> IResult<&'a str, DustTag<'a>>
|
||||
where
|
||||
F: Fn(ParameterizedBlock<'a>) -> DustTag<'a>,
|
||||
{
|
||||
move |i: &'a str| {
|
||||
let (i, (name, params)) = delimited(
|
||||
tag(open_matcher),
|
||||
tuple((
|
||||
alt((map(key, String::from), quoted_string)),
|
||||
opt(preceded(space1, separated_list(space1, key_value_pair))),
|
||||
)),
|
||||
tag("/}"),
|
||||
)(i)?;
|
||||
|
||||
Ok((
|
||||
i,
|
||||
constructor(ParameterizedBlock {
|
||||
name: name,
|
||||
params: params.unwrap_or(Vec::new()),
|
||||
}),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn filter(i: &str) -> IResult<&str, Filter> {
|
||||
preceded(
|
||||
tag("|"),
|
||||
|
Loading…
x
Reference in New Issue
Block a user