Changeset 9329


Ignore:
Timestamp:
09/25/10 09:12:13 (20 months ago)
Author:
PaulHarvey
Message:

Item9415: Doc updates, new animated example of nested (delayed) macro

  • Invented some terminology: 'Standard' and 'delayed' form of macros
  • Macros & FormattedSearch updates
  • More fixes for CompleteDocumentation
  • Removed &vbar; which isn't a real HTML entity, from VarENCODE
Location:
branches/Release01x01/core/data/System
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/Release01x01/core/data/System/FormattedSearch.txt

    r9258 r9329  
    4141| =$nhits= | Number of hits if =multiple="on"=. Cumulative across all topics in current web. Identical to =$ntopics= unless =multiple="on"= | 
    4242| =$pager= | pager control - can be optionally customised using the =pagerformat= below | 
    43 %INCLUDE{FormatTokens}% 
     43%INCLUDE{"FormatTokens"}% 
    4444 
    4545<blockquote class="foswikiHelp">%X% Note that if the separator parameter for SEARCH is not defined a newline is added after the last search result.</blockquote> 
     
    6464| =$previousbutton= | skin template (SEARCH:pager_previous) html for the full URL to the previous page - _IF_ using the built in pager system | 
    6565| =$nextbutton= | skin template (SEARCH:pager_next) html for the full URL to the previous page - _IF_ using the built in pager system | 
    66 %INCLUDE{FormatTokens}% 
     66%INCLUDE{"FormatTokens"}% 
    6767 
    6868---+++ 4. =format="..."= parameter 
     
    113113| =$nhits= | Number of hits if =multiple="on"=. Cumulative across all topics in current web. Identical to =$ntopics= unless =multiple="on"= | 
    114114| =$pager= | pager control - can be optionally customised using the =pagerformat= below | 
    115 %INCLUDE{FormatTokens}% 
     115%INCLUDE{"FormatTokens"}% 
    116116 
    117117---++ Examples 
     
    187187#NestedSearch 
    188188---+++ Nested Search 
    189  
    190 [[VarSEARCH][SEARCH]], as with many TML macros, may be nested. For example: search for some topics in an initial (outer) search, and for each of them apply a second (inner) search. The idea is to use the outer search to build a series of inner seraches. 
    191  
    192 %INCLUDE{"Macros" section="insideoutlefttoright" THETOPIC="%SYSTEMWEB%.FAQWhatIsWikiWiki" THEFIELD="TopicClassification"}% 
     189[[VarSEARCH][SEARCH]] is one of many [[Macros][macros]] that produce output which may be controlled with =format=, =header= and =footer= parameters, among others. To make use of _additional_ macros in the output, familiarity with [[#InsideOutLeftToRight][inside-out, left-to-right]] order of expansion rules is required. There are two forms: 
     190   1 Standard: Use =%<nop>INNERMACRO%= to build the parameter string *before* =%<nop>OUTERMACRO%= is expanded 
     191   <verbatim class="tml"> %OUTERMACRO{ 
     192   format="%INNERMACRO%" 
     193 }%</verbatim> 
     194   1 Delayed: Use the parameter string to incorporate =%<nop>INNERMACRO%= into the output of =%<nop>OUTERMACRO%= 
     195   <verbatim class="tml"> %OUTERMACRO{ 
     196   format="$percentINNERMACRO$percent" 
     197 }%</verbatim> 
     198 <blockquote class="foswikiHelp">%T% When working with a given [[Macros][macro]], consult its documentation to determine which paramters support the =$percent/$percnt= [[FormatTokens][format tokens]]</blockquote> 
     199 
     200%INCLUDE{"Macros" 
     201  section="insideoutlefttoright" 
     202  THETOPIC="%SYSTEMWEB%.FAQWhatIsWikiWiki" 
     203  THEFIELD="TopicClassification" 
     204  PARENT="UserDocumentationCategory" 
     205}% 
     206 
     207---++++ Worked example 
     208*Problem:* search for some topics in an initial (outer) search, and for each of them apply a second (inner) search. The idea is to use the outer search to build a series of inner seraches. 
    193209 
    194210#NestedSearchExample 
     
    216232Now let's nest the two. 
    217233#NestingWithEscapes 
    218 ---++++ Method 1 (nesting with escapes) 
     234---+++++ Method 1 (nesting with escapes) 
    219235The inner search cannot be placed directly into the format string of the outer, because of the "inside-out, left-to-right" macro expansion behaviour [[#InsideOutLeftToRight][discussed earlier]]. It must be delayed so that the outer search is evaluated first. To do this, we need to escape the inner search, i.e. let the outer search build a series of searches comprised of the inner search. 
    220236   * Use =$percent= to escape (delay) the inner search's [[VarSEARCH][SEARCH]] macro 
     
    254270}% 
    255271 
     272<blockquote class="foswikiHelp"> 
     273%X% When nesting with escapes, each new nesting level must "escape the escapes", e.g. write =$dollarpercentSEARCH{= for level three, =$dollardollarpercentSEARCH{= for level four, etc. 
     274</blockquote> 
     275 
    256276#NestedSectionalInclude 
    257 ---++++ Method 2 (nesting with sectional includes) 
    258 Nested expressions can be difficult to write correctly, and are difficult to troubleshoot when they go wrong. 
    259  
    260 The recommended approach is to make use of the [[VarSTARTSECTION][STARTSECTION]]/[[VarENDSECTION][ENDSECTION]] feature of the [[VarINCLUDE][INCLUDE]] macro. Instead of nesting the inner search expression directly inside the format string of the outer, the inner search is written as a separate stand-alone section of a topic which is INCLUDEd into the format string of the outer. 
     277---+++++ Method 2 (nesting with sectional includes) 
     278Nested expressions with delayed macros can be difficult to write: care must be taken to escape all the quotes of the inner delayed macro, and it may become confusing whether to use =$topic=, =$dollartopic= or =$dollardollartopic=. 
     279 
     280If you find yourself using escaped tokens like =$dollartopic=, another approach is to use the [[VarSTARTSECTION][STARTSECTION]]/[[VarENDSECTION][ENDSECTION]] feature of [[VarINCLUDE][INCLUDE]]. Instead of nesting the inner search expression directly inside the format string of the outer, the inner search is written as a separate stand-alone section of a topic which is INCLUDEd into the format string of the outer. 
    261281 
    262282*Write this:* 
     
    288308<blockquote class="foswikiHelp">%H% Output will be the same as for the first method 
    289309 
    290 %X% Nested search can be slow, especially if you nest more than 3 levels deep. Nesting is limited to 16 levels. 
    291  
    292 When nesting with escapes, each new nesting level must "escape the escapes", e.g. write =$dollarpercentSEARCH{= for level three, =$dollardollarpercentSEARCH{= for level four, etc. 
    293  
    294 Therefore the sectional include method is strongly recommended to avoid this kind of difficult syntax.</blockquote> 
     310%X% Nested search can be slow, especially if you nest more than 3 levels deep. Nesting is limited to 16 levels.</blockquote> 
    295311 
    296312---+++ Most recently changed pages 
     
    319335}% 
    320336 
     337#ConditionalOutputExample 
    321338---+++ Search with conditional output 
    322339 
     
    341358<blockquote class="foswikiHelp"> 
    342359%ICON{"info"}% *Details:* 
    343    * The SEARCH has a deferred [[VarICON][ICON]]. The =$percent= ensures that ICON is evaluated once for each search hit 
    344    * The [[VarICON][ICON]] contains an [[VarIF][IF]], which again is deferred with the =$percent= token and will also be evaluated for each SEARCH hit. Additionally, the "inside-out, left-to-right" rule discussed earlier means that this IF expression will be evaluated before [[VarICON][ICON]]. 
     360   * The SEARCH has a delayed [[VarICON][ICON]]. The =$percent= ensures that ICON is evaluated once for each search hit 
     361   * The [[VarICON][ICON]] contains an [[VarIF][IF]], which again is delayed with the =$percent= token and will also be evaluated for each SEARCH hit. Additionally, the [[#InsideOutLeftToRight][inside-out, left-to-right]] rule discussed earlier means that this IF expression will be evaluated before [[VarICON][ICON]]. 
    345362   * If =$topic= is a child of UserDocumentationCategory, the =info= icon is used; otherwise, =gear=. 
    346363</blockquote> 
     
    366383<verbatim class="tml"> 
    367384<form action="%SCRIPTURLPATH{"view"}%/%WEB%/%TOPIC%"> 
    368 Find Topics:  
     385Find Topics: 
    369386<input type="text" name="q" size="32"\ 
    370387  value="%URLPARAM{"q" encode="entity"}%" />&nbsp;<input\ 
  • branches/Release01x01/core/data/System/Macros.txt

    r9258 r9329  
    2323To use a macro type its name. For example, 
    2424   * type =%<nop>T%= to get %T% (a [[%SYSTEMWEB%.PreferenceSettings][preference settings]]) 
    25    * type =%<nop>TOPIC%= to get =%TOPIC%= (a predefined [[macro]]) 
    26    * type =%<nop>CALC{ "$UPPER(Text)" }%= to get =TEXT= ([[VarCALC][CALC]] is a macro defined by SpreadSheetPlugin) 
     25   * type =%<nop>TOPIC%= to get =%TOPIC%= (a predefined [[VarTOPIC][macro]]) 
     26   * type =%<nop>CALC{ "$UPPER(Text)" }%= to get =TEXT= ([[VarCALC][CALC]] is a macro defined by [[SpreadSheetPlugin]]) 
    2727 
    2828*Note:* 
     
    3434---+++ Order of expansion 
    3535The following describes only these types of macros: 
    36    * Most built-in Foswiki macros. The following are notable exceptions: [[VarCALC][CALC]], [[VarSTARTSECTION][STARTSECTION]]/ENDSECTION, [[VarSTARTINCLUDE][STARTINCLUDE]]/STOPINCLUDE 
    37    * Preference variables 
    38    * Macros registered by most plugins, using the so-called [[PerlDoc?module=Foswiki::Func#registerTagHandler][registerTagHandler()]] 
    39  
    40 But *not* plugins which rely on [[PerlDoc?module=Foswiki::Func#commonTagsHandler][commonTagsHandler()]] 
     36   * [[PreferenceSettings][Preference settings]] 
     37   * Most macros provided by plugins (those that use [[PerlDoc?module=Foswiki::Func#registerTagHandler][registerTagHandler()]]) 
     38   <blockquote class="foswikiHelp">%X% *Not* those that use [[PerlDoc?module=Foswiki::Func#commonTagsHandler][commonTagsHandler()]]</blockquote> 
     39   * Most built-in Foswiki macros 
     40   <blockquote class="foswikiHelp">%X% Notable exceptions include: [[VarCALC][CALC]], [[VarSTARTSECTION][STARTSECTION]]/ENDSECTION, [[VarSTARTINCLUDE][STARTINCLUDE]]/STOPINCLUDE</blockquote> 
    4141 
    4242%STARTSECTION{"insideoutlefttoright"}% 
     43#StandardForm 
     44---++++ Standard form 
    4345#InsideOutLeftToRight 
    44 The key to understanding nested expressions in Foswiki is to understand that macros are expanded "inside-out, left-to-right". For example: 
     46The key to understanding nested expressions in Foswiki is to understand that macros are expanded "inside-out, left-to-right". *Example:* 
     47 
    4548<verbatim class="tml"> 
    4649%MACRO1{ 
     
    5053}% 
    5154</verbatim> 
    52  
    5355The macros are expanded in this order: MACRO3, MACRO4, MACRO2, MACRO1. 
    5456 
    55 ---++++ Animated Example 
     57#AnimatedExample 
     58---+++++ Animated Example 
    5659%JQREQUIRE{"CYCLE,EASING,CHILI"}%<!-- ids are appended with %INCLUDINGTOPIC% 
    5760to avoid duplicates in System.CompleteDocumentation -->%ADDTOZONE{"script" 
     
    7275  requires="JQUERYPLUGIN::CYCLE" 
    7376}%%ADDTOZONE{"head" 
    74   id="NestedSlideshow/css" 
     77  id="NestedSlideshow%INCLUDINGTOPIC%/css" 
    7578  text="<style type='text/css'> 
    76     #NestedSlideshow%INCLUDINGTOPIC% { width: 440px; height: 249px; } 
    77     #NestedSlideshowNav%INCLUDINGTOPIC%  { z-index: 50; position: absolute; bottom: 10px; } 
    7879    #NestedSlideshowNav%INCLUDINGTOPIC%  a { margin: 0 10px 0 0; padding: 3px 5px; border: 1px solid #ddd; background: #fff; text-decoration: none } 
    7980    #NestedSlideshowNav%INCLUDINGTOPIC%  a.activeSlide, 
     
    8182    #NestedSlideshowNav%INCLUDINGTOPIC%  a:focus { outline: none; } 
    8283  </style>" 
    83 }%<div id="NestedSlideshow%INCLUDINGTOPIC%"> 
    84     <div id="NestedSlideshowNav%INCLUDINGTOPIC%"></div> 
     84}%<div id="NestedSlideshowNav%INCLUDINGTOPIC%"></div> 
     85<div id="NestedSlideshow%INCLUDINGTOPIC%"> 
    8586<pre class="tml"> 
    8687%<nop>INCLUDE{ 
     
    106107%<nop>INCLUDE{ 
    107108    "%<nop>QUERY{ 
    108         "'%<nop>SYSTEMWEB%.FAQWhatIsWikiWiki'/%THEFIELD%" 
     109        "'%<nop>SYSTEMWEB%.FAQWhatIsWikiWiki'/TopicClassification" 
    109110    }%" 
    110111    section="Summary" 
     
    116117%<nop>INCLUDE{ 
    117118    "%<nop>QUERY{ 
    118         "'%SYSTEMWEB%.FAQWhatIsWikiWiki'/%THEFIELD%" 
     119        "'%SYSTEMWEB%.FAQWhatIsWikiWiki'/TopicClassification" 
    119120    }%" 
    120121    section="Summary" 
     
    126127%<nop>INCLUDE{ 
    127128    "%QUERY{ 
    128         "'%SYSTEMWEB%.FAQWhatIsWikiWiki'/%THEFIELD%" 
     129        "'%SYSTEMWEB%.FAQWhatIsWikiWiki'/TopicClassification" 
    129130    }%" 
    130131    section="Summary" 
     
    136137%INCLUDE{ 
    137138    "%QUERY{ 
    138         "'%SYSTEMWEB%.FAQWhatIsWikiWiki'/%THEFIELD%" 
     139        "'%SYSTEMWEB%.FAQWhatIsWikiWiki'/TopicClassification" 
    139140    }%" 
    140141    section="Summary" 
     
    146147%INCLUDE{ 
    147148    "%QUERY{ 
    148         "'%SYSTEMWEB%.FAQWhatIsWikiWiki'/%THEFIELD%" 
     149        "'%SYSTEMWEB%.FAQWhatIsWikiWiki'/TopicClassification" 
    149150    }%" 
    150151    section="Summary" 
     
    152153   * Set THETOPIC = %SYSTEMWEB%.FAQWhatIsWikiWiki 
    153154   * Set THEFIELD = TopicClassification 
     155</pre> 
     156</div> 
     157 
     158#DelayedForm 
     159---++++ Delayed form 
     160[[#StandardForm][Standard form]] macros can nearly always be used to build the parameter string of another macro; however, sometimes it is desirable to bypass the [[#InsideOutLeftToRight][inside-out]] expansion order and delay the inner macro until after the outer macro has finished expansion. This is accomplished by using the [[FormatTokens][$percent]] format token instead of =%=, and escaping any ="= character it uses (becomes =\"=) 
     161 
     162<blockquote class="foswikiHelp">%T% When working with a given [[Macros][macro]], consult its documentation to determine which paramters support the =$percent/$percnt= [[FormatTokens][format tokens]]. Generally only _output parameters_ like =header=, =format= and =footer= support [[FormatTokens][format tokens]].</blockquote> 
     163*Example:* 
     164<verbatim class="tml"> 
     165%MACRO1{ 
     166   format="$percentMACRO2{ 
     167      format=\"%MACRO3%, %MACRO4%\" 
     168   }$percent" 
     169}% 
     170</verbatim> 
     171The macros are expanded in this order: MACRO3, MACRO4, MACRO1, *MACRO2*. 
     172#AnimatedDelayedExample 
     173---+++++ Animated Example 
     174From the [[FormattedSearch#ConditionalOutputExample][conditional output example]]: 
     175 
     176%JQREQUIRE{"CYCLE,EASING,CHILI"}%<!-- ids are appended with %INCLUDINGTOPIC% 
     177to avoid duplicates in System.CompleteDocumentation -->%ADDTOZONE{"script" 
     178  id="DelayedSlideshow%INCLUDINGTOPIC%" 
     179  text="<script type='text/javascript'> 
     180jQuery(document).ready(function($) { 
     181    $('#DelayedSlideshow%INCLUDINGTOPIC%').cycle({ 
     182        fx:     'fade', 
     183        speed:  'slow', 
     184        timeout: 5000, 
     185        pager:  '#DelayedSlideshowNav%INCLUDINGTOPIC%', 
     186        slideExpr: 'pre', 
     187        pause:  true, 
     188        pauseOnPagerHover: true 
     189    }); 
     190}); 
     191</script>" 
     192  requires="JQUERYPLUGIN::CYCLE" 
     193}%%ADDTOZONE{"head" 
     194  id="DelayedSlideshow%INCLUDINGTOPIC%/css" 
     195  text="<style type='text/css'> 
     196    #DelayedSlideshowNav%INCLUDINGTOPIC%  a { margin: 0 10px 0 0; padding: 3px 5px; border: 1px solid #ddd; background: #fff; text-decoration: none } 
     197    #DelayedSlideshowNav%INCLUDINGTOPIC%  a.activeSlide, 
     198    #DelayedSlideshowNav%INCLUDINGTOPIC%  a:hover { background: #cff } 
     199    #DelayedSlideshowNav%INCLUDINGTOPIC%  a:focus { outline: none; } 
     200  </style>" 
     201}%<div id="DelayedSlideshowNav%INCLUDINGTOPIC%"></div> 
     202<div id="DelayedSlideshow%INCLUDINGTOPIC%"> 
     203<verbatim class="tml"> 
     204%SEARCH{ 
     205  "info.date >= d2n('2009-01-01') AND info.date <= d2n('2009-12-31')" 
     206  type="query" 
     207  limit="2" 
     208  nonoise="on" 
     209  format="   * $percentICON{ 
     210    \"$percentIF{ 
     211      \"'$topic'/parent.name='%PARENT%'\" 
     212      then=\"info\" else=\"gear\" 
     213    }$percent\" 
     214  }$percent [[$topic]]" 
     215}% 
     216---- 
     217   * Set PARENT = UserDocumentationCategory 
     218</verbatim> 
     219<pre class="tml"> 
     220%<nop>SEARCH{ 
     221  "info.date >= d2n('2009-01-01') AND info.date <= d2n('2009-12-31')" 
     222  type="query" 
     223  limit="2" 
     224  nonoise="on" 
     225  format="   * $percentICON{ 
     226    \"$percentIF{ 
     227      \"'$topic'/parent.name='UserDocumentationCategory'\" 
     228      then=\"info\" else=\"gear\" 
     229    }$percent\" 
     230  }$percent [[$topic]]" 
     231}% 
     232---- 
     233   * Set PARENT = UserDocumentationCategory 
     234</pre> 
     235<pre class="tml"> 
     236%SEARCH{ 
     237  "info.date >= d2n('2009-01-01') AND info.date <= d2n('2009-12-31')" 
     238  type="query" 
     239  limit="2" 
     240  nonoise="on" 
     241  format="   * $percent<nop>ICON{ 
     242    \"$percent<nop>IF{ 
     243      \"'$topic'/parent.name='UserDocumentationCategory'\" 
     244      then=\"info\" else=\"gear\" 
     245    }$percent\" 
     246  }$percent [[$topic]]" 
     247}% 
     248---- 
     249   * Set PARENT = UserDocumentationCategory 
     250</pre> 
     251<pre class="tml"> 
     252%SEARCH{ 
     253  "info.date >= d2n('2009-01-01') AND info.date <= d2n('2009-12-31')" 
     254  type="query" 
     255  limit="2" 
     256  nonoise="on" 
     257  format="   * $percent<nop>ICON{ 
     258    \"$percentIF{ 
     259      \"'$topic'/parent.name='UserDocumentationCategory'\" 
     260      then=\"info\" else=\"gear\" 
     261    }$percent\" 
     262  }$percent [[$topic]]" 
     263}% 
     264---- 
     265   * Set PARENT = UserDocumentationCategory 
     266</pre> 
     267<pre class="tml"> 
     268%SEARCH{ 
     269  "info.date >= d2n('2009-01-01') AND info.date <= d2n('2009-12-31')" 
     270  type="query" 
     271  limit="2" 
     272  nonoise="on" 
     273  format="   * &lt;img src=\"$percentICONURL{ 
     274    \"$percentIF{ 
     275      \"'$topic'/parent.name='UserDocumentationCategory'\" 
     276      then=\"info\" else=\"gear\" 
     277    }$percent\" 
     278  }$percent\"/&gt; [[$topic]]" 
     279}% 
     280---- 
     281   * Set PARENT = UserDocumentationCategory 
    154282</pre> 
    155283</div> 
     
    217345*Related Topics:* UserDocumentationCategory 
    218346<!-- %JQREQUIRE{"chili"}% --> 
    219  
    220 %META:FILEATTACHMENT{name="nested_macros.gif" attr="h" version="1.1"}% 
  • branches/Release01x01/core/data/System/VarENCODE.txt

    r9226 r9329  
    2525   %<nop>ENCODE{"spaced name"}%= expands to 
    2626      %ENCODE{"spaced name"}% 
    27    %<nop>ENCODE{"| Blah | | More blah |" old="|,$n" new="&vbar;,&lt;br /&gt;"}% expands to 
    28       %ENCODE{"| Blah | | More blah |" old="|,$n" new="&vbar;,<br />"}% 
     27   %<nop>ENCODE{"| Blah | | More blah |" old="|,$n" new="&amp;#124;,&lt;br /&gt;"}% expands to 
     28      %ENCODE{"| Blah | | More blah |" old="|,$n" new="&#124;,<br />"}% 
    2929      - this encoding is useful to protect special TML characters in tables. 
    3030   %<nop>ENCODE{"10xx1x01x" old="1,x,0" new="A,,B"}% expands to 
Note: See TracChangeset for help on using the changeset viewer.