Renamed the new partial implementation to the old partial name.

This commit is contained in:
Tom Alexander 2020-05-17 21:17:34 -04:00
parent 7be00ffea6
commit 93f9581d8a
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
3 changed files with 24 additions and 24 deletions

View File

@ -33,7 +33,7 @@ pub enum DustTag<'a> {
DTNotExists(Container<'a>),
DTBlock(NamedBlock<'a>),
DTInlinePartial(NamedBlock<'a>),
DTNewPartial(NewPartial<'a>),
DTPartial(Partial<'a>),
DTHelperEquals(ParameterizedBlock<'a>),
DTHelperNotEquals(ParameterizedBlock<'a>),
DTHelperGreaterThan(ParameterizedBlock<'a>),
@ -113,7 +113,7 @@ pub struct ParameterizedBlock<'a> {
}
#[derive(Clone, Debug, PartialEq)]
pub struct NewPartial<'a> {
pub struct Partial<'a> {
pub name: Vec<PartialNameElement>,
pub params: Vec<KVPair<'a>>,
}
@ -217,7 +217,7 @@ fn dust_tag(i: &str) -> IResult<&str, DustTag> {
conditional("{^", DustTag::DTNotExists),
named_block("{+", DustTag::DTBlock),
named_block("{<", DustTag::DTInlinePartial),
new_partial("{>", DustTag::DTNewPartial),
partial("{>", DustTag::DTPartial),
parameterized_block("{@", "gte", DustTag::DTHelperGreaterThanOrEquals),
parameterized_block("{@", "lte", DustTag::DTHelperLessThanOrEquals),
parameterized_block("{@", "eq", DustTag::DTHelperEquals),
@ -518,9 +518,9 @@ where
}
}
fn new_partial_with_plain_tag<'a>(
fn partial_with_plain_tag<'a>(
open_matcher: &'static str,
) -> impl Fn(&'a str) -> IResult<&'a str, NewPartial<'a>> {
) -> impl Fn(&'a str) -> IResult<&'a str, Partial<'a>> {
move |i: &'a str| {
let (i, (name, params)) = delimited(
tag(open_matcher),
@ -537,7 +537,7 @@ fn new_partial_with_plain_tag<'a>(
Ok((
i,
NewPartial {
Partial {
name: vec![PartialNameElement::PNSpan {
contents: name.to_owned(),
}],
@ -547,7 +547,7 @@ fn new_partial_with_plain_tag<'a>(
}
}
fn new_partial_quoted_tag(i: &str) -> IResult<&str, Vec<TemplateElement>> {
fn partial_quoted_tag(i: &str) -> IResult<&str, Vec<TemplateElement>> {
// TODO: make all consuming
many1(alt((
map(span, TemplateElement::TESpan),
@ -555,15 +555,15 @@ fn new_partial_quoted_tag(i: &str) -> IResult<&str, Vec<TemplateElement>> {
)))(i)
}
fn new_partial_with_quoted_tag<'a>(
fn partial_with_quoted_tag<'a>(
open_matcher: &'static str,
) -> impl Fn(&'a str) -> IResult<&'a str, NewPartial<'a>> {
) -> impl Fn(&'a str) -> IResult<&'a str, Partial<'a>> {
move |i: &'a str| {
let (i, (name, params)) = delimited(
tag(open_matcher),
tuple((
verify(quoted_string, |s: &String| {
new_partial_quoted_tag(s.as_str()).is_ok()
partial_quoted_tag(s.as_str()).is_ok()
}),
opt(delimited(
space1,
@ -574,7 +574,7 @@ fn new_partial_with_quoted_tag<'a>(
tag("/}"),
)(i)?;
let (_remaining, template_name_elements) = new_partial_quoted_tag(name.as_str())
let (_remaining, template_name_elements) = partial_quoted_tag(name.as_str())
.expect("A successful parse was verified earlier with a call to verify()");
let partial_name_elements = template_name_elements
.into_iter()
@ -583,7 +583,7 @@ fn new_partial_with_quoted_tag<'a>(
Ok((
i,
NewPartial {
Partial {
name: partial_name_elements,
params: params.unwrap_or(Vec::new()),
},
@ -591,15 +591,15 @@ fn new_partial_with_quoted_tag<'a>(
}
}
fn new_partial<'a, F>(
fn partial<'a, F>(
open_matcher: &'static str,
constructor: F,
) -> impl Fn(&'a str) -> IResult<&'a str, DustTag<'a>>
where
F: Fn(NewPartial<'a>) -> DustTag<'a>,
F: Fn(Partial<'a>) -> DustTag<'a>,
{
let plain = new_partial_with_plain_tag(open_matcher);
let quoted = new_partial_with_quoted_tag(open_matcher);
let plain = partial_with_plain_tag(open_matcher);
let quoted = partial_with_quoted_tag(open_matcher);
move |i: &'a str| map(alt((&plain, &quoted)), &constructor)(i)
}
@ -1016,7 +1016,7 @@ mod tests {
dust_tag(r#"{>foo bar=baz animal="cat"/}"#),
Ok((
"",
DustTag::DTNewPartial(NewPartial {
DustTag::DTPartial(Partial {
name: vec![PartialNameElement::PNSpan {
contents: "foo".to_owned()
},],
@ -1042,7 +1042,7 @@ mod tests {
dust_tag(r#"{>"template name * with * special \" characters" bar=baz animal="cat"/}"#),
Ok((
"",
DustTag::DTNewPartial(NewPartial {
DustTag::DTPartial(Partial {
name: vec![PartialNameElement::PNSpan {
contents: r#"template name * with * special " characters"#.to_owned()
},],
@ -1067,7 +1067,7 @@ mod tests {
dust_tag(r#"{>"dynamic{ref}template" bar=baz animal="cat"/}"#),
Ok((
"",
DustTag::DTNewPartial(NewPartial {
DustTag::DTPartial(Partial {
name: vec![
PartialNameElement::PNSpan {
contents: "dynamic".to_owned()
@ -1101,7 +1101,7 @@ mod tests {
dust_tag(r#"{>foo a="foo" b=179/}"#),
Ok((
"",
DustTag::DTNewPartial(NewPartial {
DustTag::DTPartial(Partial {
name: vec![PartialNameElement::PNSpan {
contents: "foo".to_owned()
},],
@ -1271,8 +1271,8 @@ mod tests {
keys: vec!["level3", "level4"]
},
contents: Some(Body {
elements: vec![TemplateElement::TETag(DustTag::DTNewPartial(
NewPartial {
elements: vec![TemplateElement::TETag(DustTag::DTPartial(
Partial {
name: vec![PartialNameElement::PNSpan {
contents: "partialtwo".to_owned()
},],

View File

@ -94,7 +94,7 @@ fn extract_inline_partials_from_tag<'a, 'b>(
Some(body) => extract_inline_partials_from_body(blocks, &body),
};
}
DustTag::DTNewPartial(..) => (),
DustTag::DTPartial(..) => (),
DustTag::DTInlinePartial(named_block) => {
blocks.insert(&named_block.name, &named_block.contents);
}

View File

@ -203,7 +203,7 @@ impl<'a> DustRenderer<'a> {
self.render_maybe_body(&container.contents, breadcrumbs, blocks)
};
}
DustTag::DTNewPartial(partial) => {
DustTag::DTPartial(partial) => {
let partial_name = self.render_partial_name(&partial.name, breadcrumbs, blocks)?;
if partial.params.is_empty() {
let rendered_content =