First attempt at fixing by reading all indirect references containing a reference to a single value as the original value is a failure. Turns out the @size helper treats numeric types in indirect references differently.

This commit is contained in:
Tom Alexander 2020-06-14 14:51:31 -04:00
parent 716a110d2e
commit e70f397545
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
2 changed files with 34 additions and 0 deletions

View File

@ -1,3 +1,10 @@
The size of val ({val|js|s}) is {@size key=val /}{~n}
The size of "{~lb}val{~rb}" is {@size key="{val}" /}{~n}
{#val foo="{val}"}
The size of foo ({foo|js|s}) is {@size key=foo /}{~n}
The size of "{~lb}foo{~rb}" is {@size key="{foo}" /}{~n}
{:else}
The size of foo ({foo|js|s}) is {@size key=foo /}{~n}
The size of "{~lb}foo{~rb}" is {@size key="{foo}" /}{~n}
{/val}
The size with no key is {@size /}{~n}

View File

@ -1,6 +1,7 @@
use crate::parser::Filter;
use crate::parser::KVPair;
use crate::parser::OwnedLiteral;
use crate::parser::PartialNameElement;
use crate::parser::RValue;
use crate::renderer::breadcrumb_tree::BreadcrumbTreeElement;
use crate::renderer::context_element::CompareContextElement;
@ -140,6 +141,32 @@ impl<'a> IntoContextElement for RValue<'a> {
.map(|ice| ice.into_context_element(renderer, breadcrumbs))
.ok()
.flatten(),
// Special case: if the template is only a reference to a
// single variable without any additional text, then
// simply resolve that variable.
//
// TODO: What if the reference has filters?
// RValue::RVTemplate(template)
// if template.len() == 1
// && template.iter().all(|pne| match pne {
// PartialNameElement::PNReference { .. } => true,
// PartialNameElement::PNSpan { .. } => false,
// }) =>
// {
// let path = match template
// .first()
// .expect("Match guard proves theres one element")
// {
// PartialNameElement::PNReference { path, .. } => path,
// PartialNameElement::PNSpan { .. } => {
// panic!("Match guard prevents spans from hitting this code")
// }
// };
// walk_path(breadcrumbs, &path)
// .map(|ice| ice.into_context_element(renderer, breadcrumbs))
// .ok()
// .flatten()
// }
RValue::RVTemplate(template) => renderer
.render_partial_name(template, breadcrumbs)
.map(|rendered| OwnedLiteral::LString(rendered))