diff --git a/js/test_cases/explicit_context_setting/README.md b/js/test_cases/explicit_context_setting/README.md index ffb7a36..33ab331 100644 --- a/js/test_cases/explicit_context_setting/README.md +++ b/js/test_cases/explicit_context_setting/README.md @@ -1,3 +1,9 @@ +Priority +-------- +Partials: Explicit context takes priority over parameters + +Sections: New context takes priority, then parameters, then explicit + $idx and $len ------------- @@ -6,7 +12,7 @@ $idx and $len do not survive through an explicit context setting, which will wor 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. diff --git a/js/test_cases/explicit_context_setting/input1.json b/js/test_cases/explicit_context_setting/input1.json index 48c86c4..7a4dc34 100644 --- a/js/test_cases/explicit_context_setting/input1.json +++ b/js/test_cases/explicit_context_setting/input1.json @@ -1,4 +1,9 @@ { + "another_idx": { + "$idx": 21, + "$len": 22, + "other": 23 + }, "block": { "message": { "contents": "Explicit contexts are evaluated in the context of the block." @@ -14,6 +19,9 @@ "explicit": { "pet": "cat" }, + "has_idx": { + "$idx": 14 + }, "inline_partial": { "message": { "contents": "Explicit contexts are evaluated in the context of the inline partial." diff --git a/js/test_cases/explicit_context_setting/main.dust b/js/test_cases/explicit_context_setting/main.dust index bc4e329..eb92a10 100644 --- a/js/test_cases/explicit_context_setting/main.dust +++ b/js/test_cases/explicit_context_setting/main.dust @@ -296,3 +296,33 @@ Explicit Evaluation Time Split Partial Context OVerride{~n} {>explicit_evaluation_time_split_override/} {/inline_partial} {/partial_context} + +{! What happens with sections with explicit context and parameters !} +Section set $idx as a parameter{~n} +==============================={~n} +{#explicit $idx="7"} + $idx is {$idx}{~n} + $len is {$len}{~n} +{/explicit} + +Section set $idx as a parameter and new context{~n} +==============================================={~n} +{#has_idx $idx="7"} + $idx is {$idx}{~n} + $len is {$len}{~n} +{/has_idx} + +Section set $idx as a parameter, new context, and explicit context{~n} +=================================================================={~n} +{#has_idx:another_idx $idx="7" $len="8"} + $idx is {$idx}{~n} + $len is {$len}{~n} + other is {other}{~n} +{/has_idx} + +Section vs Partial priority{~n} +==========================={~n} +{#some_global:explicit pet="snake"} + {pet}{~n} +{/some_global} +{>priority:explicit pet="snake"/} diff --git a/js/test_cases/explicit_context_setting/priority.dust b/js/test_cases/explicit_context_setting/priority.dust new file mode 100644 index 0000000..4e7a114 --- /dev/null +++ b/js/test_cases/explicit_context_setting/priority.dust @@ -0,0 +1 @@ +{pet}{~n}