Merge branch 'literal_string_block' into render

This commit is contained in:
Tom Alexander 2020-05-23 23:47:32 -04:00
commit 6c89f7c59a
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
5 changed files with 14 additions and 0 deletions

View File

@ -0,0 +1 @@
{"name": "Bob"}

View File

@ -0,0 +1,5 @@
{`
This block is supposed
to preserve {name} all
newlines, whitespace, and braces
`}

View File

@ -27,6 +27,7 @@ use nom::IResult;
pub enum DustTag<'a> { pub enum DustTag<'a> {
DTSpecial(Special), DTSpecial(Special),
DTComment(Comment<'a>), DTComment(Comment<'a>),
DTLiteralStringBlock(&'a str),
DTReference(Reference<'a>), DTReference(Reference<'a>),
DTSection(Container<'a>), DTSection(Container<'a>),
DTExists(Container<'a>), DTExists(Container<'a>),
@ -211,6 +212,7 @@ fn dust_tag(i: &str) -> IResult<&str, DustTag> {
alt(( alt((
map(special, DustTag::DTSpecial), map(special, DustTag::DTSpecial),
map(comment, DustTag::DTComment), map(comment, DustTag::DTComment),
map(literal_string_block, DustTag::DTLiteralStringBlock),
map(reference, DustTag::DTReference), map(reference, DustTag::DTReference),
conditional("{#", DustTag::DTSection), conditional("{#", DustTag::DTSection),
conditional("{?", DustTag::DTExists), conditional("{?", DustTag::DTExists),
@ -634,6 +636,10 @@ fn ignore_new_line_leading_whitespace(i: &str) -> IResult<&str, IgnoredWhitespac
)(i) )(i)
} }
fn literal_string_block(i: &str) -> IResult<&str, &str> {
delimited(tag("{`"), take_until("`}"), tag("`}"))(i)
}
/// Any text that is not a Dust element or ignored whitespace /// Any text that is not a Dust element or ignored whitespace
fn span(i: &str) -> IResult<&str, Span> { fn span(i: &str) -> IResult<&str, Span> {
let (remaining, line) = verify( let (remaining, line) = verify(

View File

@ -63,6 +63,7 @@ fn extract_inline_partials_from_tag<'a, 'b>(
match tag { match tag {
DustTag::DTComment(..) => (), DustTag::DTComment(..) => (),
DustTag::DTSpecial(..) => (), DustTag::DTSpecial(..) => (),
DustTag::DTLiteralStringBlock(..) => (),
DustTag::DTReference(..) => (), DustTag::DTReference(..) => (),
DustTag::DTSection(container) => { DustTag::DTSection(container) => {
match &container.contents { match &container.contents {

View File

@ -144,6 +144,7 @@ impl<'a> DustRenderer<'a> {
} }
.to_owned()) .to_owned())
} }
DustTag::DTLiteralStringBlock(literal) => return Ok((*literal).to_owned()),
DustTag::DTReference(reference) => { DustTag::DTReference(reference) => {
let val = walk_path(breadcrumbs, &reference.path.keys); let val = walk_path(breadcrumbs, &reference.path.keys);
match val { match val {