Edgewall Software

Changes between Version 23 and Version 24 of WikiMacros


Ignore:
Timestamp:
Dec 6, 2007, 2:16:23 PM (16 years ago)
Author:
Christian Boos
Comment:

redirect to TracWikiMacros

Legend:

Unmodified
Added
Removed
Modified
  • WikiMacros

    v23 v24  
    1 =  Wiki Macros =
    2 Trac 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.
    3 
    4 Another kind of macros are WikiProcessors. They typically deal with alternate markup formats and representation of larger blocks of information (like source code highlighting).
    5 
    6 == Using Macros ==
    7 Macro calls are enclosed in two ''square brackets''. Like Python functions, macros can also have arguments, a comma separated list within parentheses.
    8 
    9 === Examples ===
    10 
    11 {{{
    12  [[Timestamp]]
    13 }}}
    14 Display:
    15  [[Timestamp]]
    16 
    17 {{{
    18  [[HelloWorld(Testing)]]
    19 }}}
    20 Display:
    21  [[HelloWorld(Testing)]]
    22 
    23 == Available Macros ==
    24 
    25 ''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].''
    26 
    27 [[MacroList]]
    28 
    29 == Macros from around the world ==
    30 
    31 The [http://trac-hacks.org/ Trac Hacks] site provides a wide collection of macros and other Trac [TracPlugins plugins] contributed by the Trac community. If you're looking for new macros, or have written one that you'd like to share with the world, please don't hesitate to visit that site.
    32 
    33 == Developing Custom Macros ==
    34 Macros, like Trac itself, are written in the [http://www.python.org/ Python programming language].
    35 
    36 Since version 0.9, wiki macros can also be written as TracPlugins. This gives them some capabilities that “classic” macros do not have, such as being able to directly access the HTTP request.
    37 
    38 For more information about developing macros, see the [http://projects.edgewall.com/trac/wiki/TracDev development resources] on the main project site.
    39 
    40 See also #4381 '''TODO: write a TracDev/WikiMacros HOWTO for 0.11''
    41 
    42 === Old Style Macros ===
    43 ''Note: this is still supported in [trac:milestone:0.10], but deprecated.
    44 Support for old style macros has been removed in [trac:milestone:0.11].''
    45 
    46 They are very simple modules, identified by the filename and should contain a single `execute()` function. Trac will display the returned data inserted into the HTML representation of the Wiki page where the macro is called.
    47 
    48 It's easiest to learn from an example:
    49 {{{
    50 #!python
    51 # MyMacro.py -- The world's simplest macro
    52 
    53 def execute(hdf, args, env):
    54     return "Hello World called with args: %s" % args
    55 }}}
    56 
    57 You can also use the environment (`env`) object, for example to access configuration data and the database, for example:
    58 {{{
    59 #!python
    60 def execute(hdf, txt, env):
    61     return env.config.get('trac', 'repository_dir')
    62 }}}
    63 
    64 ----
    65 See also:  WikiProcessors, WikiFormatting, TracGuide
     1See TracWikiMacros.