$idx and $len do not survive through an explicit context setting, which will work perfectly with my injected-context architecture.
You can use $idx and $len as your explicit context, but as scalar values I do not think there is a way to access them anyway.
Exists and Not-Exists
=====================
Looks like you can exlicitly set a context with exists and not-exists tags too. This works out well in the parser because I am using the same code for those blocks.
Partials
--------
Explicitly setting a context in a partial also works. The explicit context takes priority over the parameters in the partial tag.
This works for both regular named partials and quoted partials.
While normally parameters are injected 1 level above the current context, if both parameters and explicit are set, they are injected below the current context. So if the context tree was `1->2->3`, with just parameters you'd have `1->2->parameters->3` but with an explicit context you have `parameters->explicit`.
Helpers
-------
Explicitly setting a context in a helper works too.
Blocks and Inline Partials
--------------------------
Explicitly setting a context on an inline partial does not work, but it does not error out either, so I need to add support for this in the parser.
Explicitly setting a context on a block does work.
The explicit context for blocks is evaluated in the context for that template file containing the block, not the inline partial (so, whatever the context is when we invoke the partial containing the block).
References
----------
Explicitly setting a context does not work on a reference, but it has revealed that invalid dust is rendered verbatim. I'm going to leave that commented out until I can address that in a later branch.
Paths
-----
Explicit contexts do support deep paths.
Else Blocks
-----------
Else blocks also use an explicit context.
Complete Failure
----------------
If the walk destination does not exist, and the explicit context does not exist, then you end up with absolutely no context.
Regular Path Failure
--------------------
If the regular path fails but the explicit path succeeds then the context is set to the explicit path.
Falsey Explicit Path
--------------------
Since dust would not walk to a falsey path, theres no difference between a falsey path and a non-existent path.
{! First we do it without explicit context setting which results in being able to read some_global but not pet !}
Section Regular{~n}
==============={~n}
{#loop}
{#person}
{$idx}: {name} has a pet {pet} but not a {some_global}{~n}
{/person}
{/loop}
{! Then we do it with explicit context setting which should result in being able ot read pet but not some_global !}
Section Explicit{~n}
================{~n}
{#loop}
{#person:explicit}
{$idx}: {name} has a pet {pet} but not a {some_global}{~n}
{/person}
{/loop}
{! What happens if we try to use an explicit context with an exists block instead of a section !}
Exists Regular{~n}
=============={~n}
{#loop}
{?person}
{$idx}: {person.name} has a pet {pet} but not a {some_global}{~n}
{/person}
{/loop}
Exists Explicit{~n}
==============={~n}
{#loop}
{?person:explicit}
{$idx}: {person.name} has a pet {pet} but not a {some_global}{~n}
{/person}
{/loop}
{! Can you explicitly set the context for a partial? !}
Partial Regular{~n}
==============={~n}
{#loop}
{>other/}
{/loop}
Partial Explicit{~n}
================{~n}
{#loop}
{>other:explicit/}
{/loop}
Quoted Partial Explicit{~n}
======================={~n}
{#loop}
{>"other":explicit/}
{/loop}
Partial Regular with parameters{~n}
==============================={~n}
{#loop}
{>other pet="rabbit"/}
{/loop}
Partial Explicit with parameters{~n}
================================{~n}
{#loop}
{>other:explicit pet="rabbit"/}
{/loop}
{! Can you explicitly set the context for a helper? !}
Helper Regular{~n}
=============={~n}
{#loop}
{@eq key="foo" value="foo"}
{$idx}: {person.name} has a pet {pet} but not a {some_global}{~n}
{/eq}
{/loop}
Helper Explicit{~n}
==============={~n}
{#loop}
{@eq:explicit key="foo" value="foo"}
{$idx}: {person.name} has a pet {pet} but not a {some_global}{~n}
{/eq}
{/loop}
{! Can you explicitly set the context for inline partials or blocks? !}
Block Regular{~n}
============={~n}
{#loop}
{>default/}
{/loop}
Inline Partial Regular{~n}
======================{~n}
{#loop}
{>override/}
{/loop}
Block Explicit{~n}
=============={~n}
{#loop}
{>default_explicit/}
{/loop}
Inline Partial Explicit{~n}
======================={~n}
{#loop}
{>override_explicit/}
{/loop}
Inline Partial and Block Explicit{~n}
================================={~n}
{#loop}
{>override_double_explicit/}
{/loop}
{! Can you explicitly set the context for references? !}
{! Commented out until I add support for rendering invalid dust verbatim
Reference Regular{~n}
================={~n}
{.}{~n}
Reference Explicit{~n}
=================={~n}
{.:some_global}{~n}
!}
{! Can you explicitly set the context with a path? !}
Path Regular{~n}
============{~n}
{#loop}
{#person}
{$idx}: {name} has a pet {pet} but not a {some_global}{~n}
{/person}
{/loop}
Path Explicit{~n}
============={~n}
{#loop}
{#person:deep_explicit.explicit}
{$idx}: {name} has a pet {pet} but not a {some_global}{~n}
{/person}
{/loop}
{! Can you explicitly set the context to a variable? !}
Variable Regular{~n}
================{~n}
{#loop}
{#person}
{$idx}: {name} has a pet {pet} but not a {some_global}{~n}
{/person}
{/loop}
Variable Explicit{~n}
================={~n}
{#loop}
{#person:$idx}
{$idx}: {name} has a pet {pet} but not a {some_global}{~n}
{/person}
{/loop}
{! What context is set on else blocks? !}
Else Block Regular{~n}
=================={~n}
{#loop}
{#empty_array}
MAIN {$idx}: {name} has a pet {pet} but not a {some_global}{~n}
{:else}
ELSE {$idx}: {name} has a pet {pet} but not a {some_global}{~n}
{/empty_array}
{/loop}
Else Block Explicit{~n}
==================={~n}
{#loop}
{#empty_array:explicit}
MAIN {$idx}: {person.name} has a pet {pet} but not a {some_global}{~n}
{:else}
ELSE {$idx}: {person.name} has a pet {pet} but not a {some_global}{~n}
{/empty_array}
{/loop}
{! What context is set when the explicit context path does not exist? !}
Failed Explicit Regular{~n}
======================={~n}
{#loop}
{#person}
{$idx}: {name} has a pet {pet} but not a {some_global}{~n}
{/person}
{/loop}
Failed Explicit Explicit{~n}
========================{~n}
{#loop}
{#person:foobar}
{$idx}: {name} has a pet {pet} but not a {some_global}{~n}
{/person}
{/loop}
{! What context is set when the regular path and explicit context path does not exist? !}
Failed Everything Regular{~n}
========================={~n}
BEFORE {.|js}{~n}
{#foo}
MAIN {.|js}{~n}
{:else}
ELSE {.|js}{~n}
{/foo}
Failed Everything Explicit{~n}
=========================={~n}
{#foo:bar}
MAIN {.|js}{~n}
{:else}
ELSE {.|js}{~n}
{/foo}
{! What context is set when the regular context path does not exist? !}
Failed Regular Path Regular{~n}
==========================={~n}
{#loop}
{#foo}
MAIN {$idx}: {name} has a pet {pet} but not a {some_global}{~n}
{:else}
ELSE {$idx}: {name} has a pet {pet} but not a {some_global}{~n}
{/foo}
{/loop}
Failed Regular Path Explicit{~n}
============================{~n}
{#loop}
{#foo:explicit}
MAIN {$idx}: {name} has a pet {pet} but not a {some_global}{~n}
{:else}
ELSE {$idx}: {name} has a pet {pet} but not a {some_global}{~n}
{/foo}
{/loop}
{! What context is set when the explicit path is falsey? !}
Falsey Explicit Path Regular{~n}
============================{~n}
{#loop}
{#foo}
MAIN {$idx}: {name} has a pet {pet} but not a {some_global}{~n}
{:else}
ELSE {$idx}: {name} has a pet {pet} but not a {some_global}{~n}
{/foo}
{/loop}
Falsey Explicit Path Explicit{~n}
============================={~n}
{#loop}
{#foo:empty_array}
MAIN {$idx}: {name} has a pet {pet} but not a {some_global}{~n}
{:else}
ELSE {$idx}: {name} has a pet {pet} but not a {some_global}{~n}
{.|js}{~n}
{/foo}
{/loop}
{! Since partial parameters are normally injected 1 level above the current context, and explicit contexts are below the partial parameters, is the order parameters->current_context->explicit or current_context->parameters->explicit when both are being used? !}
{! Is an explicit context on an inline partial evaluated in the context of the block or the context of the inline partial? !}
Explicit Evaluation Time Global{~n}
==============================={~n}
{>explicit_evaluation_time/}
Explicit Evaluation Time Partial Context{~n}
========================================{~n}
{#partial_context}
{>explicit_evaluation_time/}
{/partial_context}
{! The previous test discovered that the inline partial's explicit context is evaluated based on the context when invoking the full-blown partial, HOWEVER, it shared the same partial context for both the block and the inline partial. To conclusively prove if the explicit context is evaluated on the inline partial and not the block, we need a different partial context for each one. !}
Explicit Evaluation Time Split Partial Context Default{~n}
// TODO: Can sections have parameters, and if so, what happens then? Currently when there is an injected context or an explicit context it gets inserted behind the current context, so 1->2->3 becomes 1->2->injected->3 or explicit->3. When there is a new context(4) with injected we're doing 1->2->3->injected->4. When there is an explicit context and a new context we're doing explicit->4. But what happens if there is a section with parameters and an explicit context, hitting all the categories? Would it be parameters->explicit->4? I would definitely have to change the parameters to this function since right now iteration variables and parameters are both sharing injected_context.
injected_context.map(|ctx|{
// Special case: when there is no explicit context or new
// context element, the injected context gets inserted 1
// spot behind the current context. Otherwise, the
// injected context gets added after the current context
// but before the explicit context and new context