duster/js/test_cases/explicit_context_setting/main.dust

258 lines
5.9 KiB
Plaintext

{! 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}