From 4ce089927974bbc23b38a8553c8973aad02eeebd Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Mon, 25 May 2020 16:21:25 -0400 Subject: [PATCH] Expand the explicit context setting test to prove that injected_context gets inserted AFTER the current context when an explicit context is used. --- js/test_cases/explicit_context_setting/README.md | 2 ++ js/test_cases/explicit_context_setting/input1.json | 9 ++++++--- js/test_cases/explicit_context_setting/main.dust | 14 ++++++++++++++ .../explicit_context_setting/other_friend.dust | 1 + 4 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 js/test_cases/explicit_context_setting/other_friend.dust diff --git a/js/test_cases/explicit_context_setting/README.md b/js/test_cases/explicit_context_setting/README.md index 8be51bf..3928dd0 100644 --- a/js/test_cases/explicit_context_setting/README.md +++ b/js/test_cases/explicit_context_setting/README.md @@ -17,6 +17,8 @@ Explicitly setting a context in a partial also works. The explicit context takes 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 `1->2->3->parameters->explicit`. + Helpers ------- diff --git a/js/test_cases/explicit_context_setting/input1.json b/js/test_cases/explicit_context_setting/input1.json index 20dd998..30ea9ae 100644 --- a/js/test_cases/explicit_context_setting/input1.json +++ b/js/test_cases/explicit_context_setting/input1.json @@ -4,17 +4,20 @@ { "person": { "name": "Alice" - } + }, + "friend": "Bob" }, { "person": { "name": "Bob" - } + }, + "friend": "Chris" }, { "person": { "name": "Chris" - } + }, + "friend": "Alice" } ], "explicit": { diff --git a/js/test_cases/explicit_context_setting/main.dust b/js/test_cases/explicit_context_setting/main.dust index fbaa3ff..cc43cc2 100644 --- a/js/test_cases/explicit_context_setting/main.dust +++ b/js/test_cases/explicit_context_setting/main.dust @@ -255,3 +255,17 @@ Falsey Explicit Path Explicit{~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? !} +Partial Overloaded Regular with parameters{~n} +=========================================={~n} +{#loop} + {>other_friend friend="Dave" pet="rabbit"/} +{/loop} + +Partial Overloaded Explicit with parameters{~n} +==========================================={~n} +{#loop} + {>other_friend:explicit friend="Dave" pet="rabbit"/} +{/loop} + diff --git a/js/test_cases/explicit_context_setting/other_friend.dust b/js/test_cases/explicit_context_setting/other_friend.dust new file mode 100644 index 0000000..327c5c2 --- /dev/null +++ b/js/test_cases/explicit_context_setting/other_friend.dust @@ -0,0 +1 @@ +{$idx}: {person.name}'s friend {friend} has a pet {pet} but not a {some_global}{~n}