diff --git a/js/test_cases/helpers_select/README.md b/js/test_cases/helpers_select/README.md new file mode 100644 index 0000000..e127586 --- /dev/null +++ b/js/test_cases/helpers_select/README.md @@ -0,0 +1,12 @@ +Depth +----- +Select blocks can contain any element type inside, just like most blocks. They, however, only apply their select-checking to immediate children. This prevents things like loops with conditionals inside of them. + +Early termination +----------------- + +Comparisons are done in-order and only the first matching comparison (eq/ne/gt/gte/lt/lte) is evaluated. All other non-comparison elements inside the select tag are still rendered normally. + +Default vs none +--------------- +Default was deprecated as of dust 1.6.0 and no longer does anything. It was deprecated because it was essentially the same as none except that there could only be one per select block and it had to be placed after all the other conditions to make sure they were all false. None is more flexible. diff --git a/js/test_cases/helpers_select/input1.json b/js/test_cases/helpers_select/input1.json new file mode 100644 index 0000000..9b9a458 --- /dev/null +++ b/js/test_cases/helpers_select/input1.json @@ -0,0 +1,19 @@ +{ + "pet": "cat", + "person": "Alice", + "pet_names": [ + { + "type": "cat", + "pet_name": "fluffy" + }, + { + "type": "dog", + "pet_name": "rover" + }, + { + "type": "lizard", + "pet_name": "dave" + } + ], + "scalar": 7 +} diff --git a/js/test_cases/helpers_select/main.dust b/js/test_cases/helpers_select/main.dust new file mode 100644 index 0000000..12e4124 --- /dev/null +++ b/js/test_cases/helpers_select/main.dust @@ -0,0 +1,102 @@ +Simple select{~n} +============={~n} +{@select key=pet} + {@eq value="cat"}Lets name your pet fluffy{~n}{/eq} + {@eq value="dog"}Lets name your pet rover{~n}{/eq} + {@eq value="lizard"}Lets name your pet dave{~n}{/eq} +{/select} + +non-comparison bodies inside select{~n} +==================================={~n} +{@select key=pet} + text not inside a comparison{~n} + {@eq value="cat"}Lets name your pet fluffy{~n}{/eq} + {@eq value="dog"}Lets name your pet rover{~n}{/eq} + {@eq value="lizard"}Lets name your pet dave{~n}{/eq} +{/select} + +@any{~n} +===={~n} +{@select key=pet} + {@any}{person} has a pet!{~n}{/any} + {@eq value="cat"}Lets name your pet fluffy{~n}{/eq} + {@eq value="dog"}Lets name your pet rover{~n}{/eq} + {@eq value="lizard"}Lets name your pet dave{~n}{/eq} +{/select} + +@none{~n} +====={~n} +{@select key=pet} + {@any}{person} has a pet!{~n}{/any} + {@none}I don't know what to name {person}'s pet...{~n}{/none} + {@eq value="dog"}Lets name your pet rover{~n}{/eq} + {@eq value="lizard"}Lets name your pet dave{~n}{/eq} +{/select} + +Is key added to the context?{~n} +============================{~n} +{@select key=pet} + {key}{~n} + {@any}{person} has a pet!{~n}{/any} +{/select}{~n} + +Conditionals inside loop sections{~n} +================================={~n} +{@select key=pet} + {@any}{person} has a pet!{~n}{/any} + {#pet_names} + {@eq value=type}Lets name your pet {pet_name}{~n}{/eq} + {/pet_names} + {@none}I don't know what to name {person}'s pet...{~n}{/none} +{/select}{~n} + +Conditionals inside scalar sections{~n} +==================================={~n} +{@select key=pet} + {@any}{person} has a pet!{~n}{/any} + {#scalar} + {@eq value="cat"}Lets name your pet fluffy{~n}{/eq} + {@eq value="dog"}Lets name your pet rover{~n}{/eq} + {@eq value="lizard"}Lets name your pet dave{~n}{/eq} + {/scalar} +{/select}{~n} + +Sections inside select without conditionals{~n} +==========================================={~n} +{@select key=pet} + {@any}{person} has a pet!{~n}{/any} + {#pet_names} + If your pet was a {type} we'd name it {pet_name}{~n} + {/pet_names} + {@eq value="cat"}Lets name your pet fluffy{~n}{/eq} + {@eq value="dog"}Lets name your pet rover{~n}{/eq} + {@eq value="lizard"}Lets name your pet dave{~n}{/eq} +{/select}{~n} + +Early termination{~n} +================={~n} +{@select key=pet} + {@eq value="cat"}Lets name your pet fluffy{~n}{/eq} + {@eq value="cat"}Lets name your pet whiskers{~n}{/eq} + {@eq value="dog"}Lets name your pet rover{~n}{/eq} + {@eq value="lizard"}Lets name your pet dave{~n}{/eq} + {@any}{person} has a pet!{~n}{/any} + text not inside a comparison{~n} + {#pet_names} + If your pet was a {type} we'd name it {pet_name}{~n} + {/pet_names} +{/select}{~n} + +Default{~n} +======={~n} +{@select key=pet} + {@eq value="dog"}Lets name your pet rover{~n}{/eq} + {@eq value="lizard"}Lets name your pet dave{~n}{/eq} + {@default}Fenton is a good name for any pet{~n}{/default} + {@any}{person} has a pet!{~n}{/any} + {@none}I don't know what to name {person}'s pet...{~n}{/none} + text not inside a comparison{~n} + {#pet_names} + If your pet was a {type} we'd name it {pet_name}{~n} + {/pet_names} +{/select}{~n}