Hi,
I've written a macro code that gives the expected results, but I find it so
complex and hard to read that I wonder if there is a better way.
Any idea ?
What makes the code complex is the expression of nested if-then-else
statements with $list widgets.
*1/ The data model*
- Tiddlers of type Source <=> with 'so ' prefix
- can have user defined fields, ex: me_agree
- Tiddlers of type Note <=> with 'no ' prefix
- Notes can inherit from a source (tagged by source)
- Notes can inherit from another note
- can have the same user defined fields as sources
This can represent a book, a MOOC, a class, ... for example with book :
- whole book is represented by a "source"
- chapters, subchapters and various notes about excerpts are represented
by several "notes"
*1/ The feature for which I need a macro*
Notes inherit the user defined fields in source, but can overwrite the
fields, and then the overwritten values are propagated to the sub notes.
In the book example above:
- book = source: set field me_agree = yes => I globally agree with the
book
- so all the notes, sub notes, etc will display "me_agree = yes"
- but I strongly disagree with a chapter : setting "me_agree = no" on
the note representing the chapter => this chapter note and all sub notes
will display "me_agree = no"
- but I strongly agree with a couple of excerpts in that particular
chapter : setting "me_agree = yes" on those notes will display "me_agree =
yes"
- etc.
*3/ The code*
Macro definition:
\define get_recursive_field(note_title, field_name, calling_note:"")
<!-- calling_note empty only for initial macro call --->
<$list filter="[<__note_title__>is[tiddler]first[]]" >
<$list filter="[<__note_title__>get<__field_name__>first[]]"
variable=field_value >
<$list filter="[<__calling_note__>is[tiddler]first[]]">
<<field_value>> --- //from <$link to=<<__note_title__>> > ancestor
</$link>//
</$list>
<$list filter="[<__calling_note__>!is[tiddler]first[]]">
<mark> ''<<field_value>>'' </mark>
</$list>
</$list>
<$list filter="[<__note_title__>!has<__field_name__>first[]]" >
<$list filter="[<__note_title__>prefix[so ]first[]]" >
N.A.
</$list>
<$list filter="[<__note_title__>!prefix[so ]first[]]" >
<$set name=new_list filter="[<__note_title__>tags[]prefix[no ]]
[<__note_title__>tags[]prefix[so ]]" select="0">
<$macrocall
$name=get_recursive_field
note_title=<<new_list>>
field_name=<<__field_name__>>
calling_note=<<__note_title__>>
/>
</$set>
</$list>
</$list>
</$list>
\end
Macro call :
Agree with //<<currentTiddler>>// ?
<$macrocall $name=get_recursive_field note_title=<<currentTiddler>>
field_name=src_url />
Hope I could make myself clear ;-)
Best,
Eric N.
--
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/28434bd2-77bd-4e6e-873a-5ffcb4141341%40googlegroups.com.