Changes between Initial Version and Version 1 of WikiMacros

2005-11-06T20:58:51Z (17 years ago)



  • WikiMacros

    v1 v1  
     1=  Wiki Macros =
     2Trac 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.
     4Another kind of macros are WikiProcessors. They typically deal with alternate markup formats and representation of larger blocks of information (like source code highlighting).
     6== Using Macros ==
     7Macro calls are enclosed in two ''square brackets''. Like python functions, macros can also have arguments, a comma separated list within parentheses.
     9=== Examples ===
     12 [[Timestamp]]
     15 [[Timestamp]]
     18 [[HelloWorld(Testing)]]
     21 [[HelloWorld(Testing)]]
     23== Available Macros ==
     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].''
     29== Macros from around the world ==
     30The [ Trac Project] has a section dedicated to user-contributed macros, [ MacroBazaar]. If you're looking for new macros, or have written new ones to share with the world, don't hesitate adding it to the [ MacroBazaar] wiki page.
     34== Developing Custom Macros ==
     35Macros, like Trac itself, are written in the [ Python programming language]. They are very simple modules, identified by the filename and should contain a single ''entry point'' function. Trac will display the returned data inserted into the HTML where the macro was called.
     37It's easiest to learn from an example:
     40# -- The world's simplest macro
     42def execute(hdf, args, env):
     43    return "Hello World called with args: %s" % args
     46You can also use the environment (`env`) object, for example to access configuration data and the database, for example:
     49def execute(hdf, txt, env):
     50    return env.get_config('trac', 'repository_dir')
     53Note that since version 0.9, wiki macros can also be written as TracPlugins. This gives them some capabilities than “classic” macros do not have, such as directly access the HTTP request.
     55For more information about developing macros, see the [ development resources] on the main project site.
     58See also:  WikiProcessors, WikiFormatting, TracGuide