Attempted to move section over to the section-specific new breadcrumbs function.
I think the problem is, the index context needs to be a higher priority than the new context element, but when referencing data with `{.}` the new context element needs to take priority. I could either combine entries in the context tree so that variables like $idx and $len live side-by-side with real context elements, or try to implement a way to skip over index context elements when walking up the tree.
This commit is contained in:
parent
79f52ecdee
commit
f04e84dc31
@ -327,6 +327,22 @@ Section vs Partial priority{~n}
|
|||||||
{/some_global}
|
{/some_global}
|
||||||
{>priority:explicit pet="snake"/}
|
{>priority:explicit pet="snake"/}
|
||||||
|
|
||||||
|
Section vs Exists priority{~n}
|
||||||
|
=========================={~n}
|
||||||
|
{?some_global:explicit pet="snake"}
|
||||||
|
{pet}{~n}
|
||||||
|
{/some_global}
|
||||||
|
{>priority:explicit pet="snake"/}
|
||||||
|
|
||||||
|
Section vs NotExists priority{~n}
|
||||||
|
=========================={~n}
|
||||||
|
{^some_global:explicit pet="snake"}
|
||||||
|
MAIN {pet}{~n}
|
||||||
|
{:else}
|
||||||
|
ELSE {pet}{~n}
|
||||||
|
{/some_global}
|
||||||
|
{>priority:explicit pet="snake"/}
|
||||||
|
|
||||||
Section vs Partial priority Failed Walk{~n}
|
Section vs Partial priority Failed Walk{~n}
|
||||||
======================================={~n}
|
======================================={~n}
|
||||||
{#doesnotexist:explicit pet="snake"}
|
{#doesnotexist:explicit pet="snake"}
|
||||||
|
@ -165,13 +165,14 @@ impl<'a> DustRenderer<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
DustTag::DTSection(container) => {
|
DustTag::DTSection(container) => {
|
||||||
|
let injected_context = ParametersContext::new(breadcrumbs, &container.params);
|
||||||
let val = walk_path(breadcrumbs, &container.path.keys);
|
let val = walk_path(breadcrumbs, &container.path.keys);
|
||||||
match val {
|
match val {
|
||||||
Err(WalkError::CantWalk) => {
|
Err(WalkError::CantWalk) => {
|
||||||
let new_breadcrumbs = Self::new_breadcrumbs(
|
let new_breadcrumbs = Self::new_breadcrumbs_section(
|
||||||
breadcrumbs,
|
|
||||||
breadcrumbs,
|
breadcrumbs,
|
||||||
None,
|
None,
|
||||||
|
Some(&injected_context),
|
||||||
&container.explicit_context,
|
&container.explicit_context,
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
@ -194,10 +195,10 @@ impl<'a> DustRenderer<'a> {
|
|||||||
final_val.get_loop_elements();
|
final_val.get_loop_elements();
|
||||||
if loop_elements.is_empty() {
|
if loop_elements.is_empty() {
|
||||||
// Scalar value
|
// Scalar value
|
||||||
let new_breadcrumbs = Self::new_breadcrumbs(
|
let new_breadcrumbs = Self::new_breadcrumbs_section(
|
||||||
breadcrumbs,
|
|
||||||
breadcrumbs,
|
breadcrumbs,
|
||||||
None,
|
None,
|
||||||
|
Some(&injected_context),
|
||||||
&container.explicit_context,
|
&container.explicit_context,
|
||||||
Some(final_val),
|
Some(final_val),
|
||||||
);
|
);
|
||||||
@ -214,11 +215,12 @@ impl<'a> DustRenderer<'a> {
|
|||||||
.into_iter()
|
.into_iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(i, array_elem)| {
|
.map(|(i, array_elem)| {
|
||||||
let injected_context =
|
let index_context =
|
||||||
IterationContext::new(i, total_length);
|
IterationContext::new(i, total_length);
|
||||||
let new_breadcrumbs = Self::new_breadcrumbs(
|
let new_breadcrumbs =
|
||||||
breadcrumbs,
|
Self::new_breadcrumbs_section(
|
||||||
breadcrumbs,
|
breadcrumbs,
|
||||||
|
Some(&index_context),
|
||||||
Some(&injected_context),
|
Some(&injected_context),
|
||||||
&container.explicit_context,
|
&container.explicit_context,
|
||||||
Some(array_elem),
|
Some(array_elem),
|
||||||
@ -242,10 +244,10 @@ impl<'a> DustRenderer<'a> {
|
|||||||
// an empty array or null), Dust uses the
|
// an empty array or null), Dust uses the
|
||||||
// original context before walking the path as
|
// original context before walking the path as
|
||||||
// the context for rendering the else block
|
// the context for rendering the else block
|
||||||
let new_breadcrumbs = Self::new_breadcrumbs(
|
let new_breadcrumbs = Self::new_breadcrumbs_section(
|
||||||
breadcrumbs,
|
|
||||||
breadcrumbs,
|
breadcrumbs,
|
||||||
None,
|
None,
|
||||||
|
Some(&injected_context),
|
||||||
&container.explicit_context,
|
&container.explicit_context,
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
@ -259,12 +261,11 @@ impl<'a> DustRenderer<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
DustTag::DTExists(container) => {
|
DustTag::DTExists(container) => {
|
||||||
let new_breadcrumbs = Self::new_breadcrumbs(
|
let new_breadcrumbs = Self::new_breadcrumbs_partial(
|
||||||
breadcrumbs,
|
breadcrumbs,
|
||||||
breadcrumbs,
|
breadcrumbs,
|
||||||
None,
|
None,
|
||||||
&container.explicit_context,
|
&container.explicit_context,
|
||||||
None,
|
|
||||||
);
|
);
|
||||||
let val = walk_path(breadcrumbs, &container.path.keys);
|
let val = walk_path(breadcrumbs, &container.path.keys);
|
||||||
return if val.map(|v| v.is_truthy()).unwrap_or(false) {
|
return if val.map(|v| v.is_truthy()).unwrap_or(false) {
|
||||||
@ -282,12 +283,11 @@ impl<'a> DustRenderer<'a> {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
DustTag::DTNotExists(container) => {
|
DustTag::DTNotExists(container) => {
|
||||||
let new_breadcrumbs = Self::new_breadcrumbs(
|
let new_breadcrumbs = Self::new_breadcrumbs_partial(
|
||||||
breadcrumbs,
|
breadcrumbs,
|
||||||
breadcrumbs,
|
breadcrumbs,
|
||||||
None,
|
None,
|
||||||
&container.explicit_context,
|
&container.explicit_context,
|
||||||
None,
|
|
||||||
);
|
);
|
||||||
let val = walk_path(breadcrumbs, &container.path.keys);
|
let val = walk_path(breadcrumbs, &container.path.keys);
|
||||||
return if !val.map(|v| v.is_truthy()).unwrap_or(false) {
|
return if !val.map(|v| v.is_truthy()).unwrap_or(false) {
|
||||||
@ -307,12 +307,11 @@ impl<'a> DustRenderer<'a> {
|
|||||||
DustTag::DTPartial(partial) => {
|
DustTag::DTPartial(partial) => {
|
||||||
let partial_name = self.render_partial_name(&partial.name, breadcrumbs, blocks)?;
|
let partial_name = self.render_partial_name(&partial.name, breadcrumbs, blocks)?;
|
||||||
if partial.params.is_empty() {
|
if partial.params.is_empty() {
|
||||||
let new_breadcrumbs = Self::new_breadcrumbs(
|
let new_breadcrumbs = Self::new_breadcrumbs_partial(
|
||||||
breadcrumbs,
|
breadcrumbs,
|
||||||
breadcrumbs,
|
breadcrumbs,
|
||||||
None,
|
None,
|
||||||
&partial.explicit_context,
|
&partial.explicit_context,
|
||||||
None,
|
|
||||||
);
|
);
|
||||||
let rendered_content = self.render_template(
|
let rendered_content = self.render_template(
|
||||||
&partial_name,
|
&partial_name,
|
||||||
@ -322,12 +321,11 @@ impl<'a> DustRenderer<'a> {
|
|||||||
return Ok(rendered_content);
|
return Ok(rendered_content);
|
||||||
} else {
|
} else {
|
||||||
let injected_context = ParametersContext::new(breadcrumbs, &partial.params);
|
let injected_context = ParametersContext::new(breadcrumbs, &partial.params);
|
||||||
let new_breadcrumbs = Self::new_breadcrumbs(
|
let new_breadcrumbs = Self::new_breadcrumbs_partial(
|
||||||
breadcrumbs,
|
breadcrumbs,
|
||||||
breadcrumbs,
|
breadcrumbs,
|
||||||
Some(&injected_context),
|
Some(&injected_context),
|
||||||
&partial.explicit_context,
|
&partial.explicit_context,
|
||||||
None,
|
|
||||||
);
|
);
|
||||||
let rendered_content = self.render_template(
|
let rendered_content = self.render_template(
|
||||||
&partial_name,
|
&partial_name,
|
||||||
@ -342,12 +340,11 @@ impl<'a> DustRenderer<'a> {
|
|||||||
return Ok("".to_owned());
|
return Ok("".to_owned());
|
||||||
}
|
}
|
||||||
DustTag::DTBlock(named_block) => {
|
DustTag::DTBlock(named_block) => {
|
||||||
let new_breadcrumbs = Self::new_breadcrumbs(
|
let new_breadcrumbs = Self::new_breadcrumbs_partial(
|
||||||
breadcrumbs,
|
breadcrumbs,
|
||||||
blocks.breadcrumbs,
|
blocks.breadcrumbs,
|
||||||
None,
|
None,
|
||||||
&named_block.explicit_context,
|
&named_block.explicit_context,
|
||||||
None,
|
|
||||||
);
|
);
|
||||||
return match blocks.blocks.get_block(named_block.name) {
|
return match blocks.blocks.get_block(named_block.name) {
|
||||||
None => self.render_maybe_body(
|
None => self.render_maybe_body(
|
||||||
@ -363,12 +360,11 @@ impl<'a> DustRenderer<'a> {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
DustTag::DTHelperEquals(parameterized_block) => {
|
DustTag::DTHelperEquals(parameterized_block) => {
|
||||||
let new_breadcrumbs = Self::new_breadcrumbs(
|
let new_breadcrumbs = Self::new_breadcrumbs_partial(
|
||||||
breadcrumbs,
|
breadcrumbs,
|
||||||
breadcrumbs,
|
breadcrumbs,
|
||||||
None,
|
None,
|
||||||
¶meterized_block.explicit_context,
|
¶meterized_block.explicit_context,
|
||||||
None,
|
|
||||||
);
|
);
|
||||||
let param_map: HashMap<&str, &RValue<'a>> =
|
let param_map: HashMap<&str, &RValue<'a>> =
|
||||||
Self::get_rval_map(¶meterized_block.params);
|
Self::get_rval_map(¶meterized_block.params);
|
||||||
@ -414,12 +410,11 @@ impl<'a> DustRenderer<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
DustTag::DTHelperNotEquals(parameterized_block) => {
|
DustTag::DTHelperNotEquals(parameterized_block) => {
|
||||||
let new_breadcrumbs = Self::new_breadcrumbs(
|
let new_breadcrumbs = Self::new_breadcrumbs_partial(
|
||||||
breadcrumbs,
|
breadcrumbs,
|
||||||
breadcrumbs,
|
breadcrumbs,
|
||||||
None,
|
None,
|
||||||
¶meterized_block.explicit_context,
|
¶meterized_block.explicit_context,
|
||||||
None,
|
|
||||||
);
|
);
|
||||||
let param_map: HashMap<&str, &RValue<'a>> =
|
let param_map: HashMap<&str, &RValue<'a>> =
|
||||||
Self::get_rval_map(¶meterized_block.params);
|
Self::get_rval_map(¶meterized_block.params);
|
||||||
@ -464,12 +459,11 @@ impl<'a> DustRenderer<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
DustTag::DTHelperGreaterThan(parameterized_block) => {
|
DustTag::DTHelperGreaterThan(parameterized_block) => {
|
||||||
let new_breadcrumbs = Self::new_breadcrumbs(
|
let new_breadcrumbs = Self::new_breadcrumbs_partial(
|
||||||
breadcrumbs,
|
breadcrumbs,
|
||||||
breadcrumbs,
|
breadcrumbs,
|
||||||
None,
|
None,
|
||||||
¶meterized_block.explicit_context,
|
¶meterized_block.explicit_context,
|
||||||
None,
|
|
||||||
);
|
);
|
||||||
let param_map: HashMap<&str, &RValue<'a>> =
|
let param_map: HashMap<&str, &RValue<'a>> =
|
||||||
Self::get_rval_map(¶meterized_block.params);
|
Self::get_rval_map(¶meterized_block.params);
|
||||||
@ -507,12 +501,11 @@ impl<'a> DustRenderer<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
DustTag::DTHelperGreaterThanOrEquals(parameterized_block) => {
|
DustTag::DTHelperGreaterThanOrEquals(parameterized_block) => {
|
||||||
let new_breadcrumbs = Self::new_breadcrumbs(
|
let new_breadcrumbs = Self::new_breadcrumbs_partial(
|
||||||
breadcrumbs,
|
breadcrumbs,
|
||||||
breadcrumbs,
|
breadcrumbs,
|
||||||
None,
|
None,
|
||||||
¶meterized_block.explicit_context,
|
¶meterized_block.explicit_context,
|
||||||
None,
|
|
||||||
);
|
);
|
||||||
let param_map: HashMap<&str, &RValue<'a>> =
|
let param_map: HashMap<&str, &RValue<'a>> =
|
||||||
Self::get_rval_map(¶meterized_block.params);
|
Self::get_rval_map(¶meterized_block.params);
|
||||||
@ -550,12 +543,11 @@ impl<'a> DustRenderer<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
DustTag::DTHelperLessThan(parameterized_block) => {
|
DustTag::DTHelperLessThan(parameterized_block) => {
|
||||||
let new_breadcrumbs = Self::new_breadcrumbs(
|
let new_breadcrumbs = Self::new_breadcrumbs_partial(
|
||||||
breadcrumbs,
|
breadcrumbs,
|
||||||
breadcrumbs,
|
breadcrumbs,
|
||||||
None,
|
None,
|
||||||
¶meterized_block.explicit_context,
|
¶meterized_block.explicit_context,
|
||||||
None,
|
|
||||||
);
|
);
|
||||||
let param_map: HashMap<&str, &RValue<'a>> =
|
let param_map: HashMap<&str, &RValue<'a>> =
|
||||||
Self::get_rval_map(¶meterized_block.params);
|
Self::get_rval_map(¶meterized_block.params);
|
||||||
@ -593,12 +585,11 @@ impl<'a> DustRenderer<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
DustTag::DTHelperLessThanOrEquals(parameterized_block) => {
|
DustTag::DTHelperLessThanOrEquals(parameterized_block) => {
|
||||||
let new_breadcrumbs = Self::new_breadcrumbs(
|
let new_breadcrumbs = Self::new_breadcrumbs_partial(
|
||||||
breadcrumbs,
|
breadcrumbs,
|
||||||
breadcrumbs,
|
breadcrumbs,
|
||||||
None,
|
None,
|
||||||
¶meterized_block.explicit_context,
|
¶meterized_block.explicit_context,
|
||||||
None,
|
|
||||||
);
|
);
|
||||||
let param_map: HashMap<&str, &RValue<'a>> =
|
let param_map: HashMap<&str, &RValue<'a>> =
|
||||||
Self::get_rval_map(¶meterized_block.params);
|
Self::get_rval_map(¶meterized_block.params);
|
||||||
@ -744,7 +735,7 @@ impl<'a> DustRenderer<'a> {
|
|||||||
/// explicit_context
|
/// explicit_context
|
||||||
/// new_context_element
|
/// new_context_element
|
||||||
/// ```
|
/// ```
|
||||||
fn new_breadcrumbs<'b>(
|
fn new_breadcrumbs_deprecated<'b>(
|
||||||
breadcrumbs: &'b Vec<&'b dyn ContextElement>,
|
breadcrumbs: &'b Vec<&'b dyn ContextElement>,
|
||||||
explicit_context_breadcrumbs: &'b Vec<&'b dyn ContextElement>,
|
explicit_context_breadcrumbs: &'b Vec<&'b dyn ContextElement>,
|
||||||
injected_context: Option<&'b dyn ContextElement>,
|
injected_context: Option<&'b dyn ContextElement>,
|
||||||
|
Loading…
Reference in New Issue
Block a user