Edgewall Software

Changes between Version 5 and Version 6 of 0.12/WikiMacros


Ignore:
Timestamp:
May 11, 2011, 2:49:31 PM (13 years ago)
Author:
Christian Boos
Comment:

snapshotting WikiMacros@40

Legend:

Unmodified
Added
Removed
Modified
  • 0.12/WikiMacros

    v5 v6  
    1 ** Note: this page was used to prepare the 0.12 version of wiki:/WikiMacros, see now directly that toplevel page **
    21= Trac Macros =
    32
    43[[PageOutline]]
     4[[TranslatedPages]]
    55
    66Trac macros are plugins to extend the Trac engine with custom 'functions' written in Python. A macro inserts dynamic HTML data in any context supporting WikiFormatting.
     
    4949  }}}
    5050}}}
    51 {{{#!td style="padding-left: 2em; font-size: 80%"
    52 [[?]]
     51{{{#!td style="padding-left: 2em"
     52{{{#!html
     53<div style="font-size: 80%" class="trac-macrolist">
     54<h3><code>[[Image]]</code></h3>Embed an image in wiki-formatted text.
     55
     56The first argument is the file …
     57<h3><code>[[InterTrac]]</code></h3>Provide a list of known <a class="wiki" href="/wiki/InterTrac">InterTrac</a> prefixes.
     58<h3><code>[[InterWiki]]</code></h3>Provide a description list for the known <a class="wiki" href="/wiki/InterWiki">InterWiki</a> prefixes.
     59<h3><code>[[KnownMimeTypes]]</code></h3>List all known mime-types which can be used as <a class="wiki" href="/wiki/WikiProcessors">WikiProcessors</a>.
     60Can be …</div>
     61}}}
     62etc.
    5363}}}
    5464
     
    5767''Note that the following list will only contain the macro documentation if you've not enabled `-OO` optimizations, or not set the `PythonOptimize` option for [wiki:TracModPython mod_python].''
    5868
    59 [[MacroList]]
     69(the following is snapshot for Trac 0.12.2 - see [[0.13/WikiMacros]] for the documentation of macros in trunk / 0.13dev)
     70{{{#!html
     71<div class="trac-macrolist"><h3 id="Image-macro"><code>[[Image]]</code></h3><p>
     72Embed an image in wiki-formatted text.
     73</p>
     74<p>
     75The first argument is the file specification. The file specification may
     76reference attachments in three ways:
     77</p>
     78<ul><li><tt>module:id:file</tt>, where module can be either <strong>wiki</strong> or <strong>ticket</strong>,
     79to refer to the attachment named <em>file</em> of the specified wiki page or
     80ticket.
     81</li><li><tt>id:file</tt>: same as above, but id is either a ticket shorthand or a Wiki
     82page name.
     83</li><li><tt>file</tt> to refer to a local attachment named 'file'. This only works from
     84within that wiki page or a ticket.
     85</li></ul><p>
     86Also, the file specification may refer to repository files, using the
     87<tt>source:file</tt> syntax (<tt>source:file@rev</tt> works also).
     88</p>
     89<p>
     90Files can also be accessed with a direct URLs; <tt>/file</tt> for a
     91project-relative, <tt>//file</tt> for a server-relative, or <tt>http://server/file</tt>
     92for absolute location of the file.
     93</p>
     94<p>
     95The remaining arguments are optional and allow configuring the attributes
     96and style of the rendered <tt>&lt;img&gt;</tt> element:
     97</p>
     98<ul><li>digits and unit are interpreted as the size (ex. 120, 25%)
     99for the image
     100</li><li><tt>right</tt>, <tt>left</tt>, <tt>center</tt>, <tt>top</tt>, <tt>bottom</tt> and <tt>middle</tt> are interpreted
     101as the alignment for the image (alternatively, the first three can be
     102specified using <tt>align=...</tt> and the last three using <tt>valign=...</tt>)
     103</li><li><tt>link=some TracLinks...</tt> replaces the link to the image source by the
     104one specified using a <a class="wiki" href="/wiki/TracLinks">TracLinks</a>. If no value is specified, the link is
     105simply removed.
     106</li><li><tt>nolink</tt> means without link to image source (deprecated, use <tt>link=</tt>)
     107</li><li><tt>key=value</tt> style are interpreted as HTML attributes or CSS style
     108indications for the image. Valid keys are:
     109<ul><li>align, valign, border, width, height, alt, title, longdesc, class,
     110margin, margin-(left,right,top,bottom), id and usemap
     111</li><li><tt>border</tt>, <tt>margin</tt>, and <tt>margin-</tt>* can only be a single number
     112</li><li><tt>margin</tt> is superseded by <tt>center</tt> which uses auto margins
     113</li></ul></li></ul><p>
     114Examples:
     115</p>
     116<pre class="wiki">    [[Image(photo.jpg)]]                           # simplest
     117    [[Image(photo.jpg, 120px)]]                    # with image width size
     118    [[Image(photo.jpg, right)]]                    # aligned by keyword
     119    [[Image(photo.jpg, nolink)]]                   # without link to source
     120    [[Image(photo.jpg, align=right)]]              # aligned by attribute
     121</pre><p>
     122You can use image from other page, other ticket or other module.
     123</p>
     124<pre class="wiki">    [[Image(OtherPage:foo.bmp)]]    # if current module is wiki
     125    [[Image(base/sub:bar.bmp)]]     # from hierarchical wiki page
     126    [[Image(#3:baz.bmp)]]           # if in a ticket, point to #3
     127    [[Image(ticket:36:boo.jpg)]]
     128    [[Image(source:/images/bee.jpg)]] # straight from the repository!
     129    [[Image(htdocs:foo/bar.png)]]   # image file in project htdocs dir.
     130</pre><p>
     131<em>Adapted from the Image.py macro created by Shun-ichi Goto
     132&lt;gotoh@…&gt;</em>
     133</p>
     134<h3 id="InterTrac-macro"><code>[[InterTrac]]</code></h3><p>
     135Provide a list of known <a class="wiki" href="/wiki/InterTrac">InterTrac</a> prefixes.
     136</p>
     137<h3 id="InterWiki-macro"><code>[[InterWiki]]</code></h3><p>
     138Provide a description list for the known <a class="wiki" href="/wiki/InterWiki">InterWiki</a> prefixes.
     139</p>
     140<h3 id="KnownMimeTypes-macro"><code>[[KnownMimeTypes]]</code></h3><p>
     141List all known mime-types which can be used as <a class="wiki" href="/wiki/WikiProcessors">WikiProcessors</a>.
     142</p>
     143<p>
     144Can be given an optional argument which is interpreted as mime-type filter.
     145</p>
     146<h3 id="MacroList-macro"><code>[[MacroList]]</code></h3><p>
     147Display a list of all installed Wiki macros, including documentation if
     148available.
     149</p>
     150<p>
     151Optionally, the name of a specific macro can be provided as an argument. In
     152that case, only the documentation for that macro will be rendered.
     153</p>
     154<p>
     155Note that this macro will not be able to display the documentation of
     156macros if the <tt>PythonOptimize</tt> option is enabled for mod_python!
     157</p>
     158<h3 id="PageOutline-macro"><code>[[PageOutline]]</code></h3><p>
     159Display a structural outline of the current wiki page, each item in the
     160outline being a link to the corresponding heading.
     161</p>
     162<p>
     163This macro accepts three optional parameters:
     164</p>
     165<ul><li>The first is a number or range that allows configuring the minimum and
     166maximum level of headings that should be included in the outline. For
     167example, specifying "1" here will result in only the top-level headings
     168being included in the outline. Specifying "2-3" will make the outline
     169include all headings of level 2 and 3, as a nested list. The default is
     170to include all heading levels.
     171</li><li>The second parameter can be used to specify a custom title (the default
     172is no title).
     173</li><li>The third parameter selects the style of the outline. This can be
     174either <tt>inline</tt> or <tt>pullout</tt> (the latter being the default). The <tt>inline</tt>
     175style renders the outline as normal part of the content, while <tt>pullout</tt>
     176causes the outline to be rendered in a box that is by default floated to
     177the right side of the other content.
     178</li></ul><h3 id="RecentChanges-macro"><code>[[RecentChanges]]</code></h3><p>
     179List all pages that have recently been modified, grouping them by the
     180day they were last modified.
     181</p>
     182<p>
     183This macro accepts two parameters. The first is a prefix string: if
     184provided, only pages with names that start with the prefix are included in
     185the resulting list. If this parameter is omitted, all pages are listed.
     186</p>
     187<p>
     188The second parameter is a number for limiting the number of pages returned.
     189For example, specifying a limit of 5 will result in only the five most
     190recently changed pages to be included in the list.
     191</p>
     192<h3 id="RepositoryIndex-macro"><code>[[RepositoryIndex]]</code></h3><p>
     193Display the list of available repositories.
     194</p>
     195<p>
     196Can be given the following named arguments:
     197</p>
     198<dl class="wiki"><dt><em>format</em></dt><dd>
     199Select the rendering format:
     200<ul><li><em>compact</em> produces a comma-separated list of repository prefix
     201names (default)
     202</li><li><em>list</em> produces a description list of repository prefix names
     203</li><li><em>table</em> produces a table view, similar to the one visible in
     204the <em>Browse View</em> page
     205</li></ul></dd><dt><em>glob</em></dt><dd>
     206Do a glob-style filtering on the repository names (defaults to '*')
     207</dd><dt><em>order</em></dt><dd>
     208Order repositories by the given column (one of "name", "date" or
     209"author")
     210</dd><dt><em>desc</em></dt><dd>
     211When set to 1, order by descending order
     212</dd></dl>
     213<p>
     214(<em>since 0.12</em>)
     215</p>
     216<h3 id="TicketQuery-macro"><code>[[TicketQuery]]</code></h3><p>
     217Wiki macro listing tickets that match certain criteria.
     218</p>
     219<p>
     220This macro accepts a comma-separated list of keyed parameters,
     221in the form "key=value".
     222</p>
     223<p>
     224If the key is the name of a field, the value must use the syntax
     225of a filter specifier as defined in <a class="wiki" href="/wiki/TracQuery#QueryLanguage">TracQuery#QueryLanguage</a>.
     226Note that this is <em>not</em> the same as the simplified URL syntax
     227used for <tt>query:</tt> links starting with a <tt>?</tt> character. Commas (<tt>,</tt>)
     228can be included in field values by escaping them with a backslash (<tt>\</tt>).
     229</p>
     230<p>
     231Groups of field constraints to be OR-ed together can be separated by a
     232litteral <tt>or</tt> argument.
     233</p>
     234<p>
     235In addition to filters, several other named parameters can be used
     236to control how the results are presented. All of them are optional.
     237</p>
     238<p>
     239The <tt>format</tt> parameter determines how the list of tickets is
     240presented:
     241</p>
     242<ul><li><strong>list</strong> -- the default presentation is to list the ticket ID next
     243to the summary, with each ticket on a separate line.
     244</li><li><strong>compact</strong> -- the tickets are presented as a comma-separated
     245list of ticket IDs.
     246</li><li><strong>count</strong> -- only the count of matching tickets is displayed
     247</li><li><strong>table</strong>  -- a view similar to the custom query view (but without
     248the controls)
     249</li></ul><p>
     250The <tt>max</tt> parameter can be used to limit the number of tickets shown
     251(defaults to <strong>0</strong>, i.e. no maximum).
     252</p>
     253<p>
     254The <tt>order</tt> parameter sets the field used for ordering tickets
     255(defaults to <strong>id</strong>).
     256</p>
     257<p>
     258The <tt>desc</tt> parameter indicates whether the order of the tickets
     259should be reversed (defaults to <strong>false</strong>).
     260</p>
     261<p>
     262The <tt>group</tt> parameter sets the field used for grouping tickets
     263(defaults to not being set).
     264</p>
     265<p>
     266The <tt>groupdesc</tt> parameter indicates whether the natural display
     267order of the groups should be reversed (defaults to <strong>false</strong>).
     268</p>
     269<p>
     270The <tt>verbose</tt> parameter can be set to a true value in order to
     271get the description for the listed tickets. For <strong>table</strong> format only.
     272<em>deprecated in favor of the <tt>rows</tt> parameter</em>
     273</p>
     274<p>
     275The <tt>rows</tt> parameter can be used to specify which field(s) should
     276be viewed as a row, e.g. <tt>rows=description|summary</tt>
     277</p>
     278<p>
     279For compatibility with Trac 0.10, if there's a last positional parameter
     280given to the macro, it will be used to specify the <tt>format</tt>.
     281Also, using "&amp;" as a field separator still works (except for <tt>order</tt>)
     282but is deprecated.
     283</p>
     284<h3 id="TitleIndex-macro"><code>[[TitleIndex]]</code></h3><p>
     285Insert an alphabetic list of all wiki pages into the output.
     286</p>
     287<p>
     288Accepts a prefix string as parameter: if provided, only pages with names
     289that start with the prefix are included in the resulting list. If this
     290parameter is omitted, all pages are listed.
     291If the prefix is specified, a second argument of value 'hideprefix'
     292can be given as well, in order to remove that prefix from the output.
     293</p>
     294<p>
     295Alternate <tt>format</tt> and <tt>depth</tt> named parameters can be specified:
     296</p>
     297<ul><li><tt>format=compact</tt>: The pages are displayed as comma-separated links.
     298</li><li><tt>format=group</tt>: The list of pages will be structured in groups
     299according to common prefix. This format also supports a <tt>min=n</tt>
     300argument, where <tt>n</tt> is the minimal number of pages for a group.
     301</li><li><tt>format=hierarchy</tt>: The list of pages will be structured according
     302to the page name path hierarchy. This format also supports a <tt>min=n</tt>
     303argument, where higher <tt>n</tt> flatten the display hierarchy
     304</li><li><tt>depth=n</tt>: limit the depth of the pages to list. If set to 0,
     305only toplevel pages will be shown, if set to 1, only immediate
     306children pages will be shown, etc. If not set, or set to -1,
     307all pages in the hierarchy will be shown.
     308</li></ul><h3 id="TracAdminHelp-macro"><code>[[TracAdminHelp]]</code></h3><p>
     309Display help for trac-admin commands.
     310</p>
     311<p>
     312Examples:
     313</p>
     314<pre class="wiki">[[TracAdminHelp]]               # all commands
     315[[TracAdminHelp(wiki)]]         # all wiki commands
     316[[TracAdminHelp(wiki export)]]  # the "wiki export" command
     317[[TracAdminHelp(upgrade)]]      # the upgrade command
     318</pre><h3 id="TracGuideToc-macro"><code>[[TracGuideToc]]</code></h3><p>
     319Display a table of content for the Trac guide.
     320</p>
     321<p>
     322This macro shows a quick and dirty way to make a table-of-contents
     323for the <a class="missing wiki">Help/Guide?</a>. The table of contents will contain the Trac* and
     324<a class="wiki" href="/wiki/WikiFormatting">WikiFormatting</a> pages, and can't be customized. Search for <a class="missing wiki">TocMacro?</a> for a
     325a more customizable table of contents.
     326</p>
     327<h3 id="TracIni-macro"><code>[[TracIni]]</code></h3><p>
     328Produce documentation for the Trac configuration file.
     329</p>
     330<p>
     331Typically, this will be used in the <a class="wiki" href="/wiki/TracIni">TracIni</a> page.
     332Optional arguments are a configuration section filter,
     333and a configuration option name filter: only the configuration
     334options whose section and name start with the filters are output.
     335</p>
     336</div>
     337}}}
    60338
    61339== Macros from around the world ==
     
    162440{{{
    163441#!python
    164     text = "whatever wiki markup you want, even containing other macros"
    165     # Convert Wiki markup to HTML, new style
    166     out = StringIO()
    167     Formatter(self.env, formatter.context).format(text, out)
    168     return Markup(out.getvalue())
    169 }}}
     442from genshi.core import Markup
     443from trac.wiki.macros import WikiMacroBase
     444from trac.wiki import Formatter
     445import StringIO
     446
     447class HelloWorldMacro(WikiMacroBase):
     448        def expand_macro(self, formatter, name, text, args):
     449                text = "whatever '''wiki''' markup you want, even containing other macros"
     450                # Convert Wiki markup to HTML, new style
     451                out = StringIO.StringIO()
     452                Formatter(self.env, formatter.context).format(text, out)
     453                return Markup(out.getvalue())
     454}}}