duster/js/test_cases/explicit_context_setting
Tom Alexander e7c05f597f
Add a test proving exists does not support parameters.
2020-05-30 14:42:34 -04:00
..
README.md Add priority tests for the other block types except helpers since I do not yet have a helper implemented that sets a value. 2020-05-30 13:47:13 -04:00
default.dust Greatly expand the explicit_context_setting test. 2020-05-24 18:16:16 -04:00
default_explicit.dust Greatly expand the explicit_context_setting test. 2020-05-24 18:16:16 -04:00
explicit_evaluation_time.dust Added tests proving that the explicit context is evaluated using the global context of the partial containing the block (NOT the inline partial, which is where the explicit context is written). 2020-05-25 17:53:04 -04:00
explicit_evaluation_time_split_default.dust Added tests proving that the explicit context is evaluated using the global context of the partial containing the block (NOT the inline partial, which is where the explicit context is written). 2020-05-25 17:53:04 -04:00
explicit_evaluation_time_split_override.dust Added tests proving that the explicit context is evaluated using the global context of the partial containing the block (NOT the inline partial, which is where the explicit context is written). 2020-05-25 17:53:04 -04:00
input1.json Add tests that prove that the priority between explicit contexts and parameters varies across sections and partials. 2020-05-25 20:23:10 -04:00
main.dust Add a test proving exists does not support parameters. 2020-05-30 14:42:34 -04:00
other.dust Greatly expand the explicit_context_setting test. 2020-05-24 18:16:16 -04:00
other_friend.dust Expand the explicit context setting test to prove that injected_context gets inserted AFTER the current context when an explicit context is used. 2020-05-25 16:21:25 -04:00
override.dust Greatly expand the explicit_context_setting test. 2020-05-24 18:16:16 -04:00
override_double_explicit.dust Greatly expand the explicit_context_setting test. 2020-05-24 18:16:16 -04:00
override_explicit.dust Greatly expand the explicit_context_setting test. 2020-05-24 18:16:16 -04:00
priority.dust Add tests that prove that the priority between explicit contexts and parameters varies across sections and partials. 2020-05-25 20:23:10 -04:00

README.md

Priority

Partials: Explicit context takes priority over parameters

Sections: New context takes priority, then parameters, then explicit

Sections with loops: Loop variables ($idx and $len) take priority over parameters and explicit context

$idx and $len

$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).

Parameters on blocks and inline partials appear to not be read but they do not error out.

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.