Implemented parsing for explicit contexts in NamedBlocks.
This commit is contained in:
parent
dbee569931
commit
9031108d2a
@ -103,6 +103,7 @@ pub struct Container<'a> {
|
|||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub struct NamedBlock<'a> {
|
pub struct NamedBlock<'a> {
|
||||||
pub name: &'a str,
|
pub name: &'a str,
|
||||||
|
pub explicit_context: Option<Path<'a>>,
|
||||||
pub contents: Option<Body<'a>>,
|
pub contents: Option<Body<'a>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -412,19 +413,21 @@ where
|
|||||||
F: Fn(NamedBlock<'a>) -> DustTag<'a>,
|
F: Fn(NamedBlock<'a>) -> DustTag<'a>,
|
||||||
{
|
{
|
||||||
move |i: &'a str| {
|
move |i: &'a str| {
|
||||||
let (i, (opening_name, inner, _closing_name)) = verify(
|
let (i, (opening_name, maybe_explicit_context, inner, _closing_name)) = verify(
|
||||||
tuple((
|
tuple((
|
||||||
delimited(tag(open_matcher), key, tag("}")),
|
preceded(tag(open_matcher), key),
|
||||||
|
terminated(opt(preceded(tag(":"), path)), tag("}")),
|
||||||
opt(body),
|
opt(body),
|
||||||
delimited(tag("{/"), key, tag("}")),
|
delimited(tag("{/"), key, tag("}")),
|
||||||
)),
|
)),
|
||||||
|(open, _inn, close)| open == close,
|
|(open, _maybe_explicit, _inn, close)| open == close,
|
||||||
)(i)?;
|
)(i)?;
|
||||||
|
|
||||||
Ok((
|
Ok((
|
||||||
i,
|
i,
|
||||||
constructor(NamedBlock {
|
constructor(NamedBlock {
|
||||||
name: opening_name,
|
name: opening_name,
|
||||||
|
explicit_context: maybe_explicit_context,
|
||||||
contents: inner,
|
contents: inner,
|
||||||
}),
|
}),
|
||||||
))
|
))
|
||||||
@ -439,12 +442,16 @@ where
|
|||||||
F: Fn(NamedBlock<'a>) -> DustTag<'a>,
|
F: Fn(NamedBlock<'a>) -> DustTag<'a>,
|
||||||
{
|
{
|
||||||
move |i: &'a str| {
|
move |i: &'a str| {
|
||||||
let (i, name) = delimited(tag(open_matcher), key, tag("/}"))(i)?;
|
let (i, (opening_name, maybe_explicit_context)) = tuple((
|
||||||
|
preceded(tag(open_matcher), key),
|
||||||
|
terminated(opt(preceded(tag(":"), path)), tag("/}")),
|
||||||
|
))(i)?;
|
||||||
|
|
||||||
Ok((
|
Ok((
|
||||||
i,
|
i,
|
||||||
constructor(NamedBlock {
|
constructor(NamedBlock {
|
||||||
name: name,
|
name: opening_name,
|
||||||
|
explicit_context: maybe_explicit_context,
|
||||||
contents: None,
|
contents: None,
|
||||||
}),
|
}),
|
||||||
))
|
))
|
||||||
@ -1014,6 +1021,7 @@ mod tests {
|
|||||||
"",
|
"",
|
||||||
DustTag::DTBlock(NamedBlock {
|
DustTag::DTBlock(NamedBlock {
|
||||||
name: "foo",
|
name: "foo",
|
||||||
|
explicit_context: None,
|
||||||
contents: None
|
contents: None
|
||||||
})
|
})
|
||||||
))
|
))
|
||||||
@ -1028,6 +1036,49 @@ mod tests {
|
|||||||
"",
|
"",
|
||||||
DustTag::DTBlock(NamedBlock {
|
DustTag::DTBlock(NamedBlock {
|
||||||
name: "foo",
|
name: "foo",
|
||||||
|
explicit_context: None,
|
||||||
|
contents: Some(Body {
|
||||||
|
elements: vec![
|
||||||
|
TemplateElement::TESpan(Span { contents: "hello " }),
|
||||||
|
TemplateElement::TETag(DustTag::DTReference(Reference {
|
||||||
|
path: Path { keys: vec!["name"] },
|
||||||
|
filters: Vec::new()
|
||||||
|
}))
|
||||||
|
]
|
||||||
|
})
|
||||||
|
})
|
||||||
|
))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_self_closing_block_with_explicit_context() {
|
||||||
|
assert_eq!(
|
||||||
|
super::dust_tag("{+foo:bar.baz/}"),
|
||||||
|
Ok((
|
||||||
|
"",
|
||||||
|
DustTag::DTBlock(NamedBlock {
|
||||||
|
name: "foo",
|
||||||
|
explicit_context: Some(Path {
|
||||||
|
keys: vec!["bar", "baz"]
|
||||||
|
}),
|
||||||
|
contents: None
|
||||||
|
})
|
||||||
|
))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_block_with_explicit_context() {
|
||||||
|
assert_eq!(
|
||||||
|
super::dust_tag("{+foo:bar.baz}hello {name}{/foo}"),
|
||||||
|
Ok((
|
||||||
|
"",
|
||||||
|
DustTag::DTBlock(NamedBlock {
|
||||||
|
name: "foo",
|
||||||
|
explicit_context: Some(Path {
|
||||||
|
keys: vec!["bar", "baz"]
|
||||||
|
}),
|
||||||
contents: Some(Body {
|
contents: Some(Body {
|
||||||
elements: vec![
|
elements: vec![
|
||||||
TemplateElement::TESpan(Span { contents: "hello " }),
|
TemplateElement::TESpan(Span { contents: "hello " }),
|
||||||
@ -1050,6 +1101,7 @@ mod tests {
|
|||||||
"",
|
"",
|
||||||
DustTag::DTInlinePartial(NamedBlock {
|
DustTag::DTInlinePartial(NamedBlock {
|
||||||
name: "foo",
|
name: "foo",
|
||||||
|
explicit_context: None,
|
||||||
contents: None
|
contents: None
|
||||||
})
|
})
|
||||||
))
|
))
|
||||||
@ -1064,6 +1116,7 @@ mod tests {
|
|||||||
"",
|
"",
|
||||||
DustTag::DTInlinePartial(NamedBlock {
|
DustTag::DTInlinePartial(NamedBlock {
|
||||||
name: "foo",
|
name: "foo",
|
||||||
|
explicit_context: None,
|
||||||
contents: Some(Body {
|
contents: Some(Body {
|
||||||
elements: vec![
|
elements: vec![
|
||||||
TemplateElement::TESpan(Span { contents: "hello " }),
|
TemplateElement::TESpan(Span { contents: "hello " }),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user