\define macrodef()
If condition not met
\end
<$list filter="condition" emptyMessage=<<macrodef>> >
If Condition met
</$list>
<$list filter="condition" emptyMessage="""
If condition not met
""">
If Condition met
</$list>
<$list filter="[is[current]tagging[]] ~[[::false]]" variable=result>
<$list filter="[<result>prefix[::]]" variable=case>
Do this if <<case>>
</$list>
<$list filter="[<result>!prefix[::]]" variable=case>
Process tiddler "<<case>>"<br>
</$list>
</$list>
<$list filter="[<casevariable>] ~[[::false]]" variable=case>
<$list filter="[<case>prefix[::false]]" variable=case>
Do this if no case value
</$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>
<<select-case condition array-of-cases>>
if filter-not-empty do-this else do-that
I use a lot $list as
if filter-not-empty do-this else do-that
- filter is not empty do what is given inside $list widget
- filter is empty go for emptyMessage
<$list filter="[<casevariable>] ~[[::else]]" variable=case>
<$list filter="[<case>!prefix[::else]]" variable=case> filter-not-empty do-this
</$list>
<$list filter="[<case>prefix[::else]]" variable=case>
else do-that
</$list>
</$list>
We need to wrap inside a macro to present a construct like
<<select-case condition array-of-cases>>
{{invoice-total}}
\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">>
<$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>
\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}]">>
\define my-macro(filter)
{{{ $filter$ }}}
{{{ $filter$ ||templatename}}}
\end
\define my-macro(filter template)
{{{ $filter$ }}}
{{{ $filter$ ||$templatename$}}}
\end
\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">>
filter="[<__x__>prefix[one]suffix[one]]"
[<__x__>equals[one]]
Mohammad,
Yes the single prefix statement allows oneWord where "one" is the prefix of another "word"!And to do what you say more literally you could use "contains[one]"This of course can be stopped if required with
filter="[<__x__>prefix[one]suffix[one]]"
If we ever get an equals[] operator this would becomeNot real yet :)
[<__x__>equals[one]]
Mat,I expect it would suffice. I assume that is an equivalent for equal or prefix[one]suffixe[one]]?
If you know regex well I could generate a list of desirable tests for you to match?
regexp[^one$]
<$list filter="[<casevariable>] ~[[false]]" variable=case>
<$list filter="[<casevariable>regexp[^false$]]" variable=case>
Do this if no case value
</$list>
<$list filter="[<case>regexp[^caseone$]]" variable=case>
Process "caseone"<br>
</$list>
<$list filter="[<case>regexp[^casetwo$]]" variable=case>
Process "casetwo"<br>
</$list>
<$list filter="[<case>regexp[^casethree$]]" variable=case>
Process "casethree"<br>
</$list>
<!-- Even this -->
<$list filter="[<case>regexp[^casetwo$]] [<case>regexp[^casethree$]]" variable=case>
Process "casetwo" and "casethree"<br>
</$list>
</$list>
Ad a result of Jeremy adding a new match operator to 5.1.20 the case statements in this code pattern will be even more user friendly.
First we would say
[<case>prefix[caseone]suffix[caseone]]
Now we would say
[<case>regexp[^caseone$]]
But this Will become which is easier to remember
[<case>match[caseone]]
The regex example still points us to the best approach for more complex tests but match will work for many common cases.
I will now abandon only testing the negative in binary comparisons such as
[<var>] -[[false]]
becomes
[<var>match[true]]
the case insensitive option may also help when var or [{$:/temp/tiddler}] was provided by the user in case they entered tRue and other combinations by mistake.
Thanks Jeremy
Tony
<$list filter="[<casevariable>] ~[[false]]" variable=case>
<$list filter="[<case>match[false]]" variable=case>
Do this if no case value
</$list>
<$list filter="[<case>match[caseone]]" variable=case>
Process "caseone"<br>
</$list>
<$list filter="[<case>match[casetwo]]" variable=case>
Process "casetwo"<br>
</$list>
<$list filter="[<case>match[casethree]]" variable=case>
Process "casethree"<br>
</$list>
<!-- Even this -->
<$list filter="[<case>match[casetwo]] [<case>match[casethree]]" variable=case>
Process "casetwo" and "casethree"<br>
</$list>
</$list>
Mat: I barely even know regexp badly. That is basically the only one I know for exctly the reason of being able to make an exact comparison. BUT don't take my word for it, I just found it on the web..
Now we would say
[<case>regexp[^caseone$]]
The difference here is that ^ is the marker for "start of string" and $ "end of string", regex meta characters.
But there would be no difference between [<case>regexp[caseone]] and [<case>match[caseone]]
I would not underestimate the value of a plain English operator like match for easy to read tests especially when they control visibility and structure in code.
On regex you could give the community A great resource if you provide 10 to 20 top regex tests we may want to use. I could brainstorm some desirable ones.
Regards
Tony
I would not underestimate the value of a plain English operator like match for easy to read tests especially when they control visibility and structure in code.
On regex you could give the community A great resource if you provide 10 to 20 top regex tests we may want to use. I could brainstorm some desirable ones.
if a>b then
do this part one
else if a<b
do this part two
end
if a< b then
do this true part
end
Your first resort would be to the reveal widget since it already permits such comparisons. I had raised the development of less than and greater than operators but there is a real issues these raise because such tests need to take account of the complexity inherent in numbers. I am sure JavaScript can help.
Never the less I will give your questions some thought and see if I can craft a method with existing features. Then if we can't get something that resembles plain English or is not too complex we can ask the developers.
One method may be using one of the sort operators then testing the first in the list. One trick could be to test if the original list ie two items is in the same order after sorting or not. If such tests can be written in a subfilter they could be easy to read
Eg [<var1>] [<var2>] +[subfilter[firstgreater]]
Is true or not.
Thanks for the challenge, I hope others take it on as well.
Though do remember the rereleased version of Evans formulas plugin can do all of this.
Regards
Tonu
<$set name=input1 value=3>
<$set name=input2 value=5>
<$list filter="=[<input1>!match<input2>]" emptyMessage="equals">
<$list filter="=[<input1>min<input2>match<input1>]">
Input 1 = Minimum
</$list>
<$list filter="=[<input1>max<input2>match<input1>]">
Input 1 = Maximum
</$list>
</$list>
</$set></$set>