Add parser support for select/any/none.
This commit is contained in:
parent
84c07b262c
commit
a61807d84c
@ -87,14 +87,14 @@ Early termination{~n}
|
|||||||
{/pet_names}
|
{/pet_names}
|
||||||
{/select}{~n}
|
{/select}{~n}
|
||||||
|
|
||||||
Default{~n}
|
Early termination stand-alone comparison{~n}
|
||||||
======={~n}
|
========================================{~n}
|
||||||
{@select key=pet}
|
{@select key=pet}
|
||||||
|
{@eq key="duck" value="duck"}Lets name your pet quackers{~n}{/eq}
|
||||||
|
{@eq value="cat"}Lets name your pet whiskers{~n}{/eq}
|
||||||
{@eq value="dog"}Lets name your pet rover{~n}{/eq}
|
{@eq value="dog"}Lets name your pet rover{~n}{/eq}
|
||||||
{@eq value="lizard"}Lets name your pet dave{~n}{/eq}
|
{@eq value="lizard"}Lets name your pet dave{~n}{/eq}
|
||||||
{@default}Fenton is a good name for any pet{~n}{/default}
|
|
||||||
{@any}{person} has a pet!{~n}{/any}
|
{@any}{person} has a pet!{~n}{/any}
|
||||||
{@none}I don't know what to name {person}'s pet...{~n}{/none}
|
|
||||||
text not inside a comparison{~n}
|
text not inside a comparison{~n}
|
||||||
{#pet_names}
|
{#pet_names}
|
||||||
If your pet was a {type} we'd name it {pet_name}{~n}
|
If your pet was a {type} we'd name it {pet_name}{~n}
|
||||||
|
@ -44,6 +44,9 @@ pub enum DustTag<'a> {
|
|||||||
DTHelperSep(ParameterizedBlock<'a>),
|
DTHelperSep(ParameterizedBlock<'a>),
|
||||||
DTHelperFirst(ParameterizedBlock<'a>),
|
DTHelperFirst(ParameterizedBlock<'a>),
|
||||||
DTHelperLast(ParameterizedBlock<'a>),
|
DTHelperLast(ParameterizedBlock<'a>),
|
||||||
|
DTHelperSelect(ParameterizedBlock<'a>),
|
||||||
|
DTHelperAny(ParameterizedBlock<'a>),
|
||||||
|
DTHelperNone(ParameterizedBlock<'a>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
@ -219,6 +222,15 @@ fn dust_tag(i: &str) -> IResult<&str, DustTag> {
|
|||||||
DustTag::DTInlinePartial,
|
DustTag::DTInlinePartial,
|
||||||
),
|
),
|
||||||
partial("{>", DustTag::DTPartial),
|
partial("{>", DustTag::DTPartial),
|
||||||
|
dust_tag_helper,
|
||||||
|
))(i)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Nom's alt() is limited to 21 possibilities, so I pushed this out
|
||||||
|
/// into its own parser. Otherwise there is no reason for this not to
|
||||||
|
/// be part of the dust_tag parser.
|
||||||
|
fn dust_tag_helper(i: &str) -> IResult<&str, DustTag> {
|
||||||
|
alt((
|
||||||
map(
|
map(
|
||||||
parameterized_block("{@", &tag_to_path("gte")),
|
parameterized_block("{@", &tag_to_path("gte")),
|
||||||
DustTag::DTHelperGreaterThanOrEquals,
|
DustTag::DTHelperGreaterThanOrEquals,
|
||||||
@ -255,6 +267,18 @@ fn dust_tag(i: &str) -> IResult<&str, DustTag> {
|
|||||||
parameterized_block("{@", &tag_to_path("last")),
|
parameterized_block("{@", &tag_to_path("last")),
|
||||||
DustTag::DTHelperLast,
|
DustTag::DTHelperLast,
|
||||||
),
|
),
|
||||||
|
map(
|
||||||
|
parameterized_block("{@", &tag_to_path("select")),
|
||||||
|
DustTag::DTHelperSelect,
|
||||||
|
),
|
||||||
|
map(
|
||||||
|
parameterized_block("{@", &tag_to_path("any")),
|
||||||
|
DustTag::DTHelperAny,
|
||||||
|
),
|
||||||
|
map(
|
||||||
|
parameterized_block("{@", &tag_to_path("none")),
|
||||||
|
DustTag::DTHelperNone,
|
||||||
|
),
|
||||||
))(i)
|
))(i)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,87 +100,18 @@ fn extract_inline_partials_from_tag<'a, 'b>(
|
|||||||
blocks.insert(&named_block.path.keys[0], &named_block.contents);
|
blocks.insert(&named_block.path.keys[0], &named_block.contents);
|
||||||
}
|
}
|
||||||
DustTag::DTBlock(..) => (),
|
DustTag::DTBlock(..) => (),
|
||||||
DustTag::DTHelperEquals(parameterized_block) => {
|
DustTag::DTHelperEquals(parameterized_block)
|
||||||
match ¶meterized_block.contents {
|
| DustTag::DTHelperNotEquals(parameterized_block)
|
||||||
None => (),
|
| DustTag::DTHelperGreaterThan(parameterized_block)
|
||||||
Some(body) => extract_inline_partials_from_body(blocks, &body),
|
| DustTag::DTHelperLessThan(parameterized_block)
|
||||||
};
|
| DustTag::DTHelperGreaterThanOrEquals(parameterized_block)
|
||||||
match ¶meterized_block.else_contents {
|
| DustTag::DTHelperLessThanOrEquals(parameterized_block)
|
||||||
None => (),
|
| DustTag::DTHelperSep(parameterized_block)
|
||||||
Some(body) => extract_inline_partials_from_body(blocks, &body),
|
| DustTag::DTHelperFirst(parameterized_block)
|
||||||
};
|
| DustTag::DTHelperLast(parameterized_block)
|
||||||
}
|
| DustTag::DTHelperSelect(parameterized_block)
|
||||||
DustTag::DTHelperNotEquals(parameterized_block) => {
|
| DustTag::DTHelperAny(parameterized_block)
|
||||||
match ¶meterized_block.contents {
|
| DustTag::DTHelperNone(parameterized_block) => {
|
||||||
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::DTHelperGreaterThan(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::DTHelperLessThan(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::DTHelperGreaterThanOrEquals(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::DTHelperLessThanOrEquals(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::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 {
|
match ¶meterized_block.contents {
|
||||||
None => (),
|
None => (),
|
||||||
Some(body) => extract_inline_partials_from_body(blocks, &body),
|
Some(body) => extract_inline_partials_from_body(blocks, &body),
|
||||||
|
@ -756,6 +756,9 @@ impl<'a> DustRenderer<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
DustTag::DTHelperSelect(parameterized_block) => todo!(),
|
||||||
|
DustTag::DTHelperAny(parameterized_block) => todo!(),
|
||||||
|
DustTag::DTHelperNone(parameterized_block) => todo!(),
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok("".to_owned())
|
Ok("".to_owned())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user