close Warning: Error with navigation contributor "AccountModule"

Changes between Version 5 and Version 42 of WikiMacros


Ignore:
Timestamp:
Jun 27, 2006, 5:04:57 PM (13 years ago)
Author:
trac
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • WikiMacros

    v5 v42  
    1 {{{ 
    2  #!html
    3 
    4 
    5 
    6 }}}
    71=  Wiki Macros =
    82Trac 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.
    93
    10 Another kind of macros are WikiProcessors. They typically deal with alternate markup formats and representation of larger blocks of information (like source code highlighting). See also: WikiProcessors.
     4Another kind of macros are WikiProcessors. They typically deal with alternate markup formats and representation of larger blocks of information (like source code highlighting).
    115
    126== Using Macros ==
    13 Macro calls are enclosed in two ''square brackets''. Like python functions, macros can also have arguments, a comma separated list within parenthesis.
     7Macro calls are enclosed in two ''square brackets''. Like python functions, macros can also have arguments, a comma separated list within parentheses.
    148
    159=== Examples ===
     
    2721 [[HelloWorld(Testing)]]
    2822
     23== Available Macros ==
    2924
    30 == Available Macros ==
    31 Macros are still a new feature, and the list of available (and distributed) macros is
    32 admittedly not very impressive. In future Trac releases, we hope to build a library of useful macros, and will of course happily include contributed macros (see below).
     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].''
    3326
    34  * '''!HelloWorld''' -- An example macro, useful for learning how to write macros.
    35  * '''Timestamp''' -- Insert the current date and time.
    36 
    37 
    38 ----
    39 
     27[[MacroList]]
    4028
    4129== Macros from around the world ==
    4230The [http://projects.edgewall.com/trac/ Trac Project] has a section dedicated to user-contributed macros, [http://projects.edgewall.com/trac/wiki/MacroBazaar 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 [http://projects.edgewall.com/trac/wiki/MacroBazaar MacroBazaar] wiki page.
    4331
    44   http://projects.edgewall.com/trac/wiki/MacroBazaar
    45 
    46 
    4732----
    4833
    49 
    50 == Developing New Macros ==
     34== Developing Custom Macros ==
    5135Macros, like Trac itself, are written in the [http://www.python.org/ 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.
    5236
    5337It's easiest to learn from an example:
    5438{{{
     39#!python
    5540# MyMacro.py -- The world's simplest macro
    5641
    5742def execute(hdf, args, env):
    58     return "Hello World called with args: %s" % args
     43    return "Hello World called with args: %s" % args
    5944}}}
    6045
    61 === Advanced Topics: Template-enabled Macros ===
    62 For advanced uses, macros can also render structured output in HDF, to be rendered to HTML using clearsilver templates - like most Trac output. In short, this allows more generic and well-designed advanced macros.
    63 
    64 Macros gain direct access to the main HDF tree, and are free to manipulate it.
    65 
    66 Example:
     46You can also use the environment (`env`) object, for example to access configuration data and the database, for example:
    6747{{{
    68 def execute(hdf, args, env):
    69     # Currently hdf is set only when the macro is called
    70     # From a wiki page
    71     if hdf:
    72         hdf.setValue('wiki.macro.greeting', 'Hello World')
    73        
    74     # args will be null if the macro is called without parentesis.
    75     args = args or 'No arguments'
    76     return 'Hello World, args = ' + args
    77 }}}
    78 
    79 You can also use the environment (env) object to access configuration data.
    80 
    81 Example.
    82 {{{
     48#!python
    8349def execute(hdf, txt, env):
    8450    return env.get_config('trac', 'repository_dir')
    8551}}}
     52
     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.
     54
     55For more information about developing macros, see the [http://projects.edgewall.com/trac/wiki/TracDev development resources] on the main project site.
     56
    8657----
    8758See also:  WikiProcessors, WikiFormatting, TracGuide
    88 http://child-clock.builtfree.org/map.html
    89 http://silver-clock.builtfree.org/map3.html
    90 http://clock-repair.angelcities.com/map2.html
    91 http://clock-service.angelcities.com/map1.html
    92 http://patek.freewebpages.org/map1.html
    93 http://patek.kogaryu.com/map.html
    94 http://clock-download.builtfree.org/map4.html
    95 http://cuckoo-clock.builtfree.org/map3.html
    96 http://panerai.freewebpages.org/map1.html
    97 http://panerai.kogaryu.com/map2.html
    98 http://iwc.freewebpages.org/map1.html
    99 http://iwc.kogaryu.com/map2.html
    100 http://clock.kogaryu.com/map.html
    101 http://clock.freewebpages.org/map2.html
    102 http://wall-clock.kogaryu.com/map.html
    103 http://wall-clock.freewebpages.org/map.html
    104 http://kitchen-wall-clock.kogaryu.com/map.html
    105 http://iron-wall-clock.kogaryu.com/map1.html
    106 http://iron-wall-clock.freewebpages.org/map.html
    107 http://clock-digital-travel.kogaryu.com/map.html
    108 http://clock-digital-travel.freewebpages.org/map.html
    109 http://atomic-clock-usa.angelcities.com/map1.html
    110 http://clock-germany.angelcities.com/map2.html