Thanks Tony!
It works great! I also used a simple version as this
\define case(x)
<$list filter="[<__x__>prefix[one]]">
This is case one.
</$list>
<$list filter="[<__x__>prefix[two]]">
This is case two
</$list>
<$list filter="[<__x__>prefix[three]] [<__x__>prefix[four]]">
This is case three and four
</$list>
\end
<<case "one">>
<<case two>>
<<case "three tag">>
<<case "four dogs come">>
The prefix is case sensitive and it is good
but it also handle cases like oneWord where one is part of another word!
--Mohammad
On Saturday, July 27, 2019 at 11:12:56 AM UTC+4:30, TonyM wrote:
>
> Mohammad,
>
> I some ways I built this so the empty message did not require a macro, to
> keep all the logic in the one block.
>
> I would imaging people would copy such a block as follows
> <$list filter="[<casevariable>] ~[[::false]]" variable=case>
> <$list filter="[<case>prefix[::false]]" variable=case>
> Do this if no case value
> </$list>
> <$list filter="[<case>!prefix[::false]]" variable=case>
> Do this for every case except empty/false
> </$list>
> <$list filter="[<case>prefix[caseone]]" variable=case>
> Process "caseone"<br>
> </$list>
> <$list filter="[<case>prefix[casetwo]]" variable=case>
> Process "casetwo"<br>
> </$list>
> <$list filter="[<case>prefix[casethree]]" variable=case>
> Process "casethree"<br>
> </$list>
> <!-- Even this -->
> <$list filter="[<case>prefix[casetwo]] [<case>prefix[casethree]]"
> variable=case>
> Process "casetwo" and "casethree"<br>
> </$list>
> </$list>
> Then change add remove as needed for their application
>
> However in the unlikely case people need to use "nested case statements or
> reuse them, here is a Quick macro version
> \define in-cases-of(case-filter)
> <$list filter="$case-filter$ ~[[::false]]" variable=case>
> <$list filter="[<case>prefix[::false]]" variable=case>
> Do this if no case value
> </$list>
> <$list filter="[<case>!prefix[::false]]" variable=case>
> Do this for every case except empty/false
> </$list>
> <$list filter="[<case>prefix[caseone]]" variable=case>
> Process "caseone"<br>
> </$list>
> <$list filter="[<case>prefix[casetwo]]" variable=case>
> Process "casetwo"<br>
> </$list>
> <$list filter="[<case>prefix[casethree]]" variable=case>
> Process "casethree"<br>
> </$list>
> <!-- Even this -->
> <$list filter="[<case>prefix[casetwo]] [<case>prefix[casethree]]"
> variable=case>
> Process "casetwo" and "casethree"<br>
> </$list>
> </$list>
> \end
>
> <<in-cases-of "[{!!tiddler-mode}]">>
> Which still needs editing for the specific situation
>
> CHanges most likely would be only
>
> - Change the values for caseone casetwo and casethree to those you
> want to use
> - Add remove other responses to different case values or combinations
> thereof.
>
> Additional interesting patterns here
>
> - The above method of passing filters to a macro as a parameter,
> allows you to pass tiddler content, field content, literal values,
> variable values,
> macronames etc.. which sometimes suddenly results in a macro for one
> purpose suddenly be capable of another purpose.
>
> In a similar way we can pass a filter to a macro as follows
>
> \define my-macro(filter)
> {{{ $filter$ }}}
> {{{ $filter$ ||templatename}}}
> \end
> or
> \define my-macro(filter template)
> {{{ $filter$ }}}
> {{{ $filter$ ||$templatename$}}}
> \end
>
> Once again all this is untested but based on experience.
>
> Regards
> Tony
>
>
>
> On Saturday, July 27, 2019 at 2:39:30 PM UTC+10, Mohammad wrote:
>>
>> Hi Tony!
>> This is great and needs some examples to explore the pros and cons!
>> By the way as you said the application may vary case by case and a macro
>> may not be a good option.
>>
>> --Mohammad
>>
>> On Saturday, July 27, 2019 at 4:18:31 AM UTC+4:30, TonyM wrote:
>>>
>>> Mohammad,
>>>
>>>
>>>> We need to wrap inside a macro to present a construct like
>>>>
>>>> <<select-case condition array-of-cases>>
>>>>
>>>>>
>>>>>
>>>>
>>> In someways I am suggesting you do not need to make a "select-case macro
>>> " because the whole case structure including the empty case can be written
>>> inside the one outer list object. Thus it may be included something like
>>> this
>>> {{invoice-total}}
>>> where the case test various conditions and generates a result eg if tax
>>> applies etc...
>>>
>>> However if you do want to make a macro as in your example the case
>>> structure will still need to know how to handle your array-of-cases
>>>
>>> I would think its more like this;
>>> \define if-else-test(filter)
>>> <$list filter="[[$filter$]] ~[[::else]]" variable=case>
>>> <$list filter="[<case>!prefix[::else]]" variable=case>
>>> filter-not-empty do-this for each result
>>> </$list>
>>> <$list filter="[<case>prefix[::else]]" variable=case>
>>> else do-that
>>> </$list>
>>> <!-- other cases if desired -->
>>> </$list>
>>> \end
>>> <<if-else-test "filter">>
>>> note: untested
>>>
>>> Regards
>>> Tony
>>>
>>
--
You received this message because you are subscribed to the Google Groups
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/tiddlywiki/8be7f90a-cdc9-4198-820c-24ef2450c769%40googlegroups.com.