[tw] Re: TW5 - Simple macro question: If fieldvalue is empty, true or false then render ...

2017-04-10 Thread Måns
Hi

For anyone who has followed this thread - or just found it and wants to see 
how the solution ended up looking like - here's a glimpse at the code:

\define if(value:"_false_",test,true,else,error) 
<$vars value="""$value$""" test="""$test$"""> 
<$set name="result" filter="[!prefix[_false_]]" value="compare" 
emptyValue="if-error">
<$macrocall $name=<> value=<> test=<> true="""$true$""" 
else="""$else$""" error="""$error$""" />
 

\end

\define compare(value,test,true,else,error) 
<$vars value="""$value$""" test="""$test$""" true="""$true$""" 
else="""$else$"""> 
<$set name="result" filter="[prefix]" value=<> 
emptyValue=<>>
<>
 

\end

\define if-error(value,test,true,else,error:"undefined")
//$error$//
\end

\define male() <$macrocall $name="if" value={{!!gender}} test="he" true="male" 
else="female" error="choose gender"/>
\define g() <$macrocall $name="if" value={{!!gender}} test="he" true="he" 
else="she"/>
\define G() <$macrocall $name="if" value={{!!gender}} test="he" true="He" 
else="She"/>
\define g2() <$macrocall $name="if" value={{!!gender}} test="he" true="him" 
else="her"/>
\define G2() <$macrocall $name="if" value={{!!gender}} test="he" true="Him" 
else="Her"/>
\define g'() <$macrocall $name="if" value={{!!gender}} test="he" true="his" 
else="her"/>
\define G'() <$macrocall $name="if" value={{!!gender}} test="he" true="His" 
else="Her" error="gender not defined"/>

<$checkbox field="gender" checked="he" unchecked="she"> <>

<$checkbox field="gender" checked=""> undefined 

!! Gender Test Results

g is ''<>''

G is ''<>''

g2 is ''<>''

G2 is ''<>''

g' is ''<>''

G' is ''<>''


I now have it working in my "teacher's tool for writing student statements" 
here: måns.dk/udtalelser/test 

It's all in Danish I'm afraid. 
The example code is here: http://xn--mns-ula.dk/udtalelser/test/#Helmigers

My danish variant is here: 
http://xn--mns-ula.dk/udtalelser/test/#PronominVariabel

Happy hacking :-)

Cheers Måns Mårtensson

Den lørdag den 8. april 2017 kl. 13.15.24 UTC+2 skrev Måns:
>
> Hi TwWizards
>
> I am attempting to create a couple of global macros which will allow 
> simple text templating.
>
> My question is: How can a create a few simple macros which will render 
> different results depending on a fieldvalue in a tiddler?:
>
> Tagged: $:/tags/Macro
>
> \define name() {{!!surname}}
>
> \define hs() If the value of the field gender is true then show: "he". 
> If gender is false then show: "she". If gender value is empty show: it
> \end
> \define Hs()  If the value of the field gender is true then show: "He". 
> If gender is false then show: "She". If gender value is empty show: It
> \end
> \define hs'()  If the value of the field gender is true then show: "his". 
> If gender is false then show: "her". If gender value is empty show: it's
> \end
> \define Hs'()  If the value of the field gender is true then show: "His". 
> If gender is false then show: "Her". If gender value is empty show: It's
> \end
> \define gender()  If the value of the field gender is true then show: "boy". 
> If gender is false then show: "girl". If gender value is empty show: boy/girl
> \end
>
> <>
>
> <$checkbox field="gender" checked="true" 
> unchecked="false"><>
>
> <>
> <>
> <>
> <>
>
>
> (As usual) I need some kind of "if-logic" ...
>
> Cheers Måns Mårtensson
>
>

-- 
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 tiddlywiki+unsubscr...@googlegroups.com.
To post to this group, send email to tiddlywiki@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/ad4b09be-f791-4dd7-8b03-ca39ce832911%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[tw] Re: TW5 - Simple macro question: If fieldvalue is empty, true or false then render ...

2017-04-08 Thread Thomas Elmiger
Somehow copy-pasting corrupted our first filter for me – please make sure there 
is no linebreak in this:

filter="[!prefix[_false_]]" 

-- 
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 tiddlywiki+unsubscr...@googlegroups.com.
To post to this group, send email to tiddlywiki@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/c9bffd36-9d6f-4ee6-bd56-b5dc2d7ec792%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[tw] Re: TW5 - Simple macro question: If fieldvalue is empty, true or false then render ...

2017-04-08 Thread Thomas Elmiger
What I wanted to say: YOU were really close! 

I am still working from my phone – that’s where all the typos come from. 

Would be interesting to see your app once it is finished …

-- 
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 tiddlywiki+unsubscr...@googlegroups.com.
To post to this group, send email to tiddlywiki@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/ff77abbf-8e5e-4413-a399-05132c6a18ff%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[tw] Re: TW5 - Simple macro question: If fieldvalue is empty, true or false then render ...

2017-04-08 Thread Thomas Elmiger
Hi Måns 

We are getting closer. Here’s some brain-candy for you: 

What your gray cells missed was the fact that every variant would need a 
check-macro. Bit that was too complicated anyway. 

Now I have generalized the check so it takes a second parameter called 
"nextmacro" to define the following macro. The check itself was therefore 
renamed to "gendercheck".

This worked for me. 

Wish you a relaxing weekend!
Thomas 

---

\define gendercheck(nextmacro:"He-She" gendervalue:"_false_") 
<$vars next="""$nextmacro$""" value="""$gendervalue$"""> 
<$set name="result" filter="[!prefix[_
false_]]" value=<> emptyValue="no-value">

<$macrocall $name=<> gendervalue=$gendervalue$ />

 

\end

\define he-she(gendervalue) 
<$vars value="""$gendervalue$"""> 
<$set name="result" filter="[prefix[he]]" value="he" emptyValue="she">

result: <>

 

\end

\define He-She(gendervalue) 
<$vars value="""$gendervalue$"""> 
<$set name="result" filter="[prefix[he]]" value="He" emptyValue="She">

result: <>

 

\end

\define no-value(gendervalue)

gender is not defined

\end

\define him-her(gendervalue) 
<$vars value="""$gendervalue$"""> 
<$set name="result" filter="[prefix[he]]" value="him" emptyValue="her">

result: <>

 

\end

\define Him-Her(gendervalue) 
<$vars value="""$gendervalue$"""> 
<$set name="result" filter="[prefix[he]]" value="Him" emptyValue="Her">

result: <>

 

\end

\define his-her(gendervalue) 
<$vars value="""$gendervalue$"""> 
<$set name="result" filter="[prefix[he]]" value="his" emptyValue="her">

result: <>

 

\end

\define His-Her(gendervalue) 
<$vars value="""$gendervalue$"""> 
<$set name="result" filter="[prefix[he]]" value="His" emptyValue="Her">

result: <>

 

\end

\define g() <$macrocall $name="gendercheck" nextmacro="he-she" 
gendervalue={{!!gender}}/>
\define G() <$macrocall $name="gendercheck" nextmacro="He-She" 
gendervalue={{!!gender}}/>
\define g2() <$macrocall $name="gendercheck" nextmacro="him-her" 
gendervalue={{!!gender}}/>
\define G2() <$macrocall $name="gendercheck" nextmacro="Him-Her" 
gendervalue={{!!gender}}/>
\define g'() <$macrocall $name="gendercheck" nextmacro="his-her" 
gendervalue={{!!gender}}/>
\define G'() <$macrocall $name="gendercheck" nextmacro="His-Her" 
gendervalue={{!!gender}}/>

<$checkbox field="gender" checked="he" unchecked="she"> male
output: <$macrocall $name="He-She-check" gendervalue={{!!gender}}/>

g is <>

G is <>

g2 is <>

G2 is <>

g' is <>

G' is <>

-- 
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 tiddlywiki+unsubscr...@googlegroups.com.
To post to this group, send email to tiddlywiki@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/0047e357-5675-4379-889b-f11a54726078%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[tw] Re: TW5 - Simple macro question: If fieldvalue is empty, true or false then render ...

2017-04-08 Thread Måns
Hi Thomas

I'm afraid some kind of "neuronic" overloading is what is happening to my 
brain :-)

I tried this to get closer to what I want. I'm afraid it doesn't work this 
way:

\define He-She-check(gendervalue:"_false_") 
<$vars value="""$gendervalue$"""> 
<$set name="result" filter="[!prefix[_false_]]" value="He-She" 
emptyValue="no-value">

<$macrocall $name=<> gendervalue=$gendervalue$ />

 

\end

\define he-she(gendervalue) 
<$vars value="""$gendervalue$"""> 
<$set name="result" filter="[prefix[he]]" value="he" emptyValue="she">

result: <>

 

\end

\define He-She(gendervalue) 
<$vars value="""$gendervalue$"""> 
<$set name="result" filter="[prefix[he]]" value="He" emptyValue="She">

result: <>

 

\end

\define no-value(gendervalue)

gender is not defined

\end

\define him-her(gendervalue) 
<$vars value="""$gendervalue$"""> 
<$set name="result" filter="[prefix[he]]" value="him" emptyValue="her">

result: <>

 

\end

\define Him-Her(gendervalue) 
<$vars value="""$gendervalue$"""> 
<$set name="result" filter="[prefix[he]]" value="Him" emptyValue="Her">

result: <>

 

\end

\define his-her(gendervalue) 
<$vars value="""$gendervalue$"""> 
<$set name="result" filter="[prefix[he]]" value="his" emptyValue="her">

result: <>

 

\end

\define His-Her(gendervalue) 
<$vars value="""$gendervalue$"""> 
<$set name="result" filter="[prefix[he]]" value="His" emptyValue="Her">

result: <>

 

\end

\define g() <$macrocall $name="he-she-check" gendervalue={{!!gender}}/>
\define G() <$macrocall $name="He-She-check" gendervalue={{!!gender}}/>
\define g2() <$macrocall $name="him-her-check" gendervalue={{!!gender}}/>
\define G2() <$macrocall $name="Him-Her-check" gendervalue={{!!gender}}/>
\define g'() <$macrocall $name="his-her-check" gendervalue={{!!gender}}/>
\define G'() <$macrocall $name="His-Her-check" gendervalue={{!!gender}}/>

<$checkbox field="gender" checked="he" unchecked="she"> male
output: <$macrocall $name="He-She-check" gendervalue={{!!gender}}/>

<>
<>
<>
<>
<>
<>


Den lørdag den 8. april 2017 kl. 18.54.43 UTC+2 skrev Thomas Elmiger:
>
> Part 2: Assigning other values by calling a macro via a variable. 
>
> Code: 
>
> ---
>
> \define He-She-check(gendervalue:"_false_") 
> <$vars value="""$gendervalue$"""> 
> <$set name="result" filter="[!prefix[_false_]]" value="He-She" 
> emptyValue="no-value">
>
> <$macrocall $name=<> gendervalue=$gendervalue$ />
>
>  
> 
> \end 
>
> \define He-She(gendervalue) 
> <$vars value="""$gendervalue$"""> 
> <$set name="result" filter="[prefix[he]]" value="He" 
> emptyValue="She">
>
> result: <> 
>
>  
> 
> \end 
>
> \define no-value(gendervalue) 
>
> gender is not defined 
>
> \end 
>
> <$checkbox field="gender" checked="he" unchecked="she"> male
>
> output: <$macrocall $name="He-She-check" gendervalue={{!!gender}}/>
>
> ---
>
> In the check-macro we test, if the value is not empty in the same way as 
> before. 
> According to the test result we assign the name of the next macro we want 
> to call. 
> If we have a value, we go to the He-She macro and check, if the value is 
> "he". Then we generate a maching output "He" or "She". 
>
> O.k. for your brain? 
>
> All the best!
> Thomas 
>
>

-- 
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 tiddlywiki+unsubscr...@googlegroups.com.
To post to this group, send email to tiddlywiki@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/87482ee3-1123-4c4b-a82a-ab33908dd669%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[tw] Re: TW5 - Simple macro question: If fieldvalue is empty, true or false then render ...

2017-04-08 Thread Thomas Elmiger
Part 2: Assigning other values by calling a macro via a variable. 

Code: 

---

\define He-She-check(gendervalue:"_false_") 
<$vars value="""$gendervalue$"""> 
<$set name="result" filter="[!prefix[_false_]]" value="He-She" 
emptyValue="no-value">

<$macrocall $name=<> gendervalue=$gendervalue$ />

 

\end 

\define He-She(gendervalue) 
<$vars value="""$gendervalue$"""> 
<$set name="result" filter="[prefix[he]]" value="He" emptyValue="She">

result: <> 

 

\end 

\define no-value(gendervalue) 

gender is not defined 

\end 

<$checkbox field="gender" checked="he" unchecked="she"> male

output: <$macrocall $name="He-She-check" gendervalue={{!!gender}}/>

---

In the check-macro we test, if the value is not empty in the same way as 
before. 
According to the test result we assign the name of the next macro we want to 
call. 
If we have a value, we go to the He-She macro and check, if the value is "he". 
Then we generate a maching output "He" or "She". 

O.k. for your brain? 

All the best!
Thomas 

-- 
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 tiddlywiki+unsubscr...@googlegroups.com.
To post to this group, send email to tiddlywiki@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/d28ba3a6-2a56-4ddc-b2b1-60a0c6040d46%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[tw] Re: TW5 - Simple macro question: If fieldvalue is empty, true or false then render ...

2017-04-08 Thread Thomas Elmiger
Hmm, correcting my own code I just realized that we don’t need the 
value=<> part in the filter statement – this is the default. 

-- 
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 tiddlywiki+unsubscr...@googlegroups.com.
To post to this group, send email to tiddlywiki@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/66cd87d4-9dec-4c75-b4c6-afca25d5ea21%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[tw] Re: TW5 - Simple macro question: If fieldvalue is empty, true or false then render ...

2017-04-08 Thread Thomas Elmiger
Sorry, wrong code!

Try this:

\define he-she-it(gendervalue:"_false_") 
<$vars value="""$gendervalue$"""> 
<$set name="result" filter="[!prefix[_false_]]" value=<> 
emptyValue="it">

result: <> 

 


\end 

<$checkbox field="gender" checked="he" unchecked="she"> male

output: <$macrocall $name="he-she-it" gendervalue={{!!gender}}/>

-- 
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 tiddlywiki+unsubscr...@googlegroups.com.
To post to this group, send email to tiddlywiki@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/99e21847-faab-4fb8-9e2d-acd15d412988%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[tw] Re: TW5 - Simple macro question: If fieldvalue is empty, true or false then render ...

2017-04-08 Thread Thomas Elmiger
Hi again Måns, 

Now this time we are going to solve thad riddle!

Try this and I try to explain gor your brain ;–)

---

\define he-she-it(gendervalue:"_false_") 
<$vars value="""$gendervalue$"""> 
<$set name="result" filter="[!prefix[_false_]]" value=<> 
emptyValue="it">

result: <> 

 


\end 

<$checkbox field="gender" checked="he" unchecked="she"> male

output: <$macrocall $name="he-she-it" gendervalue={{!!gender}}/>

---

It all starts with the macrocall instead of the shorter <> 
syntax. Frankly, I don’t know why. 
If the input for the macro is empty, we assign the value "_false_" (maybe this 
works only with the macrocall syntax). 
We assign the input value to a variable so we can use it in the filter later. 
The result is the output of a filter: if the input value does not (!) equal 
"false" we assign the input value. Else the filter returns empty and we assign 
"it". (You can of course change that to "gender unknown" if you like.)

Finally we generate the output starting with "result: …"

Hope that helps. More to come …

Cheers,
Thomas 

-- 
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 tiddlywiki+unsubscr...@googlegroups.com.
To post to this group, send email to tiddlywiki@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/64222191-62c9-4733-b277-386f91615160%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[tw] Re: TW5 - Simple macro question: If fieldvalue is empty, true or false then render ...

2017-04-08 Thread Måns
Hi Thomas

Thank you very much for answering :-)
If I do it like this:

\define he-she-it(gendervalue:"_false_") 
<$vars value="""$gendervalue$"""> 
<$set name="result" filter="[!prefix[_false_]]" value=<> 
emptyValue="it" > 
<> 
 
 
\end 

<$checkbox field="gender" checked="he" unchecked="she"><>


Nothing is shown when the field is either empty or doesn't exist.
It shows "he" when "he" is the value and "she" if "she" is the value.
It doesn't seem to do anything except rendering the fieldvalue when I use 
it like this..

Actually I don't need the neutral state - just: he, she, He, She, his, her. 
His Her computed from the state value (true or false) of a field (gender) 
(If the field does not exist a default value like: "gender not known" would 
suffice.

For convience I want to use short macros like <>, <>, <> and 
<> to render different results..

To me it seems like it should/would be some very simple (understandable) 
macro I should be able to string together with a few conditional "if's" 
here and there and wikitext... 
However I've been trying to do this in a TW for some years now - and I 
always have to give up because it gets to complicated for my (brain) usage 
:-) 
It always ends up with shooting sparrows with cannons eg: using Library 
tiddlers and what not ...

Thank you for trying to help me out - even if I don't understand the macro 
definition you posted :-)

Cheers Måns Mårtensson



Den lørdag den 8. april 2017 kl. 14.20.36 UTC+2 skrev Thomas Elmiger:
>
> Forgot to mention: my solution works, if you store "he" or "she" as values 
> in the field "gender" and call my macro with this value as a parameter. 
>
> Of course this solves only one of your questions but maybe it helps as a 
> starting point. 
>

-- 
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 tiddlywiki+unsubscr...@googlegroups.com.
To post to this group, send email to tiddlywiki@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/54cc1e02-44a2-45c9-a0f1-c920cf82578a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.